diff options
Diffstat (limited to 'support/splint/tex/flex.sty')
-rw-r--r-- | support/splint/tex/flex.sty | 124 |
1 files changed, 48 insertions, 76 deletions
diff --git a/support/splint/tex/flex.sty b/support/splint/tex/flex.sty index 59e23785b3..3008bfcb38 100644 --- a/support/splint/tex/flex.sty +++ b/support/splint/tex/flex.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 @@ -40,8 +40,6 @@ } \newif\ifyylessused -\newtoks\yylesslastformat -\newtoks\yylesslaststash \newcount\yylesslastfmark \newcount\yylesslastsmark \newcount\yylesslastchar @@ -55,8 +53,6 @@ \advance\yycurrentstate\YYATBOL % yy_current_state += YY_AT_BOL(); % save the format and stash streams for \yyless \ifyylessused - \yylesslastformat\yyformat - \yylesslaststash\yystash \yylesslastfmark\yyfmark \yylesslastsmark\yysmark \yylesslastchar\yytextlastchar @@ -67,23 +63,38 @@ \newif\ifyytextbackup \newif\iftraceflexbuffers -\def\yymatch{% - \ifyytextbackup - \xskiptofi\yyreinput - \else - \xskiptofi\yyinput - \fi -} - -\def\yyreinput{\expandafter\yyresetstreams\expandafter\yyinput\the\yytext@seen} +% an implementation of \yymatch with a low level command \yyreadinput +% that allows for a general input routine to be used at the beginning of the input +% buffer (see an example of using \yyreadinput in \ldcleanyyeof macro in ldlex.w) \def\yyresetstreams{% - \iftraceflexbuffers\ferrmessage{will rescan: <\the\yytext@seen> (stash: \the\yystashseen)}\fi + \iftraceflexbuffers\ferrmessage{will rescan: <\the\yytext@seen>}\fi \yytextseen{}\yytext@seen{}\yytextseenpure{}% - \yyformatseen{}\yystashseen{}% \yytextbackupfalse } +\def\yyreadinput#1#2{% + \expandafter\yyre@dinput\expandafter{#2}{#1}% +} + +\def\yyre@dinput#1#2{% + #2#1% +} + +\def\yyr@@dinput{% + \ifyytextbackup + \yybreak{\expandafter{\the\yytext@seen}{\yyresetstreams}}% + \else + \yybreak{{}{}}% + \yycontinue +} + +\def\yyr@@dinp@t#1#2{% + #2\yyinput#1% +} + +\def\yymatch{\yyreadinput{\yyr@@dinp@t}{\romannumeral0\yyr@@dinput}} + % \yym@tch is the return point from the low-level input routine \def\yym@tch{% do { @@ -93,20 +104,17 @@ \ifyyflexdebug\ferrmessage{match action: \the\yyact\space(yytext: \the\yytext@:^^Jyytextseen: \the\yytext@seen>\the\yybyte)}\fi \ifnum\yyact=\z@ % if ( yy_accept[yy_current_state] ) { \else % - \ifyyflexdebug\ferrmessage{yym@tch: stash seen: \the\yystashseen^^Jsmark: \the\yysmarklast}\fi + \ifyyflexdebug\ferrmessage{yym@tch: smark: \the\yysmarklast}\fi \yyg@yylastacceptingstate=\yycurrentstate % yyg->yy_last_accepting_state = yy_current_state; \concat\yytext\yytextseen % yyg->yy_last_accepting_cpos = yy_cp; \concat\yytext@\yytext@seen % ... ... \concat\yytextpure\yytextseenpure % ... ... - \concat\yyformat\yyformatseen % ... ... - \concat\yystash\yystashseen % ... ... \yytextlastchar=\yytextseenlastchar % \yyfmark=\yyfmarklast % ... ... \yysmark=\yysmarklast % ... ... \yyfmark@accept=\yyfmark \yysmark@accept=\yysmark \yytextseen={}\yytext@seen={}\yytextseenpure{}% - \yyformatseen{}\yystashseen{}% \fi % } \yyllwhile } @@ -136,19 +144,17 @@ \yycurrentstate=\fgetelemof{yybase}\at\yycurrentstate\relax \advance\yycurrentstate\yyc % \yycurrentstate=\fgetelemof{yynxt}\at\yycurrentstate\relax - \ifyyflexdebug\ferrmessage{yysubtext: (\the\yysubtext),^^Jyysbyte: (\the\yysbyte),^^Jyybyte: (\the\yybyte)}\fi + \ifyyflexdebug\ferrmessage{yysubtext: (\the\yysubtext),^^Jyybyte: (\the\yybyte)}\fi % yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; \concat\yytextseen\yybyte % ++yy_cp; \concat\yytext@seen\yysubtext \yysubtext{}% % ... \concat\yytext@seen\yybyte % ... \concat\yytextseenpure\yybytepure % ... - \concat\yyformatseen\yyfbyte \yyfbyte{}% % ... - \concat\yystashseen\yysbyte \yysbyte{}% % ... \yytextseenlastchar=\yycp@ % \yyfmarklast=\formatmarker % ... \yysmarklast=\stashmarker % ... \yyact=\fgetelemof{yybase}\at\yycurrentstate\relax % ... reusing \yyact ( yy_act = yy_base[yy_current_state] ) - \ifyyflexdebug\ferrmessage{matching the rest: <\the\yytext@seen>^^J(stash: \the\yystash:^^J\the\yystashseen)}\fi + \ifyyflexdebug\ferrmessage{matching the rest: <\the\yytext@seen>}\fi \ifnum\yyact=\YYBASEMAXENTRY\relax % } while ( yy_base[yy_current_state] != max( yy_base ) ); \ifyyflexdebug\ferrmessage{looking for the action}\fi \yybreak\yyfindaction % ... if ( yy_base[yy_current_state] == max( yy_base ) ) goto yy_find_action; @@ -177,21 +183,17 @@ \concat\yytext\yytextseen \concat\yytext@\yytext@seen \concat\yytextpure\yytextseenpure - \concat\yyformat\yyformatseen - \concat\yystash\yystashseen \yytextlastchar=\yytextseenlastchar \yyfmark=\yyfmarklast % == \formatmarker \yysmark=\yysmarklast % == \stashmarker \yytextseen{}\yytext@seen{}\yytextseenpure{}% - \yyformatseen{}\yystashseen{}% % \fi % } \YYDOBEFOREACTION % YY_DO_BEFORE_ACTION; \ifyyflexdebug \ferrmessage{action: \the\yyact,^^J% - state: \the\yycurrentstate\space(\the\yytext@:\the\yytext@seen)^^J% - stash: \the\yystash:\the\yystashseen^^J% - yysbyte: \the\yysbyte}% + state: \the\yycurrentstate\space(\the\yytext@:\the\yytext@seen)% + }% \fi \doaction } @@ -322,7 +324,6 @@ \stashmarker=\yysmark@accept \yyfmarklast=\formatmarker \yysmarklast=\stashmarker - \yyformatseen{}\yystashseen{}% \let\yyreturn\yygetpreviousstatef@r \yyinput } @@ -368,8 +369,6 @@ \yybyte{}\yybytepure{}% \yyfmarklast=\formatmarker \yysmarklast=\stashmarker - \concat\yyformatseen\yyfbyte \yyfbyte{}% - \concat\yystashseen\yysbyte \yysbyte{}% \else % \ifyyflexdebug \ferrmessage{possible accepting state.: \the\yycurrentstatelocal:% @@ -393,10 +392,6 @@ \yysmark@accept=\yysmark \yyfmarklast=\formatmarker \yysmarklast=\stashmarker - \concat\yyformat\yyformatseen - \concat\yystash\yystashseen - \yyformatseen\yyfbyte\yyfbyte{}% - \yystashseen\yysbyte\yysbyte{}% \fi \yygpswhile } @@ -465,8 +460,6 @@ \concat\yytextpure\yybytepure \yybyte{}\yybytepure{}% \yytextseen{}\yytext@seen{}\yytextseenpure{}% - \concat\yyformat\yyformatseen\yyformatseen{}% - \concat\yystash\yystashseen\yystashseen{}% \yytextlastchar=\yytextseenlastchar \yyfmark=\yyfmarklast \yysmark=\yysmarklast @@ -577,40 +570,25 @@ \def\yylexreturnval#1{% return value (yytext) only \yychar\csname token\parsernamespace #1\endcsname\relax - \yylval\expandafter{\expandafter{\the\yytext}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yytextpure}}% - % the above is an equivalent of - % \edef\next{\yylval{{\the\yytext}{\the\yytextpure}}}\next - % but does not `pollute' the definition of \next + {\edef\next{\yylval{{\the\yytext}{\the\yytextpure}}}\expandafter}\next \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail } \def\yylexreturnptr#1{% return stream pointers only - \yylval\expandafter{\expandafter{\the\yyfmark}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yysmark}}% - % the above is an equivalent of - % \edef\next{\yylval{{\the\yyfmark}{\the\yysmark}}}\next - % but does not `pollute' the definition of \next + {\edef\next{\yylval{{\the\yyfmark}{\the\yysmark}}}\expandafter}\next \yylexreturn{#1}% } +\def\yylexreturntext{\yylexreturnptr{\the\yytextpure}} + \def\yylexreturnsym#1{% return the value (yytext) followed by the pointers \yychar\csname token\parsernamespace #1\endcsname\relax - \yylval\expandafter{\expandafter{\the\yytext}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yytextpure}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yyfmark}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yysmark}}% - % the above is an equivalent of - % \edef\next{\yylval{{\the\yytext}{\the\yytextpure}{\the\yyfmark}{\the\yysmark}}}\next - % but does not `pollute' the definition of \next + {\edef\next{\yylval{{\the\yytext}{\the\yytextpure}{\the\yyfmark}{\the\yysmark}}}\expandafter}\next \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail } -\def\yylexreturntext{\yylexreturnptr{\the\yytextpure}} - \def\yylexreturnraw#1{% return the character, pointers as the value - \yylval\expandafter{\expandafter{\the\yyfmark}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yysmark}}% + {\edef\next{\yylval{{\the\yyfmark}{\the\yysmark}}}\expandafter}\next \yychar`#1\relax \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail } @@ -620,8 +598,7 @@ } \def\yylexreturnxchar#1{% return the numeric value, pointers as the value - \yylval\expandafter{\expandafter{\the\yyfmark}}% - \yylval\expandafter\expandafter\expandafter{\expandafter\the\expandafter\yylval\expandafter{\the\yysmark}}% + {\edef\next{\yylval{{\the\yyfmark}{\the\yysmark}}}\expandafter}\next \yychar#1\relax \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail } @@ -629,10 +606,16 @@ \def\yylexnext{\yytext{}\yytext@{}\yytextpure{}} % use this with a trivial \yylexcontinue \let\yylexnext\empty -\def\yyterminate{\yychar\YYEOF\yylval{}\yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail} - -\def\yyerrterminate{\yylexreturn{$undefined}} %$ +\def\yyterminate{\yychar\z@\yylval{}\yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail} +\def\yyerrterminate{% + \expandafter\ifx\csname token\parsernamespace $undefined\endcsname\relax + \yybreak{\yylexreturn{"invalid token"}}% + \else + \yybreak{\yylexreturn{$undefined}}%$ + \yycontinue +} + \def\yyfatal#1{\yycomplain{#1}\yyerrterminate} \def\yywarn#1{\yycomplain{#1}\yylexnext} @@ -654,23 +637,14 @@ } \def\yyless@backup{% - \yyformat\yylesslastformat - \yystash\yylesslaststash - \yysbyte{}\yyfbyte{}% \formatmarker\yylesslastfmark \stashmarker\yylesslastsmark } -\def\yyless@updatestreams{% - \concat\yyformat\yyfbyte\yyfbyte{}% - \concat\yystash\yysbyte\yysbyte{}% -} - \def\yyskipnchars#1{% \ifnum\yycp@=\YYENDOFBUFFERCHAR % read \yyeof \yycomplain{yyless buffer overflow: #1 characters too many}% \else - \yyless@updatestreams \ifnum#1=\@ne % skipped the required number of tokens \yybreak@\yyl@ss \else @@ -683,8 +657,6 @@ \def\yyl@ss#1\yyeof{% \yyfmark=\formatmarker \yysmark=\stashmarker - \yylesslaststash\yystash - \yylesslastformat\yyformat \unput{#1}% \let\yyreturn\oldyyreturn } |