Skip to content

Commit

Permalink
skip block comments too
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Mar 7, 2015
1 parent cd8eae2 commit c0f97e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
*.css
*.js
compiled/
doc/
16 changes: 12 additions & 4 deletions sweet-exp/modern.rkt
Expand Up @@ -107,16 +107,24 @@
(define (skip-whitespace+comments port)
(skip-whitespace port)
(define c (peek-char port))
(define-values (ln col pos) (port-next-location port))
(when (char? c)
(cond [(char=? c #\;)
(skip-line port)
(skip-whitespace+comments port)]
[(char=? c #\#)
(define c2 (peek-char port 1))
(cond [(and (char? c2) (char=? c2 #\;))
(read-char port) (read-char port)
(modern-read2 port)
(skip-whitespace+comments port)])]
(when (char? c2)
(cond [(char=? c2 #\;)
(read-char port) (read-char port)
(modern-read2 port)
(skip-whitespace+comments port)]
[(char=? c2 #\|)
(read-char port) (read-char port)
(unless (regexp-match? (regexp (regexp-quote "|#")) port)
(raise-read-eof-error "unclosed block comment"
(current-source-name) ln col pos 2))
(skip-whitespace+comments port)]))]
)))

; Unfortunately, since most Scheme readers will consume [, {, }, and ],
Expand Down
10 changes: 10 additions & 0 deletions sweet-exp/tests/modern.rkt
Expand Up @@ -19,3 +19,13 @@ not{#t and #f}

(check-equal? (f 2) 4)
(check-equal? (f 3) 9)

(define (f2 x)
{x * x}
#;this(is a comment)
)

(define (f3 x)
{x * x}
#|this is a comment|#
)

0 comments on commit c0f97e2

Please sign in to comment.