use newlines in lexer

pull/10/head
Matthew Butterick 8 years ago
parent 8504cd4d80
commit 46f6ab0c36

@ -20,8 +20,8 @@
#:source #'LINE-NUMBER)] #:source #'LINE-NUMBER)]
[ORIG-LOC caller-stx]) [ORIG-LOC caller-stx])
(syntax/loc caller-stx (syntax/loc caller-stx
(define (LINE-NUMBER-ID #:srcloc? [srcloc #f]) (define (LINE-NUMBER-ID #:srcloc? [loc #f])
(if srcloc (if loc
(syntax-srcloc #'ORIG-LOC) (syntax-srcloc #'ORIG-LOC)
(begin (void) STATEMENT ...)))))) (begin (void) STATEMENT ...))))))

@ -11,8 +11,10 @@
(srcloc 'string #f #f 1 1)))) (srcloc 'string #f #f 1 1))))
(check-equal? (check-equal?
(lex "rem ignored\n") (lex "rem ignored\n")
(list (srcloc-token (token 'REM "rem ignored\n") (list (srcloc-token (token 'REM "rem ignored")
(srcloc 'string #f #f 1 12)))) (srcloc 'string #f #f 1 11))
(srcloc-token (token 'NEWLINE)
(srcloc 'string #f #f 12 1))))
(check-equal? (check-equal?
(lex "print") (lex "print")
(list (srcloc-token "print" (list (srcloc-token "print"

@ -7,7 +7,7 @@
(lexer-srcloc (lexer-srcloc
[(eof) (return-without-srcloc eof)] [(eof) (return-without-srcloc eof)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)] [(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:seq "\n" digits) (token 'LINE-NUMBER (string->number (string-trim lexeme)))] ["\n" (token 'NEWLINE)]
[whitespace (token lexeme #:skip? #t)] [whitespace (token lexeme #:skip? #t)]
[(:or "print" "goto" "end" "+" ":") lexeme] [(:or "print" "goto" "end" "+" ":") lexeme]
[digits (token 'INTEGER (string->number lexeme))] [digits (token 'INTEGER (string->number lexeme))]

@ -1,7 +1,7 @@
#lang brag #lang brag
b-program : b-line* b-program : [b-line] (/NEWLINE+ [b-line])*
b-line : @b-line-number [b-statement] (/":" [b-statement])* b-line : @b-line-number [b-statement] (/":" [b-statement])*
b-line-number : LINE-NUMBER b-line-number : INTEGER
@b-statement : b-rem @b-statement : b-rem
| b-print | b-print
| b-goto | b-goto

Loading…
Cancel
Save