use newlines in lexer

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

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

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

@ -7,7 +7,7 @@
(lexer-srcloc
[(eof) (return-without-srcloc eof)]
[(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)]
[(:or "print" "goto" "end" "+" ":") lexeme]
[digits (token 'INTEGER (string->number lexeme))]

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

Loading…
Cancel
Save