simplify jsonic
parent
2c6d8a781a
commit
e792346b96
@ -1,7 +1,28 @@
|
||||
#lang br/quicklang
|
||||
(provide (rename-out [jsonic-mb #%module-begin])
|
||||
jsonic-program
|
||||
char
|
||||
s-val)
|
||||
|
||||
(define-macro (jsonic-mb PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
'PARSE-TREE))
|
||||
(provide (rename-out [jsonic-mb #%module-begin]))
|
||||
(display (string-trim PARSE-TREE))))
|
||||
|
||||
(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
|
||||
|
||||
{"foo": @(+ 4 (+ 4 2)),
|
||||
"bar" : ")"}
|
||||
{"number": @$(* 6 7)$@,
|
||||
"string": @$(string-append "foo" "bar")$@,
|
||||
"array": @$(range 5)$@,
|
||||
"object": @$(hash "k1" "valstring" "k2" 42)$@
|
||||
// "bar" :
|
||||
}
|
@ -1,18 +1,7 @@
|
||||
#lang brag
|
||||
|
||||
jsonic-program: value*
|
||||
jsonic-program: (char | s-val)*
|
||||
|
||||
value: array | object | string | number | s-val
|
||||
|
||||
object: /"{" [kvpair (/"," kvpair)*] /"}"
|
||||
|
||||
array: /"[" [value (/"," value)*] /"]"
|
||||
|
||||
string: STRING
|
||||
|
||||
number: NUMBER
|
||||
|
||||
kvpair: STRING /":" value
|
||||
|
||||
s-val: S-EXP
|
||||
char: CHAR
|
||||
|
||||
s-val: /OPEN CHAR* /CLOSE
|
Loading…
Reference in New Issue