summaryrefslogtreecommitdiff
path: root/support/splint/tex/yynested.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/splint/tex/yynested.sty
Initial commit
Diffstat (limited to 'support/splint/tex/yynested.sty')
-rw-r--r--support/splint/tex/yynested.sty85
1 files changed, 85 insertions, 0 deletions
diff --git a/support/splint/tex/yynested.sty b/support/splint/tex/yynested.sty
new file mode 100644
index 0000000000..db725abfc5
--- /dev/null
+++ b/support/splint/tex/yynested.sty
@@ -0,0 +1,85 @@
+% Copyright 2012-2015, Alexander Shibakov
+% This file is part of SPLinT
+%
+% SPLinT is free software: you can redistribute it and/or modify
+% it under the terms of the GNU General Public License as published by
+% the Free Software Foundation, either version 3 of the License, or
+% (at your option) any later version.
+%
+% SPLinT is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU General Public License
+% along with SPLinT. If not, see <http://www.gnu.org/licenses/>.
+
+% nested and boundary parsing macros
+
+\newcount\boundarylower
+\newcount\boundaryupper
+
+% for parsers that use short setup
+
+\boundaryupper-\@M
+\boundarylower-\@M
+
+\expandafter\def\expandafter\parserdatainit\expandafter{%
+ \parserdatainit
+ \boundaryupper-\@M
+ \boundarylower-\@M
+}
+
+% the next sequence is just a reminder of what would have to be done if
+% reentrancy is required; the current state saving mechanism is intended for
+% bare unoptimized parsers exclusively and does not handle any constant saving
+
+\expandafter\def\expandafter\savefullstateextra\expandafter{%
+ \savefullstateextra
+ % save \boundaryupper and \boundarylower
+}
+
+\def\inputboundarynext#1{%
+ \yybytepure{ }\yycp@\boundarychar
+ #1\getstackpointer\yyvsa\relax
+ \yybyte\expandafter{\the\yybyte{#1}}%
+ \yyreturn % inserting something here will effectively insert it into the input stream
+}
+
+\newcount\vspointer
+
+% to use while debugging, the sequence below displays the contents of the value stack
+
+\def\yyactione{%
+ \message{value stack at: \getstackpointer\yyvsa}%
+ \toksa\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\gettopofstackcs\yyvsa}%
+ \toksb\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\getmidstackcs\yyvsa{0}}%
+ \message{on the stack: \the\toksa, bottom: \the\toksb}%
+ \message{the value: \the\yyval}%
+ \message{rule: \the\yyn, length: \the\yylen}%
+}
+
+% this is an example of boundary processing
+
+\def\yyaction{%
+ \vspointer=\getstackpointer\yyvsa\relax
+ \advance\vspointer-\yylen
+ \ifnum\vspointer<\boundarylower
+ \ifnum\boundaryupper>-\@M % all nested tokens will be reduced
+ \boundaryupper=-\@M
+ \boundarylower=-\@M
+ \message{reduction...(\the\vspointer: \the\yy(1).\the\yy(2).)}%
+ \printrule\yyn
+ \else % pre boundary tokens are getting reduced
+ \boundarylower=\vspointer
+ \advance\boundarylower\@ne
+ \fi
+ \else
+ \ifnum\vspointer<\boundaryupper % top nested tokens will be reduced
+ \boundaryupper=\vspointer
+ \fi
+ \fi
+ \yysymswitch{\yyn}% setting symbol names
+ \yybigswitch{\yyn}%
+ \yysymcleanup{\yyn}% removing symbol names from the namespace
+}