resume in lexing comments

pull/2/head
Matthew Butterick 8 years ago
parent 12438d2900
commit a3f434c551

@ -0,0 +1,4 @@
#lang br/quicklang
(module reader br/quicklang
(require "jsonic/reader.rkt")
(provide (all-from-out "jsonic/reader.rkt")))

@ -0,0 +1,7 @@
#lang br/quicklang
(define-macro (jsonic-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [jsonic-mb #%module-begin]))

@ -0,0 +1,3 @@
#lang br/demo/jsonic
{"id": "file"}

@ -0,0 +1,19 @@
#lang brag
jsonic-program: value*
value: array | object | string | number
object: "{" [kvpair ("," kvpair)*] "}"
array: "[" [value ("," value)*] "]"
string: STRING
number: NUMBER
kvpair: STRING ":" value
s-val: "@" ("[" STRING "]" | "{" STRING "}" | "#" STRING "#" )

@ -0,0 +1,35 @@
#lang at-exp br/quicklang
(require "parser.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (tokenize port)))
(define module-datum `(module bf-mod br/demo/jsonic/expander
,parse-tree))
(datum->syntax #f module-datum))
(provide read-syntax)
(require parser-tools/lex parser-tools/lex-sre brag/support)
(define (tokenize port)
(define (next-token)
(define our-lexer
(lexer
[(eof) eof]
[(seq (* "\n") (* whitespace) "//" any-string (* "\n")) (next-token)]
[whitespace (next-token)]
[(char-set ",:[]{}") lexeme]
[(seq (* "-") (+ (or numeric "."))) (token 'NUMBER lexeme)] ;; Q: what is grammar for a JS number?
[(seq "\"" (complement (seq any-string "\"" any-string)) "\"") (token 'STRING (string-trim lexeme "\""))]))
(our-lexer port))
next-token)
(define (test-tokenize str)
(define ip (open-input-string str))
(define token-producer (tokenize ip))
(for/list ([token (in-producer token-producer eof)])
token))
(module+ main
(test-tokenize @string-append{
{"id": "file"
// yeah baby
}}))
Loading…
Cancel
Save