put on source locations

pull/21/head
Matthew Butterick 6 years ago
parent 177f0bbb09
commit 0b24352082

@ -1,5 +1,5 @@
#lang br/quicklang #lang br/quicklang
(require "grammar.rkt" brag/support) (require "parser.rkt" brag/support)
(module+ reader (module+ reader
(provide read-syntax)) (provide read-syntax))
@ -9,8 +9,8 @@
":" "," "(" ")" "//" "/*" "*/" ":" "," "(" ")" "//" "/*" "*/"
"if" "while" "==" "!=" "function" "return" "++")) "if" "while" "==" "!=" "function" "return" "++"))
(define tokenize (define scriptish-lexer
(lexer (lexer-srcloc
[(:or (from/stop-before "//" "\n") [(:or (from/stop-before "//" "\n")
(from/to "/*" "*/")) (token 'COMMENT #:skip? #t)] (from/to "/*" "*/")) (token 'COMMENT #:skip? #t)]
[reserved-terms (token lexeme (string->symbol lexeme))] [reserved-terms (token lexeme (string->symbol lexeme))]
@ -21,13 +21,21 @@
[(:+ (char-set "0123456789")) [(:+ (char-set "0123456789"))
(token 'INTEGER (string->number lexeme))] (token 'INTEGER (string->number lexeme))]
[(:or (from/to "\"" "\"") (from/to "'" "'")) [(:or (from/to "\"" "\"") (from/to "'" "'"))
(token 'STRING (string-trim lexeme (substring lexeme 0 1)))] (let ()
(token 'STRING (string-trim lexeme (substring lexeme 0 1))))]
[whitespace (token 'WHITE #:skip? #t)] [whitespace (token 'WHITE #:skip? #t)]
[any-char lexeme])) [any-char lexeme]))
(define (make-tokenizer ip [src #f])
(port-count-lines! ip)
(lexer-file-path src)
(define (next-token) (scriptish-lexer ip))
next-token)
(define (read-syntax src ip) (define (read-syntax src ip)
(define parse-tree (parse (λ () (tokenize ip)))) (println src)
(define parse-tree (parse src (make-tokenizer ip src)))
(strip-context (strip-context
(with-syntax ([PT parse-tree]) (with-syntax ([PT parse-tree])
#'(module you-win scriptish-demo/expander #'(module scriptish-mod scriptish-demo/expander
PT)))) PT))))
Loading…
Cancel
Save