diff --git a/beautiful-racket-demo/basic-demo-2/colorer.rkt b/beautiful-racket-demo/basic-demo-2/colorer.rkt index d92c5cb..16c8814 100644 --- a/beautiful-racket-demo/basic-demo-2/colorer.rkt +++ b/beautiful-racket-demo/basic-demo-2/colorer.rkt @@ -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") \ No newline at end of file + (values (or val "") cat paren pos (+ pos span))])) \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo-2/parser.rkt b/beautiful-racket-demo/basic-demo-2/parser.rkt index c5a7c77..a63b9b1 100644 --- a/beautiful-racket-demo/basic-demo-2/parser.rkt +++ b/beautiful-racket-demo/basic-demo-2/parser.rkt @@ -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 diff --git a/beautiful-racket-demo/basic-demo-2/sample.rkt b/beautiful-racket-demo/basic-demo-2/sample.rkt index a3089f6..285173f 100644 --- a/beautiful-racket-demo/basic-demo-2/sample.rkt +++ b/beautiful-racket-demo/basic-demo-2/sample.rkt @@ -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 \ No newline at end of file diff --git a/beautiful-racket-demo/basic-demo/parser.rkt b/beautiful-racket-demo/basic-demo/parser.rkt index ff898cf..dcac829 100644 --- a/beautiful-racket-demo/basic-demo/parser.rkt +++ b/beautiful-racket-demo/basic-demo/parser.rkt @@ -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])* diff --git a/beautiful-racket-demo/basic-demo/sample.rkt b/beautiful-racket-demo/basic-demo/sample.rkt index bf4b435..96f3a1f 100644 --- a/beautiful-racket-demo/basic-demo/sample.rkt +++ b/beautiful-racket-demo/basic-demo/sample.rkt @@ -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 \ No newline at end of file