From e6c5a6372b01812465d0a31c6cc289d5d03ddef7 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Wed, 19 Sep 2018 13:40:16 +1000 Subject: [PATCH] =?UTF-8?q?Add=20a=20line=20continuation=20character=20'?= =?UTF-8?q?=E2=A4=B8'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #27533 --- src/julia-parser.scm | 13 +++++++++++++ stdlib/REPL/src/latex_symbols.jl | 1 + test/syntax.jl | 7 +++++++ 3 files changed, 21 insertions(+) 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()