diff --git a/beautiful-racket/br/demo/jsonic-pro.rkt b/beautiful-racket/br/demo/jsonic-pro.rkt new file mode 100644 index 0000000..2179e34 --- /dev/null +++ b/beautiful-racket/br/demo/jsonic-pro.rkt @@ -0,0 +1,4 @@ +#lang br/quicklang +(module reader br/quicklang + (require (submod "jsonic-pro/main.rkt" reader)) + (provide (all-from-out (submod "jsonic-pro/main.rkt" reader)))) diff --git a/beautiful-racket/br/demo/jsonic/codepict.rkt b/beautiful-racket/br/demo/jsonic-pro/codepict.rkt similarity index 100% rename from beautiful-racket/br/demo/jsonic/codepict.rkt rename to beautiful-racket/br/demo/jsonic-pro/codepict.rkt diff --git a/beautiful-racket/br/demo/jsonic/color-lexer.rkt b/beautiful-racket/br/demo/jsonic-pro/color-lexer.rkt similarity index 100% rename from beautiful-racket/br/demo/jsonic/color-lexer.rkt rename to beautiful-racket/br/demo/jsonic-pro/color-lexer.rkt diff --git a/beautiful-racket/br/demo/jsonic/expander.rkt b/beautiful-racket/br/demo/jsonic-pro/expander.rkt similarity index 100% rename from beautiful-racket/br/demo/jsonic/expander.rkt rename to beautiful-racket/br/demo/jsonic-pro/expander.rkt diff --git a/beautiful-racket/br/demo/jsonic/indenter.rkt b/beautiful-racket/br/demo/jsonic-pro/indenter.rkt similarity index 100% rename from beautiful-racket/br/demo/jsonic/indenter.rkt rename to beautiful-racket/br/demo/jsonic-pro/indenter.rkt diff --git a/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt new file mode 100644 index 0000000..8bf0080 --- /dev/null +++ b/beautiful-racket/br/demo/jsonic-pro/jsonic-test.rkt @@ -0,0 +1,9 @@ +#lang br/demo/jsonic +42 +"string" +["array", "of", "strings"] +{ + "key": 42, + 25: "value", + [1, 2, 3]: {"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 new file mode 100644 index 0000000..05d6b3a --- /dev/null +++ b/beautiful-racket/br/demo/jsonic-pro/main.rkt @@ -0,0 +1,51 @@ +#lang at-exp br/quicklang +(require "parser.rkt") + +#| +Demonstrate: ++ color lexing ++ indentation ++ toolbar buttons ++ pinpoint errors ++ unit tests +|# + +(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) + (case key + [(color-lexer) + (dynamic-require 'br/demo/jsonic/color-lexer 'color-lexer (λ () #f))] + [(drracket:indentation) + (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)) diff --git a/beautiful-racket/br/demo/jsonic-pro/parser.rkt b/beautiful-racket/br/demo/jsonic-pro/parser.rkt new file mode 100644 index 0000000..cd618d3 --- /dev/null +++ b/beautiful-racket/br/demo/jsonic-pro/parser.rkt @@ -0,0 +1,7 @@ +#lang brag + +jsonic-program: (char | s-val)* + +char: CHAR + +s-val: /OPEN CHAR* /CLOSE \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/toolbar.rkt b/beautiful-racket/br/demo/jsonic-pro/toolbar.rkt similarity index 100% rename from beautiful-racket/br/demo/jsonic/toolbar.rkt rename to beautiful-racket/br/demo/jsonic-pro/toolbar.rkt diff --git a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt b/beautiful-racket/br/demo/jsonic/jsonic-test.rkt deleted file mode 100644 index f53f20d..0000000 --- a/beautiful-racket/br/demo/jsonic/jsonic-test.rkt +++ /dev/null @@ -1,9 +0,0 @@ -#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" : -} diff --git a/beautiful-racket/br/demo/jsonic/main.rkt b/beautiful-racket/br/demo/jsonic/main.rkt index 3821331..408be50 100644 --- a/beautiful-racket/br/demo/jsonic/main.rkt +++ b/beautiful-racket/br/demo/jsonic/main.rkt @@ -1,51 +1,4 @@ -#lang at-exp br/quicklang -(require "parser.rkt") - -#| -Demonstrate: -+ color lexing -+ indentation -+ toolbar buttons -+ pinpoint errors -+ unit tests -|# - -(module+ reader - (define (read-syntax path port) - (define parse-tree (parse path (tokenize port))) - (define module-datum `(module bf-mod br/demo/jsonic/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) - (case key - [(color-lexer) - (dynamic-require 'br/demo/jsonic/color-lexer 'color-lexer (λ () #f))] - [(drracket:indentation) - (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)) +#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/parser.rkt b/beautiful-racket/br/demo/jsonic/parser.rkt index cd618d3..ae1ed5d 100644 --- a/beautiful-racket/br/demo/jsonic/parser.rkt +++ b/beautiful-racket/br/demo/jsonic/parser.rkt @@ -1,7 +1,4 @@ #lang brag - jsonic-program: (char | s-val)* - char: CHAR - s-val: /OPEN CHAR* /CLOSE \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/reader.rkt b/beautiful-racket/br/demo/jsonic/reader.rkt new file mode 100644 index 0000000..a6458c5 --- /dev/null +++ b/beautiful-racket/br/demo/jsonic/reader.rkt @@ -0,0 +1,8 @@ +#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 "expander.rkt" + ,parse-tree)) + (datum->syntax #f module-datum)) +(provide read-syntax) \ No newline at end of file diff --git a/beautiful-racket/br/demo/jsonic/tokenizer.rkt b/beautiful-racket/br/demo/jsonic/tokenizer.rkt new file mode 100644 index 0000000..8d7a893 --- /dev/null +++ b/beautiful-racket/br/demo/jsonic/tokenizer.rkt @@ -0,0 +1,16 @@ +#lang br/quicklang +(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) +(provide tokenize) \ No newline at end of file