Skip to content

Commit

Permalink
Add a line continuation character '⤸'
Browse files Browse the repository at this point in the history
Closes #27533
  • Loading branch information
c42f committed Sep 19, 2018
1 parent 8dd3326 commit e6c5a63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@
(skip-multiline-comment port 1))
(skip-to-eol port)))

(define (maybe-continue-line port)
(if (not space-sensitive)
(error "Line continuation '⤸' is only allowed for space separated lists like macros arugments and matrix literals"))
(read-char port) ; Consume ⤸
(let ((c (peek-char port)))
(if (eof-object? c)
(error "incomplete: Line continuation '⤸' is last character in file")) ; NOTE: changing this may affect code in base/client.jl
(if (not (eqv? c #\newline))
(error (string "Line continuation '⤸' must be followed by a newline. Got \""
c "\" instead"))))
(read-char port))

(define (skip-ws-and-comments port)
(skip-ws port #t)
(if (eqv? (peek-char port) #\#)
Expand Down Expand Up @@ -530,6 +542,7 @@
((string.find "0123456789" c) (read-number port #f #f))

((eqv? c #\#) (skip-comment port) (next-token port s))
((eqv? c #\⤸) (maybe-continue-line port) (next-token port s))

;; . is difficult to handle; it could start a number or operator
((and (eqv? c #\.)
Expand Down
1 change: 1 addition & 0 deletions stdlib/REPL/src/latex_symbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const latex_symbols = Dict(
"\\impliedby" => "",
"\\to" => "",
"\\euler" => "",
"\\linecontinuation" => "",

# Superscripts
"\\^0" => "",
Expand Down
7 changes: 7 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,13 @@ let g = @foo28900 f28900(kwarg = x->2x)
@test g(10) == 20
end

# Line continuation - issue #27533
@test Meta.parse("[1 ⤸\n 2]") == Expr(:hcat, 1, 2)
@test Meta.parse("@f ⤸\n a") == Expr(:macrocall, Symbol("@f"), LineNumberNode(1, :none), :a)
@test Meta.isexpr(Meta.parse("@f ⤸"), :incomplete)
@test_throws ParseError("Line continuation '⤸' is only allowed for space separated lists like macros arugments and matrix literals") Meta.parse("x ⤸\n = 1")
@test_throws ParseError("Line continuation '⤸' must be followed by a newline. Got \"\" instead") Meta.parse("@x ⤸ \n")

# issue #26037
x26037() = 10
function test_26037()
Expand Down

0 comments on commit e6c5a63

Please sign in to comment.