add some grammar and expander modification

This commit is contained in:
Tan, Kian-ting 2025-09-29 17:21:26 +08:00
parent 21ac5a7efe
commit 28453d20c7
14 changed files with 100 additions and 8 deletions

4
3rdparty/LICENSE INFO vendored Normal file
View file

@ -0,0 +1,4 @@
## Harfbuzz
- Old MIT License, see: https://github.com/harfbuzz/harfbuzz?tab=License-1-ov-file#readme
## LibHaru
- zlib License, see: https://github.com/libharu/libharu/blob/master/LICENSE

1
3rdparty/libharfbuzz-subset.so vendored Symbolic link
View file

@ -0,0 +1 @@
libharfbuzz-subset.so.0

1
3rdparty/libharfbuzz-subset.so.0 vendored Symbolic link
View file

@ -0,0 +1 @@
libharfbuzz-subset.so.0.61151.0

BIN
3rdparty/libharfbuzz-subset.so.0.61151.0 vendored Executable file

Binary file not shown.

1
3rdparty/libhpdf.so vendored Symbolic link
View file

@ -0,0 +1 @@
libhpdf.so.2.4

1
3rdparty/libhpdf.so.2.4 vendored Symbolic link
View file

@ -0,0 +1 @@
libhpdf.so.2.4.5

BIN
3rdparty/libhpdf.so.2.4.5 vendored Executable file

Binary file not shown.

38
expander.rkt Normal file
View file

@ -0,0 +1,38 @@
#lang br/quicklang
(require syntax/parse/define)
(define paperwidth #f)
(define paperheight #f)
(define (set x y) (set! x y))
(define (add x y) (+ x y))
(provide (matching-identifiers-out #rx"^u-" (all-defined-out)))
(define-macro (u-id ID)
#'(string->symbol ID))
(define-macro (u-atom ITEM...)
#'ITEM...)
(define-macro (u-number NUM...)
#'(number->string NUM...))
(define-macro (u-converting-num NUM...)
#'(string->number NUM...))
(define-macro-cases u-expr
[(u-expr (u-atom ITEM)) #'ITEM]
[(u-expr (u-converting-num (u-number NUM))) #'NUM]
[(u-expr X) #'X])
(define-macro-cases u-sexp
[(u-sexp (u-expr (u-atom (u-id "set"))) X Y) #'(set! X Y)]
[(u-sexp X Y) #'[X Y]]
[(u-sexp REQ OPT ...)
#'(let ([head REQ])
(eval `(,head OPT ...)))]
)
(define-macro (u-module-begin (u-program LINE ...))
#'(#%module-begin
LINE ...))
(provide (rename-out [u-module-begin #%module-begin]))

View file

@ -8,7 +8,7 @@
(define uahgi2-lexer
(lexer-srcloc
[(:or "\r\n" "\n") (token 'NEWLINE lexeme)] ; newline
[whitespace (token lexeme #:skip? #t)] ; whitespace
[whitespace (token lexeme lexeme)] ; whitespace
[(:: "\\"(char-set "@\\{}%|")) (token 'CHAR (substring lexeme
1 (string-length lexeme)))]
[(:: "@" raw-id) (token 'ID (substring lexeme

14
parse-only.rkt Normal file
View file

@ -0,0 +1,14 @@
#lang br/quicklang
(require "parser.rkt" "tokenizer.rkt")
(define (read-syntax path port)
(define parse-tree (parse path (make-tokenizer port path)))
(strip-bindings
#`(module uahgi2-parser-mod uahgi2/parse-only
#,parse-tree)))
(module+ reader (provide read-syntax))
(define-macro (parser-only-mb PARSE-TREE)
#'(#%module-begin
'PARSE-TREE))
(provide (rename-out [parser-only-mb #%module-begin]))

30
parsed-out.txt Normal file
View file

@ -0,0 +1,30 @@
#lang br/quicklang
'(u-program
(u-expr (u-atom (u-number 123)))
(u-expr (u-sexp (u-expr (u-atom (u-id "set"))) (u-expr (u-atom (u-id "paperwidth"))) (u-expr (u-converting-num (u-number 2100)))))
(u-expr (u-sexp (u-expr (u-atom (u-id "set"))) (u-expr (u-atom (u-id "paperheight"))) (u-expr (u-converting-num (u-number 2970)))))
(u-expr (u-sexp (u-expr (u-atom (u-id "set"))) (u-expr (u-atom (u-id "textsize"))) (u-expr (u-converting-num (u-number 12.3)))))
(u-expr
(u-sexp
(u-expr (u-atom (u-id "maintext")))
(u-expr
(u-series
(u-atom "\n")
(u-sexp (u-expr (u-atom (u-id "hd2"))) (u-expr (u-atom "我" "是" "貓" " " "I" "'" "m" " " "a" " " "c" "a" "t")))
(u-atom "\n")
(u-atom "天" "地" "人")
(u-atom (u-number 123))
(u-atom ".")
(u-atom "\n" "\n")
(u-atom "我" "是" "換" "行")
(u-atom "\n"))))))
> #lang uahgi2
123
{@set|@paperheight|`2970}
{@set|@textsize|`12.3}
{@maintext|
{@hd2|我是貓 I'm a cat}
天地人123.
我是換行
}

View file

@ -6,12 +6,12 @@ u-expr:
| u-converting-num
| u-sexp
u-sexp:
L_PAREN u-expr (SEPERATOR u-expr)* R_PAREN
| L_PAREN u-expr (G_SEPERATOR [(/" "|/NEWLINE)+] u-expr [(/" "|/NEWLINE)+])* R_PAREN
/L_PAREN u-expr (/SEPERATOR u-expr)* /R_PAREN
| /L_PAREN [(/" "|/NEWLINE)+] u-expr (/G_SEPERATOR [(/" "|/NEWLINE)+] u-expr [(/" "|/NEWLINE)+])* /R_PAREN ; ??
u-series: (u-atom | u-sexp)+
u-converting-num: NUM_CONVERTER (u-id | u-number)
u-atom: u-id | u-string | u-number | NEWLINE+
u-converting-num: /NUM_CONVERTER (u-id | u-number)
u-atom: u-id | u-string | u-number | (NEWLINE+)
u-number: INTEGER | DECIMAL
u-id: ID
u-string: u-char+
u-char: CHAR
@u-string: u-char+
@u-char: CHAR | " "

View file

@ -5,4 +5,4 @@
{@maintext@@
{@hd2|測試}
他對這塊土地有著愛惜的情感。今天是@today星期@dayofweek。
@@}
@@123}

2
test.rkt Normal file
View file

@ -0,0 +1,2 @@
#lang uahgi2
{@display|210|100}