dev-srcloc
Matthew Butterick 8 years ago
parent 586189012f
commit 3a6c74360c

@ -1,21 +1,20 @@
#lang br/quicklang #lang br/quicklang
(require json (for-syntax br/datum racket/string))
(provide (rename-out [jsonic-mb #%module-begin])
jsonic-program
other-char
s-exp)
(require json)
(define-macro (jsonic-mb PARSE-TREE) (define-macro (jsonic-mb PARSE-TREE)
#'(#%module-begin #'(#%module-begin
(define json-string (string-trim PARSE-TREE)) (define json-string PARSE-TREE)
(when (string->jsexpr json-string) (when (string->jsexpr json-string)
(display json-string)))) (display json-string))))
(provide (rename-out [jsonic-mb #%module-begin]))
(define-macro (jsonic-program STR ...) (define-macro (jsonic-program TOK ...)
#'(string-append STR ...)) #'(string-trim (string-append TOK ...)))
(provide jsonic-program)
(define-macro (other-char STR) (define-macro (json-char TOK)
#'STR) #'TOK)
(provide json-char)
(define (stringify result) (define (stringify result)
(cond (cond
@ -26,8 +25,10 @@
(format "~a: ~a" (stringify k) (stringify v))) ", "))] (format "~a: ~a" (stringify k) (stringify v))) ", "))]
[else ""])) [else ""]))
(define-macro (s-exp STR ...) (require (for-syntax br/datum racket/string))
(define-macro (s-exp TOK ...)
(define s-exp-string (define s-exp-string
(string-join (map syntax->datum (syntax->list #'(STR ...))) "")) (string-join (map syntax->datum (syntax->list #'(TOK ...))) ""))
(with-pattern ([DATUM (format-datum '~a s-exp-string)]) (with-pattern ([DATUM (format-datum '~a s-exp-string)])
#'(stringify DATUM))) #'(stringify DATUM)))
(provide s-exp)

@ -0,0 +1,10 @@
#lang br/demo/jsonic
// a line comment
[
@$ (* 6 7) $@,
@$ "string" $@,
@$ (list "array" "of" "strings") $@,
@$ (hash "key-1" 42
"key-2" "value"
"key-3" (hash "subkey" 21)) $@
]
Loading…
Cancel
Save