adjust rem semantics

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

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

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

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

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

@ -4,6 +4,6 @@
50 print "never gets here" 50 print "never gets here"
40 end 40 end
60 print 'three' : print 1.0 + 3 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" 10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end 20 print : goto 60.0 : end
Loading…
Cancel
Save