From a7080a47b30616aa85f7556d6bb57c37d810e81d Mon Sep 17 00:00:00 2001 From: Tan Kian-ting Date: Thu, 23 Oct 2025 05:52:34 +0800 Subject: [PATCH] add cjk-splitter pass --- expander.rkt | 21 +++++++++++++++++++++ test1.ug | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/expander.rkt b/expander.rkt index 2224d2f..211e3c7 100644 --- a/expander.rkt +++ b/expander.rkt @@ -69,12 +69,33 @@ ["body" . ,remove-newline-between-cjk-aux]))) +(define [splitter-cjk-aux cont] + (display (list-ref cont 1)) + (define [splitter-cjk-unit x] + (define tmp (regexp-match* #rx"[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\U00020000-\U0002EBEF\u3000-\u303F·,。!?:」』》】]〕』〗〉}「『《〔[【『〖〈{…—]" x #:gap-select? #t)) + (filter (lambda (x) [not (equal? x "")]) tmp)) + (define [splitter-cjk-proc res rem] + (cond + [(eq? rem '()) (reverse res)] + [(string? [car rem]) [splitter-cjk-proc [append (reverse (splitter-cjk-unit [car rem])) res] (cdr rem)]] + [else [splitter-cjk-proc [cons (car rem) res] (cdr rem)]] + )) + (list-set cont 1 (splitter-cjk-proc '() (list-ref cont 1)))) + +(define splitter-cjk (make-hash `(["lang" . "zh"] + ["body" . ,splitter-cjk-aux]))) + + + + + (define-syntax append-plugin! (syntax-rules () [(_ ls plugin) (set! ls (reverse (cons plugin (reverse ls))))])) [append-plugin! plugin-list two-newlines-into-par] [append-plugin! plugin-list remove-newline-between-cjk] +[append-plugin! plugin-list splitter-cjk] (define (main-text txt) (begin diff --git a/test1.ug b/test1.ug index 9363ced..813293b 100644 --- a/test1.ug +++ b/test1.ug @@ -1,8 +1,9 @@ -#lang uahgi-ng +#lang uahgi2 {@display|`10.3} {@dict?|@main-config} +{@set-main-config|lang|{@list|zh}} {@set-main-config|paper-width|`2480} {@display|{@dict-ref|@main-config|paper-width}} {@main-text| -天地人123我為貓} +{@hd2|我是貓 I'm a cat}天地人123我為貓} {@display|@main-frame} \ No newline at end of file