how to do this with at-exp reader
This commit is contained in:
parent
a3f434c551
commit
cd936ae09b
|
@ -1,3 +1,3 @@
|
||||||
#lang br/demo/jsonic
|
#lang br/demo/jsonic
|
||||||
|
|
||||||
{"id": "file"}
|
{"foo": @#(+ 4 2)#}
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
jsonic-program: value*
|
jsonic-program: value*
|
||||||
|
|
||||||
value: array | object | string | number
|
value: array | object | string | number | s-val
|
||||||
|
|
||||||
object: "{" [kvpair ("," kvpair)*] "}"
|
object: /"{" [kvpair (/"," kvpair)*] /"}"
|
||||||
|
|
||||||
array: "[" [value ("," value)*] "]"
|
array: /"[" [value (/"," value)*] /"]"
|
||||||
|
|
||||||
string: STRING
|
string: STRING
|
||||||
|
|
||||||
number: NUMBER
|
number: NUMBER
|
||||||
|
|
||||||
kvpair: STRING ":" value
|
kvpair: STRING /":" value
|
||||||
|
|
||||||
s-val: "@" ("[" STRING "]" | "{" STRING "}" | "#" STRING "#" )
|
s-val: "@" ("[" STRING "]" | "{" STRING "}" | "#" STRING "#" )
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,13 @@
|
||||||
(define our-lexer
|
(define our-lexer
|
||||||
(lexer
|
(lexer
|
||||||
[(eof) eof]
|
[(eof) eof]
|
||||||
[(seq (* "\n") (* whitespace) "//" any-string (* "\n")) (next-token)]
|
[(or whitespace
|
||||||
[whitespace (next-token)]
|
(seq "//" (complement (seq any-string "\n" any-string)) "\n")) (next-token)]
|
||||||
[(char-set ",:[]{}") lexeme]
|
[(char-set ",:[]{}@#") lexeme]
|
||||||
[(seq (* "-") (+ (or numeric "."))) (token 'NUMBER lexeme)] ;; Q: what is grammar for a JS number?
|
[(seq (repetition 0 1 "-") (+ numeric) (repetition 0 1 (seq "." (* numeric))))
|
||||||
[(seq "\"" (complement (seq any-string "\"" any-string)) "\"") (token 'STRING (string-trim lexeme "\""))]))
|
(token 'NUMBER lexeme)] ;; Q: what is grammar for a JS number?
|
||||||
|
[(seq "\"" (complement (seq any-string "\"" any-string)) "\"") (token 'STRING (string-trim lexeme "\""))]
|
||||||
|
[any-char lexeme]))
|
||||||
(our-lexer port))
|
(our-lexer port))
|
||||||
next-token)
|
next-token)
|
||||||
|
|
||||||
|
@ -28,8 +30,7 @@
|
||||||
(for/list ([token (in-producer token-producer eof)])
|
(for/list ([token (in-producer token-producer eof)])
|
||||||
token))
|
token))
|
||||||
|
|
||||||
(module+ main
|
(test-tokenize #<<HERE
|
||||||
(test-tokenize @string-append{
|
{"foo": @#(+ 4 2)#}
|
||||||
{"id": "file"
|
HERE
|
||||||
// yeah baby
|
)
|
||||||
}}))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user