diff options
Diffstat (limited to 'support/splint/tex/yyinput.sty')
-rw-r--r-- | support/splint/tex/yyinput.sty | 219 |
1 files changed, 49 insertions, 170 deletions
diff --git a/support/splint/tex/yyinput.sty b/support/splint/tex/yyinput.sty index 0898410c51..4ca9a8617c 100644 --- a/support/splint/tex/yyinput.sty +++ b/support/splint/tex/yyinput.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 @@ -207,14 +207,26 @@ \yyreturn }% +% the single character switch `normalizes' the typesetting of underscores, as this +% is a particularly tricky character to get right; in typewriter fonts there is a +% `first class' underscore character so \_ may be defined as \char`\_ whereas in other fonts +% there is no `native' underscore character so \_ may be defined as a rule of an appropriate +% size +\def\acharswitch{ + \raw_\raw\_ {% the name parser will replace _ with \_ in subscripts + \yycp@`\_\relax + \yybyte{\_}% + \mkpurebyte + \yyreturn + } +} + \def\achardefault{% \expandafter\yycp@\expandafter`\the\yybyte\relax \mkpurebyte \yyreturn } -\def\acharswitch{} - % the following commands are only here for debugging purposes % they slow down the input @@ -222,6 +234,13 @@ \setspecialcharsfrom\multicharswitch \setspecialcharsfrom\acharswitch +% care should be taken with using the next command; it will only be executed +% if the parser (rather the lexer) `sees' it as part of the input; thus if this +% command is inserted at the end of the parsed text and, say, a bootstrap parser +% terminates early, the command will not be executed; likewise, it may be executed +% (more than) twice in case, for example, a parser stack is used and both (several) +% parsers see it before the parsing is terminated. + \def\insertrawnext#1{% insert a command #1\yyinput } @@ -230,62 +249,55 @@ \yyinput#1\stashed{#2}\vb } +% stash and format streams (lists) + \chardef\stashchar=`\ % \chardef\formatchar=`\ % \newcount\stashmarker \newcount\formatmarker +\def\yystash{[stash]} +\def\yyformat{[format]} + \def\stashnextwithspace#1{% \yybytepure{ }\yycp@\stashchar \yybyte\expandafter{\the\yybyte{#1}}% \advance\stashmarker\@ne - \edef\next{\yysbyte{\noexpand\strm[\the\stashmarker]{\the\yybyte}.[\the\stashmarker]}}\next - % the extra `.' is to avoid the stripping of braces by the parameter scanning mechanism of TeX + \ifnum\stashmarker<\showlistcounter\yystash\relax + \else + \appendtolist\yystash{#1}% + \fi \yyreturn } % the mechanism for stash processing making stash invisible \def\stashnextwithnothing#1{% - \advance\stashmarker\@ne \yybyte\expandafter{\the\yybyte{#1}}\concat\yysubtext\yybyte - \appendr\yysbyte{\noexpand\strm[\the\stashmarker]{\the\yybyte}.[\the\stashmarker]}% - \ifyyinputdebug - \immediate\write16{stash byte: \the\yysbyte mid text: \the\yysubtext}% - \fi - % the extra `.' is to avoid the stripping of braces by the parameter scanning mechanism of TeX - \yyinput -} - -% while collecting the stash, the macro below packages the stash contents into a command sequence -% to add to the \yystash stream; the stash is presented to the lexer unpackaged though; this -% introduces a minor inefficiency while ensuring that exactly one level of packaging is present -% (otherwise the lexer may back up and repackage already packaged stash); the inefficiency only -% persists while the lexer scans the current token (and possibly backs up). - -\def\stashnextwithnothingnx#1{% \advance\stashmarker\@ne - \yypush{#1}\on\astarray - \appendr\yysbyte{\noexpand\strm[\the\stashmarker]{\the\yybyte{% - \expandafter\noexpand\romannumeral\gettopofstackcsx\astarray}}.[\the\stashmarker]}% - \yybyte\expandafter{\the\yybyte{#1}}% do not package the input - \concat\yysubtext\yybyte + \ifnum\stashmarker<\showlistcounter\yystash\relax + \else + \appendtolist\yystash{#1}% + \fi \ifyyinputdebug - \immediate\write16{stash byte: \the\yysbyte mid text: \the\yysubtext}% + \immediate\write16{mid text: \the\yysubtext}% \fi - % the extra `.' is to avoid the stripping of braces by the parameter scanning mechanism of TeX \yyinput } -\let\stashnext\stashnextwithnothingnx +% collect the stash in the stash list (stream) + +\let\stashnext\stashnextwithnothing \def\formatnext#1{% \yybytepure{ }\yycp@\formatchar \toksa{#1}% \advance\formatmarker\@ne - \edef\next{\yyfbyte{\noexpand\strm[\the\formatmarker]{\the\yybyte{\the\toksa}}.[\the\formatmarker]}}\next - % the extra `.' is to avoid the stripping of braces by the parameter scanning mechanism of TeX + \ifnum\formatmarker<\showlistcounter\yyformat\relax + \else + \expandafter\appendtolisti\expandafter\yyformat\expandafter{\the\yybyte{#1}}% insert the iterator sequence, as well + \fi \yybyte\expandafter{\the\yybyte{#1}}% \yyreturn } @@ -303,155 +315,22 @@ \yyreturn % inserting something here will effectively insert it into the input stream } +% the next macro is not implemented correctly (since after a backup the flushed +% tokens may be reinserted; there needs to be a mechanism to remember that the +% tokens are already in the stash stream + \def\sflushnext#1#2{% #1 is the marker % #2 is the contents \yybytepure{ }\yycp@\stashchar - \edef\next{\toksc{\the\yystash\the\yystashseen}}\next - \yyfifolastidx\toksc\in\toksc - \toksa{#1}\toksb{#2}% - \appendr\yysbyte{\noexpand\strm[\the\toksa]{\the\yybyte{{\nx\it flushing}: ``\the\toksb'', - {\nx\it last index}: $[\the\toksc]$. }}.[\the\toksa]}% - % the extra `.' is to avoid the stripping of braces by the parameter scanning mechanism of TeX + % `save the flushed code' goes here \yybyte\expandafter{\the\yybyte{#1}{#2}}% \concat\yysubtext\yybyte \ifyyinputdebug - \immediate\write16{stash byte: \the\yysbyte mid text: \the\yysubtext}% + \immediate\write16{mid text: \the\yysubtext}% \fi \yyreturn } -% the following implementation is marginally cleaner as it does not redefine \yyr@@dfifo -% it also makes it almost transparent that \yyreadfifo does not modify any token registers -% except for the two of its parameters -% TODO: replace \yyr@@dfifo with \yyr@adfifo - -\def\yyreadfifo#1\to#2\in#3{% -%{% to reduce the side effects to the redefinition of the input and output - % token registers - \def\yyr@adfifo##1\strm[#2]##2[#2]##3\end{% - \yystringempty{##3}{#3{}}% there is no such marker in the fifo - {% - #3{##1\strm[#2]##2[#2]}% - \def\yyr@@dfifo####1\strm[#2]####2[#2]\end{#1{####1}}% strip off the inserted string - \yyr@@dfifo##3\end -% TODO: \def\yyr@dfifo####1\strm[#2].[#2]\end{#1{####1}}% strip off the inserted string -% \yyr@dfifo##3\end - }% - }% - \expandafter\yyr@adfifo\the#1\strm[#2].[#2]\end -%\edef\next{#1{\the#1}#3{\the#3}}\expandafter}\next -} - -\def\yytrimfifo#1\to#2\in#3{% just save the initial segment of #1 in #3 - \def\yyr@adfifo##1\strm[#2]##2[#2]##3\end{% - \yystringempty{##3}{#3{}}% there is no such marker in the fifo - {% - #3{##1\strm[#2]##2[#2]}% - }% - }% - \expandafter\yyr@adfifo\the#1\strm[#2].[#2]\end -} - -\def\yyreadfifox#1\to#2\in#3{% read the fifo to a marker in #2 - \expandafter\yyreadfifo\expandafter#1\expandafter\to\number#2\in#3% -} - -\def\yyreadfifoxx#1\to#2\in#3{% read the fifo to a marker in #2 - \expandafter\yyreadfifo\expandafter#1\expandafter\to#2\in#3% -} - -\def\yyreadfifot#1\to#2\in#3\with#4{% read fifo with a test: - \def\yyr@adfifo##1\strm[#2]##2[#2]##3\end{% #4 is a \macro[##1]##2.[##3] which - \def\yyr@@dfifo{##3}% looks at its parameters and fills up - \ifx\yyr@@dfifo\empty % \othertoks (to be attached at the beginning of #1 - % after the initial segment has been removed) - % and \fifotoks (to be used by another macro) - #3{}% there is no such marker in the fifo - \else - \let\fifotoks#3% - \let\othertoks#1 - \let\@@strm\strm - \let\strm#4% - \fifotoks{}% - \othertoks{}% - ##1\strm[#2]##2[#2]% run all the tests - \let\strm\@@strm - \def\yyr@@dfifo####1\strm[#2]####2[#2]\end{#1\expandafter{\the\othertoks####1}}% - \yyr@@dfifo##3\end - \fi - }% - \expandafter\yyr@adfifo\the#1\strm[#2].[#2]\end -} - -\def\yyreadfifotx#1\to#2\in#3\with#4{% read the fifo to a marker in #2 - \expandafter\yyreadfifot\expandafter#1\expandafter\to\number#2\in#3\with{#4}% -} - -% an example of a sorting macro: extract all the local formatting - -\def\formatsort[#1]#2.[#3]{% clobbers \toksb, \toksc - \formatgrab#2\end - \toksc{\strm[#1]{#2}.[#3]}% - \let\default\formatdefaultact - \switchon{\the\toksb}\in\formatswitch -} - -\def\formatgrab#1#2\end{\toksb{#1}} - -\def\formatswitch{% - \formatlocal {% - \edef\next{\fifotoks{\the\fifotoks\the\toksc}}\next - } -} - -\def\formatdefaultact{% - \edef\next{\othertoks{\the\othertoks\the\toksc}}\next -} - -\def\yygrabfifoelem#1\at#2\in#3{% - \def\yyr@adfifo##1\strm[#2]##2[#2]##3\end{% - \def\yyr@@dfifo{##3}% - \ifx\yyr@@dfifo\empty - #3{}% there is no such marker in the fifo - \else - #3{\strm[#2]##2[#2]}% - \def\yyr@@dfifo####1\strm[#2]####2[#2]\end{#1{####1}}% strip off the inserted string - \yyr@@dfifo##1##3\end - \fi - }% - \expandafter\yyr@adfifo\the#1\strm[#2].[#2]\end -} - -\def\yygrabfifoelemx#1\at#2\in#3\with#4{% read the fifo to a marker in #2 - \expandafter\yygrabfifoelem\expandafter#1\expandafter\at\number#2\in#3\with{#4}% -} - -\def\yypeekfifoelem#1\at#2\in#3{% just read the first element that matches the marker - \def\yyr@adfifo##1\strm[#2]##2[#2]##3\end{% - \def\yyr@@dfifo{##3}% - \ifx\yyr@@dfifo\empty - #3{}% there is no such marker in the fifo - \else - #3{##2}% just get the contents - \fi - }% - \expandafter\yyr@adfifo\the#1\strm[#2].[#2]\end -} - -\def\yypeekfifoelemx#1\at#2\in#3\with#4{% read the fifo to a marker in #2 - \expandafter\yypeekfifoelem\expandafter#1\expandafter\at\number#2\in#3\with{#4}% -} - -\def\strmgetfirstidx[#1]#2.[#3]{\toksa{#1}} - -\def\yyfifolastidx#1\in#2{% - \let\next\strm - \let\strm\strmgetfirstidx - \toksa{}\the#1% - #2\toksa - \let\strm\next -} - \def\z@rotest{0} \newif\ifchar |