diff --git a/beautiful-racket/br/demo/jsonic-b.rkt b/beautiful-racket/br/demo/jsonic-b.rkt deleted file mode 100644 index 4ae83d6..0000000 --- a/beautiful-racket/br/demo/jsonic-b.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#lang br/quicklang -(module reader br/quicklang - (require (submod "jsonic-b/main.rkt" reader)) - (provide (all-from-out (submod "jsonic-b/main.rkt" reader)))) diff --git a/beautiful-racket/br/demo/jsonic-b/expander.rkt b/beautiful-racket/br/demo/jsonic-b/expander.rkt deleted file mode 100644 index fe5d673..0000000 --- a/beautiful-racket/br/demo/jsonic-b/expander.rkt +++ /dev/null @@ -1,20 +0,0 @@ -#lang br/quicklang -(require json) -(define-macro (js-module-begin PARSE-TREE) - #'(#%module-begin - (define result-string PARSE-TREE) - (define validated-jsexpr (string->jsexpr result-string)) - (display (jsexpr->string validated-jsexpr)))) -(provide (rename-out [js-module-begin #%module-begin])) - -(define-macro (jsonic-program S-EXP-OR-JSON-CHAR ...) - #'(string-trim (string-append S-EXP-OR-JSON-CHAR ...))) -(provide jsonic-program) - -(define-macro (json-char CHAR-STR) #'CHAR-STR) -(provide json-char) - -(define-macro (s-exp SEXP-STR) - (with-pattern ([SEXP-DATUM (format-datum '~a (syntax->datum #'SEXP-STR))]) - #'(jsexpr->string SEXP-DATUM))) -(provide s-exp) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-b/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic-b/jsonic-test.rkt deleted file mode 100644 index 33613e9..0000000 --- a/beautiful-racket/br/demo/jsonic-b/jsonic-test.rkt +++ /dev/null @@ -1,12 +0,0 @@ -#lang br/demo/jsonic-b -// a line comment -[ - @$ 'null $@, - @$ #f $@, - @$ (* 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 diff --git a/beautiful-racket/br/demo/jsonic-b/main.rkt b/beautiful-racket/br/demo/jsonic-b/main.rkt deleted file mode 100644 index 408be50..0000000 --- a/beautiful-racket/br/demo/jsonic-b/main.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#lang br/quicklang -(module reader br - (require "reader.rkt") - (provide read-syntax)) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-b/parser.rkt b/beautiful-racket/br/demo/jsonic-b/parser.rkt deleted file mode 100644 index 2a282ba..0000000 --- a/beautiful-racket/br/demo/jsonic-b/parser.rkt +++ /dev/null @@ -1,4 +0,0 @@ -#lang brag -jsonic-program: (s-exp | json-char)* -s-exp: SEXP-TOK -json-char: CHAR-TOK diff --git a/beautiful-racket/br/demo/jsonic-b/reader.rkt b/beautiful-racket/br/demo/jsonic-b/reader.rkt deleted file mode 100644 index 41434ce..0000000 --- a/beautiful-racket/br/demo/jsonic-b/reader.rkt +++ /dev/null @@ -1,8 +0,0 @@ -#lang br/quicklang -(require "tokenizer.rkt" "parser.rkt") -(define (read-syntax path port) - (define parse-tree (parse path (tokenize port))) - (define module-datum `(module jsonic-module br/demo/jsonic-b/expander - ,parse-tree)) - (datum->syntax #f module-datum)) -(provide read-syntax) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-b/tokenizer.rkt b/beautiful-racket/br/demo/jsonic-b/tokenizer.rkt deleted file mode 100644 index 13aa18c..0000000 --- a/beautiful-racket/br/demo/jsonic-b/tokenizer.rkt +++ /dev/null @@ -1,14 +0,0 @@ -#lang br/quicklang -(require brag/lexer-support) -(define (tokenize port) - (define (next-token) - (define our-lexer - (lexer - [(eof) eof] - [(delimited-by "//" "\n") (next-token)] - [(delimited-by "@$" "$@") - (token 'SEXP-TOK (trim-delimiters "@$" lexeme "$@"))] - [any-char (token 'CHAR-TOK lexeme)])) - (our-lexer port)) - next-token) -(provide tokenize) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/expander.rkt b/beautiful-racket/br/demo/jsonic/expander.rkt index 46257c7..65752c8 100644 --- a/beautiful-racket/br/demo/jsonic/expander.rkt +++ b/beautiful-racket/br/demo/jsonic/expander.rkt @@ -3,35 +3,18 @@ (define-macro (js-module-begin PARSE-TREE) #'(#%module-begin (define result-string PARSE-TREE) - (when (string->jsexpr result-string) - (display result-string)))) + (define validated-jsexpr (string->jsexpr result-string)) + (display (jsexpr->string validated-jsexpr)))) (provide (rename-out [js-module-begin #%module-begin])) (define-macro (jsonic-program S-EXP-OR-JSON-CHAR ...) - #'(string-trim (string-append S-EXP-OR-JSON-CHAR ...))) + #'(string-append S-EXP-OR-JSON-CHAR ...)) (provide jsonic-program) -(define-macro (json-char TOKEN) - #'TOKEN) +(define-macro (json-char CHAR-STR) #'CHAR-STR) (provide json-char) -(define-macro (s-exp TOKEN ...) - (define token-stxs (syntax->list #'(TOKEN ...))) - (define token-strs (map syntax->datum token-stxs)) - (define s-exp-str (apply string-append token-strs)) - (with-pattern ([S-EXP-DATUM (format-datum '~a s-exp-str)]) - #'(->json S-EXP-DATUM))) -(provide s-exp) - -(define (->json x) - (cond - [(number? x) (number->string x)] - [(string? x) (format "~v" x)] - [(list? x) - (format "[~a]" (string-join (map ->json x) ", "))] - [(hash? x) - (define pair-strs (for/list ([(k v) (in-hash x)]) - (format "~a: ~a" - (->json k) (->json v)))) - (format "{~a}" (string-join pair-strs ", "))] - [else ""])) \ No newline at end of file +(define-macro (s-exp SEXP-STR) + (with-pattern ([SEXP-DATUM (format-datum '~a #'SEXP-STR)]) + #'(jsexpr->string SEXP-DATUM))) +(provide s-exp) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt index 8972dbe..2c4792e 100644 --- a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt +++ b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt @@ -1,10 +1,13 @@ #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)) $@ + @$ 'null $@, + @$ #f $@, + @$ #t $@, + @$ (* 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 diff --git a/beautiful-racket/br/demo/jsonic/parser.rkt b/beautiful-racket/br/demo/jsonic/parser.rkt index 2315a55..2a282ba 100644 --- a/beautiful-racket/br/demo/jsonic/parser.rkt +++ b/beautiful-racket/br/demo/jsonic/parser.rkt @@ -1,4 +1,4 @@ #lang brag jsonic-program: (s-exp | json-char)* -s-exp: /OPEN CHAR* /CLOSE -json-char: CHAR +s-exp: SEXP-TOK +json-char: CHAR-TOK diff --git a/beautiful-racket/br/demo/jsonic/tokenizer.rkt b/beautiful-racket/br/demo/jsonic/tokenizer.rkt index 4a76b08..13aa18c 100644 --- a/beautiful-racket/br/demo/jsonic/tokenizer.rkt +++ b/beautiful-racket/br/demo/jsonic/tokenizer.rkt @@ -5,14 +5,10 @@ (define our-lexer (lexer [(eof) eof] - [(:seq "//" (:* (char-complement "\n"))) (next-token)] - ["@$" (token 'OPEN)] - ["$@" (token 'CLOSE)] - [any-char (token 'CHAR lexeme)])) + [(delimited-by "//" "\n") (next-token)] + [(delimited-by "@$" "$@") + (token 'SEXP-TOK (trim-delimiters "@$" lexeme "$@"))] + [any-char (token 'CHAR-TOK lexeme)])) (our-lexer port)) next-token) -(provide tokenize) - - -;; (char-complement "\n") means any char but "\n" -;; (complement "\n") means any whole string except "\n" \ No newline at end of file +(provide tokenize) \ No newline at end of file