adjust rem semantics

pull/10/head
Matthew Butterick 8 years ago
parent f49f42003a
commit fad102d545

@ -3,14 +3,13 @@
(provide basic-colorer)
(define (basic-colorer port)
(define next-char (peek-char port))
(define (handle-read-error exn)
(define (handle-lexer-error exn)
(define exn-srclocs (exn:fail:read-srclocs exn))
(srcloc-token (token 'ERROR (string next-char)) (car exn-srclocs)))
(define srcloc-tok (with-handlers ([exn:fail:read? handle-read-error])
(srcloc-token (token 'ERROR) (car exn-srclocs)))
(define srcloc-tok (with-handlers ([exn:fail:read? handle-lexer-error])
(basic-lexer port)))
(cond
[(eof-object? srcloc-tok) (values srcloc-tok 'eof #f #f #f)]
(match srcloc-tok
[(? eof-object?) (values srcloc-tok 'eof #f #f #f)]
[else
(match-define (srcloc-token (token-struct type val _ _ _ _ _)
(srcloc _ _ _ pos span)) srcloc-tok)
@ -25,6 +24,4 @@
["(" '(parenthesis |(|)]
[")" '(parenthesis |)|)]
[else '(no-color #f)])]))
(values (or val "") cat paren pos (+ pos span))]))
(apply-colorer basic-colorer "foo")
(values (or val "") cat paren pos (+ pos span))]))

@ -1,13 +1,13 @@
#lang brag
;; program & lines
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-rem]
@b-line-number : INTEGER
b-rem : REM
;; statements
@b-statement : b-rem | b-end | b-print | b-let | b-input | b-def
@b-statement : b-end | b-print | b-let | b-input | b-def
| b-goto | b-gosub | b-return | b-for | b-next | b-if
b-rem : REM
b-end : /"end"
b-print : /"print" [STRING | b-expr] (/";" [STRING | b-expr])*
b-goto : /"goto" b-expr

@ -1,9 +1,9 @@
#lang basic-demo
#lang basic-demo-2
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5
10 print "one"
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end

@ -1,8 +1,8 @@
#lang brag
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-rem]
@b-line-number : INTEGER
@b-statement : b-rem | b-end | b-print | b-goto
@b-statement : b-end | b-print | b-goto
b-rem : REM
b-end : /"end"
b-print : /"print" [b-printable] (/";" [b-printable])*

@ -4,6 +4,6 @@
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end
Loading…
Cancel
Save