diff --git a/uahgi-ng/expander.rkt b/uahgi-ng/expander.rkt index 25a7b19..5d44ddf 100644 --- a/uahgi-ng/expander.rkt +++ b/uahgi-ng/expander.rkt @@ -1,3 +1,42 @@ + (module uahgi-ng racket/base - (provide lambda quote add1 begin #%module-begin #%app #%datum #%expression #%top) + (require racket/dict) + (define main-config (make-hash + '(["paper-width". 2480] + ["paper-height". 3508] + ["font-family" . "FreeSerif"] + ["font-family-CJK" . "Noto Sans CJK TC"] + ["font-size" . 14] + ["font-weight" . "regular"] + ["font-style" . "normal"] + + ))) + (define main-frame (make-hash + '(["id" . 1] + ["font-family" . (dict-ref main-config "font-family")] + ["class" . frame] + ["width" . 2000] + ["height" . 3000] + ["x" . 200] + ["y" . 250] + ["content" . #f]))) + + (define (set-main-config attr val) + (dict-set! main-config attr val)) + + (define (main-text txt) + (dict-set! main-frame "content" txt)) + + (define-syntax text-series + (syntax-rules () + [(_ x ...) + ; delete the beginning newline + (if (eq? (caar `(x ...)) "\n") + `('text ,(cdar `(x ...))) + `('text ,(caar `(x ...)) ,(cdar `(x ...)))))])) + + (provide text-series main-text main-frame main-config set-main-config set! + (all-from-out racket/base) (all-from-out racket/dict) + #%module-begin #%app #%datum #%expression #%top) + ) diff --git a/uahgi-ng/lexer.rkt b/uahgi-ng/lexer.rkt index 5cf2bce..e8fd2f9 100644 --- a/uahgi-ng/lexer.rkt +++ b/uahgi-ng/lexer.rkt @@ -9,7 +9,7 @@ (define-lex-abbrev digits (+ (char-set "0123456789"))) -(define-lex-abbrev raw-id (: (or "_" (/ "a" "z") (/ "A" "Z")) (* (or "_" (/ "0" "9") (/ "a" "z") (/ "A" "Z"))))) +(define-lex-abbrev raw-id (: (or "_" (/ "a" "z") (/ "A" "Z")) (* (or "_" "-" "!" "?" (/ "0" "9") (/ "a" "z") (/ "A" "Z"))))) (define-lex-abbrev any-other-char (~ (char-set "0123456789@\\{}%|"))) (define uahgi2-lexer diff --git a/uahgi-ng/parser.rkt b/uahgi-ng/parser.rkt index d9d3e1a..669db41 100644 --- a/uahgi-ng/parser.rkt +++ b/uahgi-ng/parser.rkt @@ -31,8 +31,8 @@ (define sexp-elem/p - (delay/p (or/p expr/p - series/p))) + (delay/p (or/p (try/p series/p) + expr/p))) (define sexp/p @@ -47,11 +47,6 @@ converting-num/p sexp/p)) - - - - - (define series-elem/p (or/p newline/p num/p @@ -63,12 +58,6 @@ (do [args <- (many/p series-elem/p #:min 2)] (pure (list 'text-series args)))) - - - - - - (define prog/p (syntax/p (do diff --git a/uahgi-ng/test1.ug b/uahgi-ng/test1.ug new file mode 100644 index 0000000..9363ced --- /dev/null +++ b/uahgi-ng/test1.ug @@ -0,0 +1,8 @@ +#lang uahgi-ng +{@display|`10.3} +{@dict?|@main-config} +{@set-main-config|paper-width|`2480} +{@display|{@dict-ref|@main-config|paper-width}} +{@main-text| +天地人123我為貓} +{@display|@main-frame} \ No newline at end of file