diff options
Diffstat (limited to 'support/splint/tex/yyinit.sty')
-rw-r--r-- | support/splint/tex/yyinit.sty | 520 |
1 files changed, 166 insertions, 354 deletions
diff --git a/support/splint/tex/yyinit.sty b/support/splint/tex/yyinit.sty index 5091c05007..5fdd0ee9a5 100644 --- a/support/splint/tex/yyinit.sty +++ b/support/splint/tex/yyinit.sty @@ -1,4 +1,4 @@ -% Copyright 2012-2020, Alexander Shibakov +% Copyright 2012-2024, Alexander Shibakov % This file is part of SPLinT % % SPLinT is free software: you can redistribute it and/or modify @@ -143,30 +143,67 @@ \def\flexparserdatainit{% \table{}% + \let\secttwoprefix\empty } -% output parsed tables +% output parsed tables to a file -\long\def\displayoutputcode#1#2#3{% #1 is the output code (will be expanded by \write) +\long\def\saveoutputcode#1#2#3{% #1 is the output code (will be expanded by \write) % #2 is the output stream % #3 is the preamble (will be expanded by \write) - \immediate\write#2{#3#1}% + \newlinechar=`^^J% + \immediate\write#2{% + \harmlesscomment \parsernamespace::parsed table #3:^^J#1^^J^^J% + \harmlesscomment \parsernamespace::stashed stream:^^J\yystash^^J^^J% TODO: this just displays the name for now; + \harmlesscomment \parsernamespace::format stream:^^J\yyformat^^J^^J% TODO: this just displays the name for now; + }% +} + +% display parsed tables and streams + +\def\displayparsedoutput#1{% + \ifchecktable + \ferrmessage{parsed table: \the#1^^J^^J% + stashed stream: \yystash^^J^^J% TODO: this just displays the name for now; + format stream: \yyformat}% TODO: this just displays the name for now; + \fi +} + +% display raw input + +\def\displayrawtable{% + \ifsaveparseoutput + {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment + table before parsing:^^J\the\Binputtoks}}% + \fi + \ifchecktable + \ferrmessage{table before parsing: \the\Binputtoks}% + \fi } -\def\displayflextable#1{{% +\def\displayorsavefulloutput#1#2{% + \ifchecktable + \ferrmessage{table after processing: \the#1}% + \fi + \ifsaveparseoutput + {\newlinechar=`^^J\immediate\write#2{^^J\harmlesscomment + processed table:^^J\the#1}}% + \fi +} + +% the macros below make sure that (almost) none of the command sequences produced by the parser are +% expandable; this makes debugging easier + +\def\saveflextable#1{{% \hidecslist\cwebstreamchars \restorecslist{flexparser-debug}\yyflunion - \newlinechar=`^^J% - \expandafter\displayoutputcode\expandafter{\the\table}\exampletable - {^^J\harmlesscomment \parsernamespace::parsed table #1:^^J}% + \expandafter\saveoutputcode\expandafter{\the\table}\exampletable{#1}% }} -\def\displaybisontable#1{{% +\def\savebisontable#1{{% \hidecslist\cwebstreamchars \restorecslist{parser-debug}\yyunion - \newlinechar=`^^J% - \expandafter\displayoutputcode\expandafter{\the\table}\exampletable - {^^J\harmlesscomment \parsernamespace::parsed table #1:^^J}% + \expandafter\saveoutputcode\expandafter{\the\table}\exampletable{#1}% }} % stage two parsing macros @@ -229,7 +266,9 @@ \else \yybreak{% \ifparseverbose\ferrmessage{#1 parsing successful.}\fi - \ifsaveparseoutput\displayparsedtable{#1}\fi + \ifsaveparseoutput\saveparsedtable{#1}\fi + \finishlist\yystash + \finishlist\yyformat \typesetparsedtables }% \yycontinue @@ -242,39 +281,29 @@ } \def\postparsebisongrammar{% - \let\displayparsedtable\displaybisontable + \let\saveparsedtable\savebisontable \let\typesetparsedtables\typesetalltables \postparsegeneric{(grammar)}% } \def\postparsebisonprologue{% - \let\displayparsedtable\displaybisontable + \let\saveparsedtable\savebisontable \let\typesetparsedtables\typesetalltables \postparsegeneric{(prologue)}% } \def\postparseflexone{% - \let\displayparsedtable\displayflextable + \let\saveparsedtable\saveflextable \let\typesetparsedtables\typesetfsonetables \postparsegeneric{(section 1)}% } \def\postparseflextwo{% - \let\displayparsedtable\displayflextable + \let\saveparsedtable\saveflextable \let\typesetparsedtables\typesetfstwotables \postparsegeneric{(section 2)}% } -\def\displayrawtable{% - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - table before parsing:^^J\the\Binputtoks}}% - \fi - \ifchecktable - \ferrmessage{table before parsing: \the\Binputtoks}% - \fi -} - \fillpstack{}{% \preparsebisongrammar \preparsebisonprologue @@ -286,7 +315,8 @@ \fillpstack{b}{% \preparsebisongrammar \preparsebisonprologue - {\preparsefallback{**}}% + \preparseflexone + {\preparsefallback{..}}% \relax % this \relax is necessary so that the braces above % are not stripped by \poppstack } @@ -312,8 +342,6 @@ % stage 3.5 macros: typesetting -\newtoks\symstream - \def\tlskip{\z@} \def\tfskip{\parindent} @@ -321,178 +349,77 @@ \def\typesetalltables{% \begingroup - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - stashed stream:^^J\the\yystash^^J^^J\harmlesscomment - format stream: ^^J\the\yyformat}}% - \fi - \ifchecktable - \ferrmessage{parsed table: \the\table^^J^^J% - stashed stream: \the\yystash^^J^^J% - format stream: \the\yyformat}% - \fi - \extractprodtableinfo - \symstream\table - \table{}% + \displayparsedoutput\table + \extractprodtableinfo \setprodtable - \the\symstream\relax - \postoks{}\pushothertables - \ifchecktable - \ferrmessage{table after processing: \the\table}% - \fi - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - processed table:^^J\the\table}}% - \fi + \executeast{\postoks{}\pushothertables}% \parindent1em - \checkforpropertable\table + \checkforpropertable{\executelist\aststream}% \tabskip\tfskip \ruletableset - \ifchecktrailingstash - \ferrmessage{remaining stash: \the\yystash}% - \fi - \unwrapstash\yystash - \toksa\expandafter{\the\yystash}% - \cleanstash\stripstash\checkforccode - \ifchecktrailingstash - \ferrmessage{stash after cleaning: \the\toksa}% - \fi - \ifnum\wd0>\z@ - %\ifchecktable - % \showboxdepth=1000 - % \showboxbreadth=1000 - % \showbox0 - %\fi - % currently testing for nontrivial leftover stash involves packaging the stash material - % into a \vbox; as a result, the stash containing ${}{}$\hbox{} will have a nonzero length - % which is why the test below is necessary - \ifnum\ht0>\z@ - \indent\boxstash - \fi - \fi - \expandafter % export the value of the alignment + {\edef\next{\write\auxstream{\nx\nx\nx\lodimens{\the\gaglue}{}{}{}\harmlesscomment}}\next}% + \finishastoutput % debugging and stash cleanup + \expandafter % export the value of the alignment glue \endgroup \expandafter\gaglue\the\gaglue\relax } \def\typesetfstwotables{% \begingroup - \ifchecktable - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - stashed stream:^^J\the\yystash^^J^^J\harmlesscomment - format stream: ^^J\the\yyformat}}% - \else - \errmessage{parsed table: \the\table^^J^^J% - stashed stream: \the\yystash^^J^^J% - format stream: \the\yyformat}% - \fi - \fi - \extractregextableinfo - \symstream\table - \table{}% - \setregextable - \the\symstream\relax - \regextableset - \ifchecktable - \ifsaveparseoutput - \else - \errmessage{table after processing: \the\table}% - \fi - \fi - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - processed table:^^J\the\table}}% - \fi - \ifchecktable - \ifchecktrim - \ferrmessage{remaining stash: \the\yystash}% - \fi - \fi - \unwrapstash\yystash - \toksa\expandafter{\the\yystash}% - \cleanstash\stripstash\checkforccode - \ifchecktable - \ifchecktrim - \ferrmessage{stash after cleaning: \the\toksa}% - \fi - \fi - \ifnum\wd0>\z@ - %\ifchecktable - % \showboxdepth=1000 - % \showboxbreadth=1000 - % \showbox0 - %\fi - % currently testing for nontrivial leftover stash involves packaging the stash material - % into a \vbox; as a result, the stash containing ${}{}$\hbox{} will have a nonzero length - % which is why the test below is necessary - \ifnum\ht0>\z@ - \indent\boxstash - \fi - \fi + \displayparsedoutput\table + \extractregextableinfo % preprocess the AST for section 2 + \setregextable % activate AST control sequences for section 2 + \executeast{}% execute AST (the output will be collected in the \aststream list) + \regextableset % typeset the contents + \finishastoutput % debugging and stash cleanup \endgroup } \def\typesetfsonetables{% \begingroup - \ifchecktable - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - stashed stream:^^J\the\yystash^^J^^J\harmlesscomment - format stream: ^^J\the\yyformat}}% - \else - \errmessage{parsed table: \the\table^^J^^J% - stashed stream: \the\yystash^^J^^J% - format stream: \the\yyformat}% - \fi - \fi -% \extractregextableinfo - \symstream\table - \table{}% + \displayparsedoutput\table + \extractregextableinfo \setregexdeftable - \the\symstream\relax + \executeast{}% execute AST (the output will be collected in the \aststream list) \regexdeftableset - \ifchecktable - \ifsaveparseoutput - \else - \errmessage{table after processing: \the\table}% - \fi - \fi - \ifsaveparseoutput - {\newlinechar=`^^J\immediate\write\exampletable{^^J\harmlesscomment - processed table:^^J\the\table}}% - \fi - \ifchecktable - \ifchecktrim - \ferrmessage{remaining stash: \the\yystash}% - \fi - \fi - \unwrapstash\yystash - \toksa\expandafter{\the\yystash}% - \cleanstash\stripstash\checkforccode - \ifchecktable - \ifchecktrim - \ferrmessage{stash after cleaning: \the\toksa}% - \fi - \fi - \ifnum\wd0>\z@ - %\ifchecktable - % \showboxdepth=1000 - % \showboxbreadth=1000 - % \showbox0 - %\fi - % currently testing for nontrivial leftover stash involves packaging the stash material - % into a \vbox; as a result, the stash containing ${}{}$\hbox{} will have a nonzero length - % which is why the test below is necessary - \ifnum\ht0>\z@ - \indent\boxstash - \fi - \fi + \finishastoutput % debugging and stash cleanup \endgroup } -\let\extractprodtableinfo\empty % we do not preprocess the productions table +\def\executeast#1{% #1 is an optional postprocessing action + % execute AST (the output will be collected in the \aststream list) + \initlist\aststream + \the\table\relax + #1% + \finishlist\aststream +} +\def\finishastoutput{% + % possibly output debugging information, + % clean up and typeset any remaining stash + \displayorsavefulloutput\table\exampletable + \ifchecktrailingstash + \ferrmessage{remaining stash: \yystash}% TODO: this just displays the name for now; + \fi + \consumefulllist\yystash\to\toksa + \cleanstash\stripstash\checkforccode + \ifchecktrailingstash + \ferrmessage{stash after cleaning: \the\toksa}% + \fi + \ifnum\wd0>\z@ + %\ifchecktable + % \showboxdepth=1000 \showboxbreadth=1000 \showbox0 + %\fi + % currently testing for nontrivial leftover stash involves packaging the stash material + % into a \vbox; as a result, the stash containing ${}{}$\hbox{} will have a nonzero length + % which is why the test below is necessary + \ifnum\ht0>\z@ + \indent\boxstash + \fi + \fi +} + +\let\extractprodtableinfo\extractprodrefs % record the rules to be used later as a reference \let\extractregextableinfo\empty % we do not preprocess the regex table % setting the rule table: cross-section alignment and other effects are applied here; @@ -506,14 +433,15 @@ \vskip-\baselineskip \ifx\gatoks\relax \else - \table\expandafter{\the\table\gatoks}% + \expandafter\appendtolist\expandafter\aststream\expandafter{\gatoks}% + \finishlist\aststream \fi \setbox0\vbox\expandafter{\expandafter \null\expandafter\prevdepth\the\prevdepth \halign \ifpropertable to \hsize \fi {\hbox to 2em{##\/$\,${\rm:}\hss}\hfil\tabskip\z@&\setallterms{##}&##\hfil\tabskip0pt plus1fil&% \toksa{}##\makestashbox\hfil\tabskip\tlskip\cr - \the\table + \executelist\aststream } \expandafter }\expandafter @@ -534,7 +462,7 @@ \null\expandafter\prevdepth\the\prevdepth \halign to\hsize {##\hfil\tabskip0 pt plus1fil\ &\relax\tabskip\tlskip\toksa{}##\makestashbox\hfil\cr - \the\table + \executelist\aststream }% \expandafter }\expandafter @@ -551,7 +479,7 @@ \null\expandafter\prevdepth\the\prevdepth \halign to\hsize {\hskip\parindent##\hfil\tabskip0 pt plus1fil\ &\relax\tabskip\tlskip\tt##\hfil\cr - \the\table + \executelist\aststream }% \expandafter }\expandafter @@ -559,6 +487,44 @@ \prevdepth\the\prevdepth\relax } +% recording alignment layout: the gaglue, etc. + +\def\yyuniontag{\auxunionctl} +\defp\tablorunionctl{}% sequence to activate/deactivate/take other action for + % tablor set of macros + +\defc\tablorunionctl{% + \restorecslist{aux:global:tablors}\tablorunion +} +\savecs{aux:global:activate}\tablorunionctl + +\defc\tablorunionctl{% + \restorecslist{aux:global:tablors:neutral}\tablorunion +} +\savecs{aux:global:deactivate}\tablorunionctl + +\defc\tablorunionctl{% this command should not make any page material contributions + \message{tablors...}% +} +\savecs{aux:global:preend}\tablorunionctl + +\defc\tablorunionctl{% writing a header, etc. + \message{tablors...}% + \toksa\expandafter{\tablorunion}% + \immediate\write\auxstream{\harmlesscomment\the\toksa}% +} +\savecs{aux:global:prestart}\tablorunionctl + +\yyuniondeclare\tablorunion{aux:global:tablors} + +\defp\lodimens#1#2#3#4{} + +\toyyunion{aux:global:tablors:neutral} + +\defc\lodimens#1#2#3#4{}% define this to set the layout for tables on a given page + +\toyyunion{aux:global:tablors} + % quick and dirty global alignment: the size of the last box (and those in between) % can be chosen automatically after one pass and read in for the final pass; % in the future this will be the default implementation; for now, the inelegant @@ -586,147 +552,6 @@ \hidecs{\1\4\5\6\8}% } -\newif\ifdisplaytokenraw - -\def\toksdefline#1#2#3#4#5{% #1 is the parsed version of the internal bison name - % #2 is the index entry - % #3 is the type - % #4 is the explicit value - % #5 is the parsed version of the string value - \ifnum\tempca=\z@ - \tokdectoks\expandafter{\the\tokdectoks&{#2}#1\hfil\cr}% - \tempca\tempcb - \else - \ifnum\tempcb=\tempca - \tokdectoks\expandafter{\the\tokdectoks{#2}#1\hfil}% - \else - \tokdectoks\expandafter{\the\tokdectoks&{#2}#1\hfil}% - \fi - \advance\tempca\m@ne - \fi -} - -\def\attachtokentable{% typesetting the token declarations as part of the grammar - \tempcb3 \tempca\tempcb - \expandafter\tokdectoks\expandafter{\expandafter}\the\tokdectoks - \ifnum\tempca=\tempcb - \else - \bloop - \tokdectoks\expandafter{\the\tokdectoks&\omit\hfil}% - \ifnum\tempca=\z@ - \else - \advance\tempca\m@ne - \repeat - \tokdectoks\expandafter{\the\tokdectoks\cr}% - \fi - \toksa{\tt\strut##\hfil\tabskip=0pt plus 1fil}% - \bloop - \toksa\expandafter{\the\toksa&\tt\strut##\hfil}% - \ifnum\tempcb=\tw@ - \else - \advance\tempcb\m@ne - \repeat - \toksa\expandafter{\the\toksa&\tt\strut##\hfil\tabskip\z@\cr}% - \concat\toksa\tokdectoks - \tokdectoks\toksa - \edef\next{\table{\the\table\noalign{% - \tabskip\parindent - %\nx\displaytokenrawtrue % this controls how tokens are displayed - % in the declarations: if true, the macro names will be shown - \halign to\hsize{\the\tokdectoks}% - }% - }}\next - \tokdectoks{}% -} - -% typesetting token lists, precedence declaratins, etc -% these belong to yyunion.sty but they use `global' settings that are -% too specific to put there - -\def\attachtypestable{% typesetting the type declarations as part of the grammar - \toksa{}\the\typestable - \edef\next{\table{\the\table\noalign{% - {% - \the\toksa - }% - }% - }}\next\typestable{}% -} - -\long\def\onetype#1#2{% - \toksb{{% - \hbadness\@M - \rightskip=\z@ - \tempda\hsize \advance\tempda-1in - \indent{$\langle$\tt union$\rangle.#1$:}\ \hfill\nobreak\hfill\nobreak\null\penalty1\relax\null\nobreak\hfill - \hbox to\tempda{$\vtop{\noindent\hsize\tempda\raggedright #2\strut}$}\par - }}% - \concat\toksa\toksb -} - -\long\def\flexsstatelist#1{% - \toksb{{% - \hbadness\@M - \rightskip=\z@ - \tempda\hsize \advance\tempda-1in - \indent{$\langle$\tt states-s$\rangle_{\rm f}$:}\ \hfill\nobreak\hfill\nobreak\null\penalty1\relax\null\nobreak\hfill - \hbox to\tempda{$\vtop{\noindent\hsize\tempda\raggedright #1\strut}$}\par - }}% - \concat\toksa\toksb -} - -\long\def\flexxstatelist#1{% - \toksb{{% - \hbadness\@M - \rightskip=\z@ - \tempda\hsize \advance\tempda-1in - \indent{$\langle$\tt states-x$\rangle_{\rm f}$:}\ \hfill\nobreak\hfill\nobreak\null\penalty1\relax\null\nobreak\hfill - \hbox to\tempda{$\vtop{\noindent\hsize\tempda\raggedright #1\strut}$}\par - }}% - \concat\toksa\toksb -} - -\def\attachprectable{% typesetting the precedence declarations as part of the grammar - \toksa{}\the\prectable - \edef\next{\table{\the\table\noalign{% - {% - \the\toksa - }% - }% - }}\next\prectable{}% -} - -\long\def\oneprec#1#2#3{% - \toksc{% - \hbadness\@M - \rightskip=\z@ - \tempda\hsize \advance\tempda-1in - \indent - }% - \toksd{% - \ \hfill\nobreak\hfill\nobreak\null\penalty1\relax\null\nobreak\hfill - \hbox to\tempda{$\vtop{\noindent\hsize\tempda\raggedright #3\strut}$}\par - } - \def\next{#2}% - \ifx\next\empty - \toksb{}% - \else - \toksb{${}:{}$#2}% - \fi - \edef\next{\toksb{{$\nx\langle$\nx\bf #1\the\toksb$\nx\rangle$}}}\next - \appendr\toksa{{\the\toksc\the\toksb\the\toksd}}% -} - -\def\attachoptionstable{% typesetting the options as part of the grammar - \edef\next{\table{\the\table\noalign{% - \tabskip\parindent - \halign{####\nx\hfil\tabskip\z@&\nx\qquad\nx\it####\nx\hfil\cr - \the\opttable - }% - }% - }}\next\opttable{}% -} - \newif\ifpropertable \def\checkforpropertable#1{{% checking if there is any table material @@ -738,7 +563,7 @@ \setbox\z@=\vbox{ \halign {\eatone{##}&\eatone{##}.&\eatone{##}&\eatone{##}\cr - \the#1% + #1% }% }% \ifnum\wd\z@>\z@ @@ -867,8 +692,7 @@ \def\1{\setbox\indentbox\hbox{\box\indentbox\hbox to 3em{\hfil}}}% \def\2{\setbox\indentbox\hbox{\box\indentbox\hbox to -3em{}}}% \def\4{\hbox to -3em{}}% - \def\5{}% -% \let\6\cr + \let\5\ignorespaces % so that @+ does not produce a space \def\6{% \edef\setindentbox{% \setbox\indentbox\hbox to\the\wd\indentbox{\noexpand\hfil}% @@ -903,10 +727,10 @@ \ifcat\noexpand\next0% \let\next\pr@dterm \else - \if\noexpand\next[% - \let\next\pr@dterm + \ifcat\noexpand\next a% + \def\next{\hbox{$\Upsilon$}}% TODO: look for an identifier \else - \let\next\oldmathS + \let\next\oldmathS% TODO: one more category: control sequence for cases like \$\\{identifier} \fi \fi \fi @@ -921,13 +745,13 @@ \let\next\seeksym \else \ifnum`#1<"3A\relax - \ifnum`#1>`0\relax + \ifnum`#1>"2F\relax % within ['0', '9'] \def\next{\seekno#1}% \else - \def\next{\hbox{$\Upsilon$}#1}% TODO: look for an identifier + \def\next{\oldmathS#1}% \fi \else - \def\next{\hbox{$\Upsilon$}#1}% TODO: look for an identifier + \def\next{\oldmathS#1}% \fi \fi \fi @@ -970,7 +794,6 @@ \let\extractprodtableinfo\empty % we do not preprocess the table \showlastactionfalse \let\actionfiller\empty - \let\postparsetext\postparsebproduction \fillpstack{b}{% \preparsebisongrammar \preparsebisonprologue @@ -985,18 +808,18 @@ } \def\texcharadjust{ - ` {% + `{% \yybyte{|}% \expandafter\yycp@\expandafter`\the\yybyte\relax \mkpurebyte \yyreturn - } - _ {% + }% + _{% \yybyte{\_}% \expandafter\yycp@\expandafter`\the\yybyte\relax \mkpurebyte \yyreturn - } + }% } \def\texcsadjust{ @@ -1016,6 +839,9 @@ } }% +% Note that using \setspecialcharsfrom on the switches above is unnecessary (and, indeed, an error) +% since the characters need to be read as is, with the category codes and all + % production typesetting \def\beginprod{% @@ -1066,7 +892,6 @@ \let\acharswitch\texcharadjust %\let\onecharswitch\texcsadjust \let\extractprodtableinfo\empty % we do not preprocess the table - \let\postparsetext\postparsefsection \fillpstack{fs1}{% \preparseflexone % TODO \preparseflextwo @@ -1091,19 +916,6 @@ \expandafter\gaglue\the\gaglue\relax % export the alignment width, TODO: set \gaglue in \flex } - - -% the following macros assume that \gindex or \xrefstream having been defined implies -% that all the bookkeeping required for maintaining the custom index and local cross referencing -% has been taken care of; this way during the bootstrapping mode, index entries or cross references -% are not generated. - -\ifx\gindex\UNDEFINED -\else - \termindextrue - \immediate\openout\gindex=\jobname.gdx -\fi - \let\endcprod\endgroup \let\endmprod\endgroup \let\endprod\endgroup |