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

WIP: implement #= ... =# multiline comments #6128

Merged
merged 1 commit into from
Mar 12, 2014
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ New language features
the module is first loaded, and on process startup if a pre-compiled
version of the module is present ([#1268]).

* Multiline comments: `#= .... =#` ([#69], [#6128]).

Library improvements
--------------------

Expand Down
23 changes: 21 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,29 @@
(eq? (car t) 'macrocall)
(memq (cadr t) '(@int128_str @uint128_str @bigint_str))))

; skip to end of comment, starting at #: either #...<eol> or #= .... =#.
(define (skip-comment port)
(define (skip-multiline-comment port)
(let ((c (read-char port)))
(if (eof-object? c)
(error "non-terminated multiline comment #= ... =#")
(begin (if (eqv? c #\=)
(let ((c (peek-char port)))
(if (eqv? c #\#)
(read-char port)
(skip-multiline-comment port)))
(skip-multiline-comment port))))))

(read-char port) ; read # that was already peeked
(if (eqv? (peek-char port) #\=)
(begin (read-char port) ; read initial =
(skip-multiline-comment port))
(skip-to-eol port)))

(define (skip-ws-and-comments port)
(skip-ws port #t)
(if (eqv? (peek-char port) #\#)
(begin (skip-to-eol port)
(begin (skip-comment port)
(skip-ws-and-comments port)))
#t)

Expand All @@ -371,7 +390,7 @@

((char-numeric? c) (read-number port #f #f))

((eqv? c #\#) (skip-to-eol port) (next-token port s))
((eqv? c #\#) (skip-comment port) (next-token port s))

; . is difficult to handle; it could start a number or operator
((and (eqv? c #\.)
Expand Down