simplify jsonic
parent
2c6d8a781a
commit
e792346b96
@ -1,7 +1,28 @@
|
|||||||
#lang br/quicklang
|
#lang br/quicklang
|
||||||
|
(provide (rename-out [jsonic-mb #%module-begin])
|
||||||
|
jsonic-program
|
||||||
|
char
|
||||||
|
s-val)
|
||||||
|
|
||||||
(define-macro (jsonic-mb PARSE-TREE)
|
(define-macro (jsonic-mb PARSE-TREE)
|
||||||
#'(#%module-begin
|
#'(#%module-begin
|
||||||
'PARSE-TREE))
|
(display (string-trim PARSE-TREE))))
|
||||||
(provide (rename-out [jsonic-mb #%module-begin]))
|
|
||||||
|
|
||||||
|
(define-macro (jsonic-program STR ...)
|
||||||
|
#'(string-append STR ...))
|
||||||
|
|
||||||
|
(define-macro (char TOK)
|
||||||
|
#'TOK)
|
||||||
|
|
||||||
|
(define (stringify result)
|
||||||
|
(cond
|
||||||
|
[(number? result) (number->string result)]
|
||||||
|
[(string? result) (format "~v" result)]
|
||||||
|
[(list? result) (format "[~a]" (string-join (map stringify result) ", "))]
|
||||||
|
[(hash? result) (format "{~a}" (string-join (for/list ([(k v) (in-hash result)])
|
||||||
|
(format "~a: ~a" (stringify k) (stringify v))) ", "))]
|
||||||
|
[else (error 'unknown-thing)]))
|
||||||
|
|
||||||
|
(define-macro (s-val TOK ...)
|
||||||
|
(with-pattern ([DATUM (read (open-input-string (apply string-append (map syntax->datum (syntax->list #'(TOK ...))))))])
|
||||||
|
#'(stringify DATUM)))
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
#lang br/demo/jsonic
|
#lang br/demo/jsonic
|
||||||
|
|
||||||
{"foo": @(+ 4 (+ 4 2)),
|
{"number": @$(* 6 7)$@,
|
||||||
"bar" : ")"}
|
"string": @$(string-append "foo" "bar")$@,
|
||||||
|
"array": @$(range 5)$@,
|
||||||
|
"object": @$(hash "k1" "valstring" "k2" 42)$@
|
||||||
|
// "bar" :
|
||||||
|
}
|
@ -1,18 +1,7 @@
|
|||||||
#lang brag
|
#lang brag
|
||||||
|
|
||||||
jsonic-program: value*
|
jsonic-program: (char | s-val)*
|
||||||
|
|
||||||
value: array | object | string | number | s-val
|
char: CHAR
|
||||||
|
|
||||||
object: /"{" [kvpair (/"," kvpair)*] /"}"
|
s-val: /OPEN CHAR* /CLOSE
|
||||||
|
|
||||||
array: /"[" [value (/"," value)*] /"]"
|
|
||||||
|
|
||||||
string: STRING
|
|
||||||
|
|
||||||
number: NUMBER
|
|
||||||
|
|
||||||
kvpair: STRING /":" value
|
|
||||||
|
|
||||||
s-val: S-EXP
|
|
||||||
|
|
Loading…
Reference in New Issue