Skip to content

Commit e232ad4

Browse files
committed
improve the typesetting of nonterminals that have both subscripts and primes
specifically, the prime now sits on top of the subscript
1 parent bb8ef64 commit e232ad4

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

redex-lib/redex/HISTORY.txt

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ v8.17
44
them suitable to abstract over (before, they required their
55
arguments to be identifiers bound to judgment forms)
66

7+
* fixed the rendering of nonterminals that have both subscripts and primes
8+
79
v8.16
810

911
* bug fixes

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

+35-9
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,23 @@
790790
(cond
791791
[(or (memq nt-name-sym all-nts)
792792
(memq nt-name-sym underscore-allowed))
793-
(define subsup-m (regexp-match #rx"^([^^]*)\\^(.*)$" after-underscore))
794-
(define-values (sub sup)
793+
(define-values (sub sup primes) (parse-subscript after-underscore))
794+
(define sub+sup
795795
(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))
796+
[(equal? primes "")
797+
(define sup-pict (basic-text sup (non-terminal-superscript-style)))
798+
(define sub-pict (basic-text sub (non-terminal-subscript-style)))
799+
(lbl-superimpose sup-pict sub-pict)]
800+
[(equal? sup "")
801+
(define primes-pict (basic-text primes (non-terminal-style)))
802+
(define sub-pict (basic-text sub (non-terminal-subscript-style)))
803+
(lbl-superimpose primes-pict sub-pict)]
804+
[else
805+
;; here we've got both a superscript and primes. Do our best.
806+
(define primes-pict (basic-text primes (non-terminal-style)))
807+
(define sup-pict (basic-text sup (non-terminal-superscript-style)))
808+
(define sub-pict (basic-text sub (non-terminal-subscript-style)))
809+
(lbl-superimpose (hbl-append sup-pict primes-pict) sub-pict)]))
803810
(list (non-terminal->token col span nt-name)
804811
(make-pict-token (+ col span) 0 sub+sup))]
805812
[else
@@ -826,6 +833,25 @@
826833
[(pict-convertible? str/pict/sym) (make-pict-token col span str/pict/sym)]
827834
[(symbol? str/pict/sym) #f]))
828835

836+
(define (parse-subscript after-underscore)
837+
(let loop ([i 0]
838+
[seen-caret? #f]
839+
[sub '()]
840+
[sup '()]
841+
[primes 0])
842+
(cond
843+
[(< i (string-length after-underscore))
844+
(define char (string-ref after-underscore i))
845+
(match char
846+
[#\^ (loop (+ i 1) #t sub sup primes)]
847+
[#\′ (loop (+ i 1) seen-caret? sub sup (+ primes 1))]
848+
[_ (if seen-caret?
849+
(loop (+ i 1) #t sub (cons char sup) primes)
850+
(loop (+ i 1) #f (cons char sub) sup primes))])]
851+
[else (values (apply string (reverse sub))
852+
(apply string (reverse sup))
853+
(make-string primes #\′))])))
854+
829855
(define (apply-atomic-rewrite e)
830856
(cond
831857
[(assoc e (atomic-rewrite-table))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
"lw.png")
219219
(btest (render-lw
220220
lang-lw-test
221-
(to-lw (e e_1 e_′ e_′′ e_^1 K^ K^_1 )))
221+
(to-lw (e e_1 e_′ e_′′ e_^1 e_1′ K^ K^_1)))
222222
"lw2.png")
223223

224224
(define-metafunction lang
155 Bytes
Loading

0 commit comments

Comments
 (0)