-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 digraph \#
#35336
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,6 +522,21 @@ | |
|
||
(define (scolno port) (string " near column " (input-port-column port))) | ||
|
||
(define (line-continuation port s) | ||
(if (eqv? (skip-to-eol port) #\newline) | ||
(read-char port)) ;; Consume newline | ||
(if (eof-object? (peek-char port)) | ||
(error "incomplete: expression ends in line continuation")) | ||
(let ((tok (next-token port s))) | ||
(aset! s 2 #t) | ||
tok)) | ||
|
||
(define (line-continuation-comment port s) | ||
(read-char port) ;; Consume # | ||
(if (eqv? (peek-char port) #\= ) | ||
(error "Cannot start block comment after \\#")) | ||
(line-continuation port s)) | ||
|
||
(define (next-token port s) | ||
(aset! s 2 (eq? (skip-ws port whitespace-newline) #t)) | ||
(let ((c (peek-char port))) | ||
|
@@ -535,6 +550,12 @@ | |
|
||
((eqv? c #\#) (skip-comment port) (next-token port s)) | ||
|
||
((eqv? c #\\) | ||
(let ((c (read-char port))) | ||
(if (eqv? (peek-char port) #\#) | ||
(line-continuation-comment port s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A small nit: Might it be clearer to structure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm completely fine either way. It probably makes sense to first see what the consensus will be about specific choice of characters, etc. and then perfect the implementation. |
||
(read-operator port c)))) | ||
|
||
;; . is difficult to handle; it could start a number or operator | ||
((and (eqv? c #\.) | ||
(let ((c (read-char port)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so a line continuation counts as nonzero whitespace? That makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. The newline should definitely count as whitespace. This prevents things like
being parsed as an invalid string juxtaposition
@info "hello"x
.Interestingly, this brings to light an existing behavior of the Julia parser. Whitespace before a comment gets ignored by the next token, so
x #==#y
is parsed asx*y
even though there is whitespace afterx
.