Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a line continuation character '⤸' #29273

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I'm having second thoughts about using space-sensitive in the lexer right here. It seemed like a good idea when I got up this morning but I'm not so sure now.

Needs further testing.

(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