From e66b7acad13e9a0a967e4c4a867fd1c2b4ac9c6a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 30 Nov 2016 10:29:32 -0800 Subject: [PATCH] jsonic2: setup --- .../br/demo/jsonic-pro/codepict.rkt | 12 ----- .../br/demo/jsonic-pro/expander.rkt | 33 -------------- .../br/demo/jsonic-pro/jsonic-test.rkt | 22 +++++---- beautiful-racket/br/demo/jsonic-pro/main.rkt | 45 +++++-------------- .../br/demo/jsonic-pro/parser.rkt | 7 --- 5 files changed, 25 insertions(+), 94 deletions(-) delete mode 100644 beautiful-racket/br/demo/jsonic-pro/codepict.rkt delete mode 100644 beautiful-racket/br/demo/jsonic-pro/expander.rkt delete mode 100644 beautiful-racket/br/demo/jsonic-pro/parser.rkt diff --git a/beautiful-racket/br/demo/jsonic-pro/codepict.rkt b/beautiful-racket/br/demo/jsonic-pro/codepict.rkt deleted file mode 100644 index 94bd447..0000000 --- a/beautiful-racket/br/demo/jsonic-pro/codepict.rkt +++ /dev/null @@ -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" : -}|) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-pro/expander.rkt b/beautiful-racket/br/demo/jsonic-pro/expander.rkt deleted file mode 100644 index b93d58c..0000000 --- a/beautiful-racket/br/demo/jsonic-pro/expander.rkt +++ /dev/null @@ -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))) diff --git a/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt index 8bf0080..076e00e 100644 --- a/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt +++ b/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt @@ -1,9 +1,13 @@ -#lang br/demo/jsonic -42 -"string" -["array", "of", "strings"] -{ - "key": 42, - 25: "value", - [1, 2, 3]: {"subkey": 21} -} \ No newline at end of file +#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)) $@ + ] \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-pro/main.rkt b/beautiful-racket/br/demo/jsonic-pro/main.rkt index 05d6b3a..f601270 100644 --- a/beautiful-racket/br/demo/jsonic-pro/main.rkt +++ b/beautiful-racket/br/demo/jsonic-pro/main.rkt @@ -1,37 +1,22 @@ -#lang at-exp br/quicklang -(require "parser.rkt") +#lang br/quicklang +(module reader br + (require br/demo/jsonic/reader) + (provide (all-from-out br/demo/jsonic/reader))) + +(require br/demo/jsonic/expander) +(provide (all-from-out br/demo/jsonic/expander)) #| Demonstrate: ++ contracts ++ unit tests + color lexing + indentation + toolbar buttons -+ pinpoint errors -+ unit tests ++ docs ++ info.rkt |# -(module+ reader - (define (read-syntax path port) - (define parse-tree (parse path (tokenize port))) - (define module-datum `(module bf-mod br/demo/jsonic-pro/expander - ,parse-tree)) - (datum->syntax #f module-datum)) - (provide read-syntax get-info)) - -(require parser-tools/lex parser-tools/lex-sre brag/support) -(define (tokenize port) - (define (next-token) - (define our-lexer - (lexer - [(eof) eof] - ;; (char-complement "\n") means any char but "\n" - ;; (complement "\n") means any whole string except "\n" - [(seq "//" (* (char-complement "\n"))) (next-token)] - ["@$" (token 'OPEN lexeme)] - ["$@" (token 'CLOSE lexeme)] - [any-char (token 'CHAR lexeme)])) - (our-lexer port)) - next-token) (define (get-info . _) (λ (key default) @@ -42,10 +27,4 @@ Demonstrate: (dynamic-require 'br/demo/jsonic/indenter 'indenter (λ () #f))] [(drracket:toolbar-buttons) (dynamic-require 'br/demo/jsonic/toolbar 'buttons (λ () #f))] - [else default]))) - -(define (test-tokenize str) - (define ip (open-input-string str)) - (define token-producer (tokenize ip)) - (for/list ([token (in-producer token-producer eof)]) - token)) + [else default]))) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic-pro/parser.rkt b/beautiful-racket/br/demo/jsonic-pro/parser.rkt deleted file mode 100644 index cd618d3..0000000 --- a/beautiful-racket/br/demo/jsonic-pro/parser.rkt +++ /dev/null @@ -1,7 +0,0 @@ -#lang brag - -jsonic-program: (char | s-val)* - -char: CHAR - -s-val: /OPEN CHAR* /CLOSE \ No newline at end of file