diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 9d832894f9bb1..bd75855f45ca7 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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) #\#) @@ -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 #\.) diff --git a/stdlib/REPL/src/latex_symbols.jl b/stdlib/REPL/src/latex_symbols.jl index 6f8cf59fc22b6..e91d4acfefa76 100644 --- a/stdlib/REPL/src/latex_symbols.jl +++ b/stdlib/REPL/src/latex_symbols.jl @@ -107,6 +107,7 @@ const latex_symbols = Dict( "\\impliedby" => "⟸", "\\to" => "→", "\\euler" => "ℯ", + "\\linecontinuation" => "⤸", # Superscripts "\\^0" => "⁰", diff --git a/test/syntax.jl b/test/syntax.jl index 4a0c7a390850f..0c36e91c95f31 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -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()