jsonic2: setup
parent
1a033e7980
commit
e66b7acad1
@ -1,12 +0,0 @@
|
||||
#lang at-exp racket
|
||||
(require pict/code)
|
||||
(codeblock-pict
|
||||
#:keep-lang-line? #f
|
||||
@string-append|{
|
||||
#lang br/demo/jsonic
|
||||
{
|
||||
"string": @$(string-append "foo" "bar")$@,
|
||||
"array": @$(range 5)$@,
|
||||
"object": @$(hash "k1" "valstring" (format "~a" 42) (hash "k1" (range 10) "k2" 42))$@
|
||||
// "bar" :
|
||||
}|)
|
@ -1,33 +0,0 @@
|
||||
#lang br/quicklang
|
||||
(require json (for-syntax br/datum racket/string))
|
||||
(provide (rename-out [jsonic-mb #%module-begin])
|
||||
jsonic-program
|
||||
char
|
||||
s-val)
|
||||
|
||||
(define-macro (jsonic-mb PARSE-TREE)
|
||||
#'(#%module-begin
|
||||
(define json-string (string-trim PARSE-TREE))
|
||||
(when (string->jsexpr json-string)
|
||||
(display json-string))))
|
||||
|
||||
(define-macro (jsonic-program STR ...)
|
||||
#'(string-append STR ...))
|
||||
|
||||
(define-macro (char STR)
|
||||
#'STR)
|
||||
|
||||
(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 ""]))
|
||||
|
||||
(define-macro (s-val STR ...)
|
||||
(define s-exp-string
|
||||
(string-join (map syntax->datum (syntax->list #'(STR ...))) ""))
|
||||
(with-pattern ([DATUM (format-datum '~a s-exp-string)])
|
||||
#'(stringify DATUM)))
|
@ -1,9 +1,13 @@
|
||||
#lang br/demo/jsonic
|
||||
42
|
||||
"string"
|
||||
["array", "of", "strings"]
|
||||
{
|
||||
"key": 42,
|
||||
25: "value",
|
||||
[1, 2, 3]: {"subkey": 21}
|
||||
}
|
||||
#lang br/demo/jsonic-pro
|
||||
// a line comment
|
||||
[
|
||||
@$ 'null $@,
|
||||
@$ #f $@,
|
||||
@$ #t $@,
|
||||
@$ (* 6 7) $@,
|
||||
@$ "string" $@,
|
||||
@$ (list "array" "of" "strings") $@,
|
||||
@$ (hash 'key-1 42
|
||||
'key-2 "value"
|
||||
'key-3 (hash 'subkey 21)) $@
|
||||
]
|
@ -1,7 +0,0 @@
|
||||
#lang brag
|
||||
|
||||
jsonic-program: (char | s-val)*
|
||||
|
||||
char: CHAR
|
||||
|
||||
s-val: /OPEN CHAR* /CLOSE
|
Loading…
Reference in New Issue