From bbc654c69e2a0030ffc31cf7f4d557a950adaf13 Mon Sep 17 00:00:00 2001 From: Casey Klein Date: Sun, 24 Jan 2010 11:36:29 +0000 Subject: [PATCH] Typesetting now recognizes carets (^) in the underscore component of a non-terminal reference, applying the non-terminal-superscript-style to the text following the caret. svn: r17801 --- collects/redex/pict.ss | 1 + collects/redex/private/bitmap-test.ss | 4 +++ .../private/bmps-macosx/superscripts.png | Bin 0 -> 944 bytes collects/redex/private/core-layout.ss | 24 ++++++++--------- collects/redex/redex.scrbl | 25 +++++++++++++----- 5 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 collects/redex/private/bmps-macosx/superscripts.png diff --git a/collects/redex/pict.ss b/collects/redex/pict.ss index c511e1f375..0d636a934f 100644 --- a/collects/redex/pict.ss +++ b/collects/redex/pict.ss @@ -59,6 +59,7 @@ [default-style (parameter/c text-style/c)] [non-terminal-style (parameter/c text-style/c)] [non-terminal-subscript-style (parameter/c text-style/c)] + [non-terminal-superscript-style (parameter/c text-style/c)] [linebreaks (parameter/c (or/c false/c (listof boolean?)))] [curly-quotes-for-strings (parameter/c boolean?)] [white-bracket-sizing (parameter/c diff --git a/collects/redex/private/bitmap-test.ss b/collects/redex/private/bitmap-test.ss index 8a8aefe9c7..e5f73397d9 100644 --- a/collects/redex/private/bitmap-test.ss +++ b/collects/redex/private/bitmap-test.ss @@ -159,5 +159,9 @@ ;; make sure two metafunctions simultaneously rewritten line up properly (test (render-metafunctions S T TL) "metafunctions-multiple.png") +;; Non-terminal superscripts +(test (render-lw lang (to-lw (x_^abcdef x_q^abcdef))) + "superscripts.png") + (printf "bitmap-test.ss: ") (done) diff --git a/collects/redex/private/bmps-macosx/superscripts.png b/collects/redex/private/bmps-macosx/superscripts.png new file mode 100644 index 0000000000000000000000000000000000000000..69484218f2decdc0365848277dc928f7cc4c18c9 GIT binary patch literal 944 zcmV;h15f;kP)YD6?l8alP2{3(=0l3lo97gL&&T5h?P3vxjTS6GKKiO^aZn^vo7 ztuafpwIpXXbJ$kH?Ah_W7kgV`?|R>D@AvNceV^aw`Td^r^y>ihMIRp@=+A->s#L1i z*Vlxu%jGf}jo*S+tM%#WDG4(jxXEOS!!ZB=03Z^HEH5uZ2*IDlX0r_j1DDH9=-%Dk zJv=;ojVvuK;W!=&g_1DSfj>SzYBZYP=>Px-;rRIY{QNwQ<3ADW>+8kE#YUrXW@aWB z46dxK1OkDnsj024EeyjdD=V|IvbguXWrMkJfaXOv1x3?`VEhi@@VzIcUrY1@C z>A)8j7Tj*PQmGsn8NmPmBuO?lHWn2X{X9mkR+pETb2yyp>S~k8#OL$na=FD~(Q36k z9&d1PkRXWN-Q9tK0UXEk^71w}H^bp@XJ;pl<2^k+b#-+~dPpDM*VnhPu@MS|Foe+T z?5sp0NqEx1!9hnyhgz*}Zf@3UwZp^1I-O1|7Vqrrw70kC9x?)Fu~@CGt!ry*n8)L}zrU}jr~m*&qtTTsQ3xS~FlN2KzsI-5$66#3 zVHhSFjmClu!@Rw{EiNu5oH-eXYcv`@pAQZX55KiRl4M(3Tf!p#Mt;A4dwZLv>4a{^ z;pgY)xw*MmZEda3=VKTq{`F~^b~>HOpLG)D=jThM(!#>Rgzh&uNs>C9PN7hw41a!p zE-Nd;s;a88v$K6ZUo2`c7`nT=IUJ7NZg)5wsrHgs-{5Am830gHQc_S*kTTQj^$LYT zjLl{%6bg&Qa&~qm5{V#$LZMJ1kxWldV;GjH1`@)RN@ah4|Nj1dS65d$ zgF{0@2%$hA5PNV8!zBMPNkKp1GMQ{|Z%-?l9>YkS{D}=b8~Z%NF;?^o6Qy<*1rHx&>Y4f S+EAqc0000string atom))) + (regexp-match #rx"^([^_^]*)_([^^]*)\\^?(.*)$" (symbol->string atom))) => - (λ (m) - (let* ([first-part (cadr m)] - [second-part (caddr m)] - [first-span (- span (string-length first-part))]) - (list - (non-terminal->token col first-span first-part) - (make-string-token (+ col first-span) - (- span first-span) - second-part - (non-terminal-subscript-style)))))] + (match-lambda + [(list _ nt sub sup) + (let* ([sub-pict (basic-text sub (non-terminal-subscript-style))] + [sup-pict (basic-text sup (non-terminal-superscript-style))] + [sub+sup (lbl-superimpose sub-pict sup-pict)]) + (list (non-terminal->token col span nt) + (make-pict-token (+ col span) 0 sub+sup)))])] [(or (memq atom all-nts) (memq atom '(number variable variable-except variable-not-otherwise-mentioned))) (list (non-terminal->token col span (format "~s" atom)))] @@ -747,6 +746,7 @@ (define (unksc str) (pink-background ((current-text) str 'modern (default-font-size)))) (define non-terminal-style (make-parameter '(italic . roman))) (define non-terminal-subscript-style (make-parameter `(subscript . ,(non-terminal-style)))) + (define non-terminal-superscript-style (make-parameter `(superscript . ,(non-terminal-style)))) (define default-style (make-parameter 'roman)) (define metafunction-style (make-parameter 'swiss)) (define (metafunction-text str) ((current-text) str (metafunction-style) (metafunction-font-size))) diff --git a/collects/redex/redex.scrbl b/collects/redex/redex.scrbl index fb34a26e47..a66ca1287a 100644 --- a/collects/redex/redex.scrbl +++ b/collects/redex/redex.scrbl @@ -1865,6 +1865,7 @@ cases appear. If it is a list of numbers, then only the selected cases appear (c @defparam[metafunction-style style text-style/c]{} @defparam[non-terminal-style style text-style/c]{} @defparam[non-terminal-subscript-style style text-style/c]{} +@defparam[non-terminal-superscript-style style text-style/c]{} @defparam[default-style style text-style/c]{}]]{ These parameters determine the font used for various text in @@ -1875,15 +1876,27 @@ useful things it can be is one of the symbols @scheme['roman], monospaced font, respectively. (It can also encode style information, too.) -The label-style is used for the reduction rule label -names. The literal-style is used for names that aren't +The @scheme[label-style] is used for the reduction rule label +names. The @scheme[literal-style] is used for names that aren't non-terminals that appear in patterns. The -metafunction-style is used for the names of -metafunctions. The non-terminal-style is for non-terminals -and non-terminal-subscript-style is used for the portion +@scheme[metafunction-style] is used for the names of +metafunctions. + +The @scheme[non-terminal-style] is used for the names of non-terminals. +Two parameters style the text in the (optional) "underscore" component +of a non-terminal reference. The first, @scheme[non-terminal-subscript-style], +applies to the segment between the underscore and the first caret (@scheme[^]) +to follow it; the second, @scheme[non-terminal-superscript-style], applies +to the segment following that caret. For example, in the non-terminal +reference @scheme[x_y_z], @scheme[x] has style @scheme[non-terminal-style], +@scheme[y] has style @scheme[non-terminal-subscript-style], and @scheme[z] +has style @scheme[non-terminal-superscript-style]. + +The +@scheme[non-terminal-subscript-style] is used for the portion after the underscore in non-terminal references. -The default-style is used for parenthesis, the dot in dotted +The @scheme[default-style] is used for parenthesis, the dot in dotted lists, spaces, the separator words in the grammar, the "where" and "fresh" in side-conditions, and other places where the other parameters aren't used.