diff --git a/NEWS.md b/NEWS.md index 33b2cebbb2388..8a7bbafe79fdd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 -------------------- diff --git a/src/julia-parser.scm b/src/julia-parser.scm index e276d1a8567d5..1967eebb1cb84 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -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 #... 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) @@ -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 #\.)