Skip to content

Commit 70eb4d9

Browse files
committed
fix the handling of subscripts and superscripts
the previous version didn't work right if there was a ^ in the name of the non-terminal
1 parent 70e4f77 commit 70eb4d9

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

redex-pict-lib/redex/private/core-layout.rkt

+31-18
Original file line numberDiff line numberDiff line change
@@ -777,25 +777,38 @@
777777
((current-text) (if (string? atom) atom (format "~a" atom))
778778
pink-code-font
779779
(default-font-size)))))]
780-
[(and (symbol? atom)
781-
(not (equal? atom '_))
782-
(regexp-match #rx"^([^_^]*)_([^^]*)\\^?(.*)$" (symbol->string atom)))
783-
=>
784-
(match-lambda
785-
[(list _ nt sub sup)
786-
(let* ([sub-pict (if (regexp-match? #rx"^′+$" sub)
787-
(basic-text sub (non-terminal-style))
788-
(basic-text sub (non-terminal-subscript-style)))]
789-
[sup-pict (basic-text sup (non-terminal-superscript-style))]
790-
[sub+sup (lbl-superimpose sub-pict sup-pict)])
791-
(list (non-terminal->token col span nt)
792-
(make-pict-token (+ col span) 0 sub+sup)))])]
793-
[(or (memq atom all-nts)
794-
(memq atom underscore-allowed))
795-
(list (non-terminal->token col span (symbol->string atom)))]
796780
[(symbol? atom)
797-
(list (or (rewrite-atomic col span atom literal-style)
798-
(make-string-token col span (symbol->string atom) (literal-style))))]
781+
(define (not-nt)
782+
(list (or (rewrite-atomic col span atom literal-style)
783+
(make-string-token col span (symbol->string atom) (literal-style)))))
784+
(define nt-m (regexp-match #rx"^([^_]*)_(.*)$" (symbol->string atom)))
785+
(cond
786+
[nt-m
787+
(define nt-name (list-ref nt-m 1))
788+
(define after-underscore (list-ref nt-m 2))
789+
(define nt-name-sym (string->symbol nt-name))
790+
(cond
791+
[(or (memq nt-name-sym all-nts)
792+
(memq nt-name-sym underscore-allowed))
793+
(define subsup-m (regexp-match #rx"^([^^]*)\\^(.*)$" after-underscore))
794+
(define-values (sub sup)
795+
(cond
796+
[subsup-m (values (list-ref subsup-m 1) (list-ref subsup-m 2))]
797+
[else (values after-underscore "")]))
798+
(define sub-pict (if (regexp-match? #rx"^′+$" sub)
799+
(basic-text sub (non-terminal-style))
800+
(basic-text sub (non-terminal-subscript-style))))
801+
(define sup-pict (basic-text sup (non-terminal-superscript-style)))
802+
(define sub+sup (lbl-superimpose sub-pict sup-pict))
803+
(list (non-terminal->token col span nt-name)
804+
(make-pict-token (+ col span) 0 sub+sup))]
805+
[else
806+
(not-nt)])]
807+
[(or (memq atom all-nts)
808+
(memq atom underscore-allowed))
809+
(list (non-terminal->token col span (symbol->string atom)))]
810+
[else
811+
(not-nt)])]
799812
[(or (member atom '("(" ")" "[" "]" "{" "}"))
800813
;; Typeset keywords in the same font as parentheses:
801814
(and (string? atom)

redex-test/redex/tests/bitmap-test.rkt

+14-2
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,24 @@
202202
(render-metafunction T))
203203
"metafunction-T.png")
204204

205+
(define-language lang-lw-test
206+
(e (e e)
207+
x
208+
(λ (x) e)
209+
number)
210+
(v number (λ (x) e))
211+
(K^ e)
212+
((x y) variable-not-otherwise-mentioned))
205213
;; in this test, the `x' is italic and the 'z' is sf, since 'x' is in the grammar, and 'z' is not.
206-
(btest (render-lw
207-
lang
214+
(btest (render-lw
215+
lang-lw-test
208216
(to-lw ((λ (x) (x x))
209217
(λ (z) (z z)))))
210218
"lw.png")
219+
(btest (render-lw
220+
lang-lw-test
221+
(to-lw (e e_1 e_′ e_′′ e_^1 K^ K^_1 )))
222+
"lw2.png")
211223

212224
(define-metafunction lang
213225
[(TL 1) (a
1.95 KB
Loading

0 commit comments

Comments
 (0)