basic updates

pull/10/head
Matthew Butterick 8 years ago
parent 2392559263
commit de98d96c74

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

@ -6,7 +6,7 @@
(define basic-lexer (define basic-lexer
(lexer-srcloc (lexer-srcloc
[(eof) (return-without-srcloc eof)] [(eof) (return-without-srcloc eof)]
["\n" (token 'NEWLINE)] ["\n" (token 'NEWLINE lexeme)]
[whitespace (token lexeme #:skip? #t)] [whitespace (token lexeme #:skip? #t)]
[(from/stop-before "rem" "\n") (token 'REM lexeme)] [(from/stop-before "rem" "\n") (token 'REM lexeme)]
[(:or "print" "goto" "end" "+" ":") lexeme] [(:or "print" "goto" "end" "+" ":") lexeme]

@ -4,13 +4,7 @@
(module+ reader (provide read-syntax)) (module+ reader (provide read-syntax))
(define (read-syntax path port) (define (read-syntax path port)
(define-values (pline pcol ppos) (port-next-location port)) (define parse-tree (parse path (make-tokenizer port path)))
(define port+newline
(input-port-append #f port (open-input-string "\n")))
(port-count-lines! port+newline)
(set-port-next-location! port+newline pline pcol ppos)
(define parse-tree
(parse path (make-tokenizer port+newline path)))
(strip-bindings (strip-bindings
#`(module basic-mod basic-demo/expander #`(module basic-mod basic-demo/expander
#,parse-tree))) #,parse-tree)))

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module basic-parser-mod basic-demo/parse-only
#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [parser-only-mb #%module-begin]))

@ -1,7 +1,7 @@
#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-line-number : INTEGER @b-line-number : INTEGER
@b-statement : b-rem | b-end | b-print | b-goto @b-statement : b-rem | b-end | b-print | b-goto
b-rem : REM b-rem : REM
b-end : /"end" b-end : /"end"

@ -1,5 +1,5 @@
#lang basic-demo #lang basic-demo
30 rem print "ignored" 30 rem print 'ignored'
35 35
50 print "never gets here" 50 print "never gets here"
40 end 40 end

@ -0,0 +1,14 @@
#lang br/quicklang
(require brag/support "tokenizer.rkt")
(define (read-syntax path port)
(define tokens (apply-tokenizer make-tokenizer port))
(strip-bindings
#`(module basic-tokens-mod basic-demo/tokenize-only
#,@tokens)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb TOKEN ...)
#'(#%module-begin
(list TOKEN ...)))
(provide (rename-out [parser-only-mb #%module-begin]))
Loading…
Cancel
Save