From 3a6c74360cba0ed5fad2344cb8264a5575a7967d Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 9 Nov 2016 08:41:32 -0800 Subject: [PATCH] update --- beautiful-racket/br/demo/jsonic/expander.rkt | 27 ++++++++++--------- .../br/demo/jsonic/jsonic-test.rkt | 10 +++++++ 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 beautiful-racket/br/demo/jsonic/jsonic-test.rkt diff --git a/beautiful-racket/br/demo/jsonic/expander.rkt b/beautiful-racket/br/demo/jsonic/expander.rkt index 429af9d..fe0a4c8 100644 --- a/beautiful-racket/br/demo/jsonic/expander.rkt +++ b/beautiful-racket/br/demo/jsonic/expander.rkt @@ -1,21 +1,20 @@ #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) #'(#%module-begin - (define json-string (string-trim PARSE-TREE)) + (define json-string PARSE-TREE) (when (string->jsexpr json-string) (display json-string)))) +(provide (rename-out [jsonic-mb #%module-begin])) -(define-macro (jsonic-program STR ...) - #'(string-append STR ...)) +(define-macro (jsonic-program TOK ...) + #'(string-trim (string-append TOK ...))) +(provide jsonic-program) -(define-macro (other-char STR) - #'STR) +(define-macro (json-char TOK) + #'TOK) +(provide json-char) (define (stringify result) (cond @@ -26,8 +25,10 @@ (format "~a: ~a" (stringify k) (stringify v))) ", "))] [else ""])) -(define-macro (s-exp STR ...) +(require (for-syntax br/datum racket/string)) +(define-macro (s-exp TOK ...) (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)]) #'(stringify DATUM))) +(provide s-exp) diff --git a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt new file mode 100644 index 0000000..8972dbe --- /dev/null +++ b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt @@ -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)) $@ +] \ No newline at end of file