|
790 | 790 | (cond
|
791 | 791 | [(or (memq nt-name-sym all-nts)
|
792 | 792 | (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 |
795 | 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)) |
| 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)])) |
803 | 810 | (list (non-terminal->token col span nt-name)
|
804 | 811 | (make-pict-token (+ col span) 0 sub+sup))]
|
805 | 812 | [else
|
|
826 | 833 | [(pict-convertible? str/pict/sym) (make-pict-token col span str/pict/sym)]
|
827 | 834 | [(symbol? str/pict/sym) #f]))
|
828 | 835 |
|
| 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 | + |
829 | 855 | (define (apply-atomic-rewrite e)
|
830 | 856 | (cond
|
831 | 857 | [(assoc e (atomic-rewrite-table))
|
|
0 commit comments