diff --git a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt index 9343f6e..868a5ed 100644 --- a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt +++ b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt @@ -1,3 +1,3 @@ #lang br/demo/jsonic -{"id": "file"} \ No newline at end of file +{"foo": @#(+ 4 2)#} \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/parser.rkt b/beautiful-racket/br/demo/jsonic/parser.rkt index 30e2da9..b5cb4df 100644 --- a/beautiful-racket/br/demo/jsonic/parser.rkt +++ b/beautiful-racket/br/demo/jsonic/parser.rkt @@ -2,17 +2,17 @@ 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 number: NUMBER -kvpair: STRING ":" value +kvpair: STRING /":" value s-val: "@" ("[" STRING "]" | "{" STRING "}" | "#" STRING "#" ) diff --git a/beautiful-racket/br/demo/jsonic/reader.rkt b/beautiful-racket/br/demo/jsonic/reader.rkt index f513cd9..25c7c6a 100644 --- a/beautiful-racket/br/demo/jsonic/reader.rkt +++ b/beautiful-racket/br/demo/jsonic/reader.rkt @@ -14,11 +14,13 @@ (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 "\""))])) + [(or whitespace + (seq "//" (complement (seq any-string "\n" any-string)) "\n")) (next-token)] + [(char-set ",:[]{}@#") lexeme] + [(seq (repetition 0 1 "-") (+ numeric) (repetition 0 1 (seq "." (* numeric)))) + (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)) next-token) @@ -28,8 +30,7 @@ (for/list ([token (in-producer token-producer eof)]) token)) -(module+ main - (test-tokenize @string-append{ - {"id": "file" - // yeah baby - }})) \ No newline at end of file +(test-tokenize #<