summaryrefslogtreecommitdiff
path: root/support/splint/tex/flex.sty
blob: 59e23785b30ff02968ef15d446d7ac6fb2241a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
% Copyright 2012-2020, 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/>.

% the implementation of (some part of) the \flex automata mechanisms;
% note that a few important features have been omitted and some that
% have been implemented may follow a (sometimes subtly) different
% semantics (see \unput and \yyless below);
% among the features that are missing are REJECT, ECHO and YYMORE;
% another important missing feature is the lack of trailing
% context matching; fixed length trailing context or fixed length
% match with variable length context can be easily emulated with
% regular rules and \yyless (or \unput); when both the match and
% the context are variable length, different automaton code is
% required; same code is required to implement REJECT; in addition,
% the action code for the actions matching trailing context rules
% must also be modified; while all of this may be implemented, it
% is better not to (ab)use trailing context rules.

\def\yylex{%
    \ifnum\yyg@yyinit=\z@           % if ( !yyg->yy_init ) {
        \yyg@yyinit=\@ne            %     yyg->yy_init = 1;
        \ifnum\yyg@yystart=\z@      %     if ( ! yyg->yy_start ) {
            \yyg@yystart=\@ne       %         yyg->yy_start = 1;
        \fi                         %     }
    \fi                             % }
    \yylwhile
}

\newif\ifyylessused
\newtoks\yylesslastformat
\newtoks\yylesslaststash
\newcount\yylesslastfmark
\newcount\yylesslastsmark
\newcount\yylesslastchar

\def\yylwhile{%
                                    % yy_cp = yyg->yy_c_buf_p;
                                    % *yy_cp = yyg->yy_hold_char;
                                    % yy_bp = yy_cp;
                                    %
    \yycurrentstate=\yyg@yystart    % yy_current_state = yyg->yy_start;
    \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
    \fi
    \yymatch
}

\newif\ifyytextbackup
\newif\iftraceflexbuffers

\def\yymatch{%
    \ifyytextbackup
        \xskiptofi\yyreinput
    \else
        \xskiptofi\yyinput
    \fi
}

\def\yyreinput{\expandafter\yyresetstreams\expandafter\yyinput\the\yytext@seen}

\def\yyresetstreams{%
    \iftraceflexbuffers\ferrmessage{will rescan: <\the\yytext@seen> (stash: \the\yystashseen)}\fi
    \yytextseen{}\yytext@seen{}\yytextseenpure{}%
    \yyformatseen{}\yystashseen{}%
    \yytextbackupfalse
}

% \yym@tch is the return point from the low-level input routine

\def\yym@tch{%                                      do {
    \yyc=\fgetelemof{yyec}\at\yycp@\relax         %     yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
    \yyact=\fgetelemof{yyaccept}\at\yycurrentstate\relax  
                                                  % ... ... reuse \yyact ( yy_act = yy_accept[yy_current_state] )
    \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
        \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
}

\let\yyreturn\yym@tch

% \yyllwhile searches for an accepting of rejecting state

\def\yyllwhile{%                                             ... yyllwhile:
    \yyact=\fgetelemof{yybase}\at\yycurrentstate\relax     % ... ... reusing \yyact ( yy_act = yy_base[yy_current_state] )
    \advance\yyact\yyc                                     % ... ... ( yy_act = yy_act + yy_c )
    \yyact=\fgetelemof{yychk}\at\yyact\relax               % ... ... ( yy_act = yy_chk[yy_act] ( == yy_chk[yy_base[yy_current_state] + yy_c] ) )
    \ifnum\yyact=\yycurrentstate                           % while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) {
        \yybreak\yymatchtail                               % ... if ( yy_chk[yy_base[yy_current_state] + yy_c] == yy_current_state )
    \else                                                  % ...     goto yy_match_tail;
                                                           % ... else
        \yycurrentstate=\fgetelemof{yydef}\at\yycurrentstate\relax 
                                                           %     yy_current_state = (int) yy_def[yy_current_state];
        \ifnum\yycurrentstate>\YYMAXREALCHAR\relax         %     if ( yy_current_state >= sizeof( yy_accept ) ) {
            \yyc=\fgetelemof{yymeta}\at\yyc\relax          %         yy_c = yy_meta[(unsigned int) yy_c];
        \fi                                                %     }
        \yybreak\yyllwhile                                 % ... goto yyllwhile;
    \yycontinue                                              % }
}

\def\yymatchtail{%
    \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
                                                           % 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
    \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;
    \else                                                  % ... else goto yy_match;
        \ifyyflexdebug\ferrmessage{looking for more input}\fi
        \yybreak\yymatch                                  
    \yycontinue
}

\newif\ifyyflexdebug
\newif\iftracebadchars

\def\yyfindaction{%
    \yyact=\fgetelemof{yyaccept}\at\yycurrentstate\relax   % yy_act = yy_accept[yy_current_state];
    \ifnum\yyact=\z@                                       % if ( yy_act == 0 ) {
        \yytextbackuptrue                                  %     yy_cp = yyg->yy_last_accepting_cpos;
        \yycurrentstate=\yyg@yylastacceptingstate          %     yy_current_state = yyg->yy_last_accepting_state;
        \yyact=\fgetelemof{yyaccept}\at\yycurrentstate\relax%    yy_act = yy_accept[yy_current_state];
        \formatmarker=\yyfmark@accept                      % ...
        \stashmarker=\yysmark@accept                       % ...
        \ifyyflexdebug\ferrmessage{backup: \the\yytext@:\the\yytext@seen^^J^^J%
                                   from state: \the\yyg@yylastacceptingstate\space
                                   stashmarker: \the\stashmarker}\fi
    \else
        % note that at this point \yytextbackupfalse is already set
        \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}%
    \fi
    \doaction
}

\newif\iftraceactioncode

\def\YYDOBEFOREACTION{%
}

% \yytext---current yytext
% \yytextseen---last accepted yytext
% |--\yytext--|--\yytextseen--|--remaining buffer--|
% after accepting state:
% [---------\yytext-----------]                    
% after backing up:
% |--\yytext--|--\yytextseen-----remaining buffer--|
% \yytextseen={}

%#define YY_DO_BEFORE_ACTION \
%	yyg->yytext_ptr = yy_bp; \
%	yyleng = (size_t) (yy_cp - yy_bp); \
%	yyg->yy_hold_char = *yy_cp; \
%	*yy_cp = '\0'; \
%	yyg->yy_c_buf_p = yy_cp;

\def\doaction{%
    \iftraceactioncode
        {%
            \expandafter\toksa
                \expandafter\expandafter\expandafter{\csname doflexaction\number\yyact\parsernamespace\endcsname}%
            \ferrmessage{action code (\the\yyact):^^J\the\toksa}%
        }%
    \fi
    \yydoactionswitch\yyact
}

%#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)

% as the macros above and below make a lot of assignments, 
% expandability was not a
% priority, however, keeping the macro namespace clean was;
% expandability is, of course a guaranteed way to do so, grouping is
% another; 

\def\yylexeofaction{%
    \ifyyflexdebug
        \ferrmessage{eof action: .\the\yytext@>>\the\yytext@seen(\the\yytext)}%
    \fi
    \yygetnextbuffer
    \ifYYEOBLASTMATCH
        \yygetpreviousstate
        \ifyyflexdebug\ferrmessage{found previous state: \the\yycurrentstatelocal\space 
                                   matched text: \the\yytext@>>\the\yytext@seen(\the\yybyte)}\fi
        \yycurrentstate\yycurrentstatelocal
        \let\yylextail\yyfind@ction
        \YYEOBLASTMATCHfalse
    \else
        \yyact\YYENDOFBUFFER\relax
        \advance\yyact\YYSTART
        \advance\yyact\@ne        % yy_act = YY_STATE_EOF(YY_START);
        \let\yylextail\doaction   % goto do_action;
        \concatl\yytext\yytext@seen \yytextbackuptrue % in case the scanner gets called again
        \yytoksempty{\yytext}%
            {\errmessage{internal error: matched nothing in eob state}}%
            {\yyisthiscsr\yytext\yyeof{}{\errmessage{internal error: matched more than a single eob: (\the\yytext)}}}%
        \ifyyflexdebug
            \ferrmessage{eob in user state: \the\yyact\space matched text: \the\yytext@(\the\yytext)\space
                         to read: \the\yytext@seen}%
        \fi
        \yytext{}\yytext@{}%
    \fi
}

\def\yygetnextbuffer{%
    \yytoksempty{\yytext}{\errmessage{internal error: empty matched text in eob state}}%
        {% this somewhat complicated definition is needed in case the last character is an ordinary 
         % space character
            \expandafter\yystartsinspace\expandafter{\the\yytext}{%
                \expandafter\expandafter\expandafter
                    \yystringempty % we have matched exactly one token (space)
                \expandafter\expandafter\expandafter{\expandafter\eattospace\the\yytext}%
                    {\YYEOBLASTMATCHfalse}{\YYEOBLASTMATCHtrue}%
            }{%
                \expandafter\expandafter\expandafter
                    \yystringempty % we have matched exactly one token
                \expandafter\expandafter\expandafter{\expandafter\eatone\the\yytext}%
                    {\YYEOBLASTMATCHfalse}{\YYEOBLASTMATCHtrue}%
            }%
        }%
}

\newif\ifYYEOBLASTMATCH

\def\yygetpreviousstate{%
    \yycurrentstatelocal=\yyg@yystart
    \advance\yycurrentstatelocal\YYATBOL
    \ifyyflexdebug\ferrmessage{state setup.: start(\the\yyg@yystart), bol(\number\YYATBOL)}\fi
    %
    \yytoksempty{\yytext}{\errmessage{internal error: empty matched text in eob state}}{}%
    % move the scanned \yyeof to the buffer of seen characters
    \expandafter\yysplitoff\expandafter.\the\yytext\yyeof\end\yytext
    \expandafter\yysplitoff\expandafter.\the\yytext@\yyeof\end\yytext@
    \appendlnx\yytextseen\yyeof
    \appendlnx\yytext@seen\yyeof \yytextbackuptrue
    \ifyyflexdebug\ferrmessage{searching for last match in text: \the\yytext@}\fi
    \yytoksempty{\yytext}{}{% yyg->yytext_ptr >= yyg->yy_c_buf_p /* do not enter the for loop */
        \expandafter\yygetpreviousstatefor\the\yytext@\splitoffend % at least one iteration of the for loop
    }%
}

\def\yysplitoff#1\yyeof#2\end#3{%
    \yystringempty{#2}{%
        \errmessage{internal error: something other than \noexpand\yyeof\space triggered eob action: <\the\yytext@>}%
    }{%
        #3\expandafter{\eatone#1}% to remove the `.' at the beginning
    }%
}

\def\yygetpreviousstatefor{%
    % save all the lexer variables affected by \yyinput
    % to be restored on exit from the `for' loop
    % i.e.~when the \splitoff token is read
    \let\currentyyreturn\yyreturn
    \yyfutureyytext\yytext@seen % to be reinserted in yyfind@action
    \yytext{}\yytext@{}\yytextpure{}%
    \yytextseen{}\yytext@seen{}\yytextseenpure{}%
    \formatmarker=\yyfmark@accept
    \stashmarker=\yysmark@accept
    \yyfmarklast=\formatmarker
    \yysmarklast=\stashmarker
    \yyformatseen{}\yystashseen{}%
    \let\yyreturn\yygetpreviousstatef@r
    \yyinput
}

\def\yygetpreviousstatef@r{%
    \let\default\yygetpreviousstatedefault
    \ifyyflexdebug\ferrmessage{just read: \the\yybyte (so far: \the\yytext@><\the\yytext@seen)}\fi % TODO: delete
    \switchon{\expandafter\getfirsttoken\expandafter{\the\yybyte}}\in\yygetpreviousstateswitch
}

\def\yygetpreviousstateswitch{%
    \yyeof {% scanned a NUL: currently NUL transitions are not implemented
            % (so one cannot use NUL's in the input) so this state is never used
        \yyclocal\YYECMAGIC\relax % the constant extracted from yy_get_next_state
        \edef\yycurrentstatelocal@prejam{\the\yycurrentstatelocal}% 
        \yygetpreviousstat@f@r
    }%
    \splitoffend {% yyg->yytext_ptr >= yyg->yy_c_buf_p /* exit the for loop */
        % this is not an actual character but a marker for the end of the `for' loop
        \yycp@=\YYENDOFBUFFERCHAR\relax % this is not necessary
        \yybyte{}\yybytepure{}%
%
        \let\yyreturn\currentyyreturn
    }%
    \endparse \endparseinput {%
        \errmessage{internal error.: reading past the end of the input buffer}%
    }%
}

\def\yygetpreviousstatedefault{%
    \yyclocal=\fgetelemof{yyec}\at\yycp@\relax           %     yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
    \yytextseenlastchar=\yycp@
    \yygetpreviousstat@f@r
}

\def\yygetpreviousstat@f@r{%
    \ifnum\fgetelemof{yyaccept}\at\yycurrentstatelocal=\z@
                                                  %     if ( yy_accept[yy_current_state] ) {
        \concat\yytextseen\yybyte
        \concat\yytext@seen\yysubtext \yysubtext{}%
        \concat\yytext@seen\yybyte
        \concat\yytextseenpure\yybytepure
        \yybyte{}\yybytepure{}%
        \yyfmarklast=\formatmarker
        \yysmarklast=\stashmarker
        \concat\yyformatseen\yyfbyte \yyfbyte{}%
        \concat\yystashseen\yysbyte \yysbyte{}%
    \else                                         % 
        \ifyyflexdebug
            \ferrmessage{possible accepting state.: \the\yycurrentstatelocal:%
                         \fgetelemof{yyaccept}\at\yycurrentstatelocal}%
        \fi
        \yyg@yylastacceptingstate=\yycurrentstatelocal
                                                  %         yyg->yy_last_accepting_state = yy_current_state;
        \concat\yytext\yytextseen                 %         yyg->yy_last_accepting_cpos = yy_cp; TODO:?????????
        \concat\yytext@\yytext@seen               % ...
        \concat\yytextpure\yytextseenpure         % ... 
        \yytextseen=\yybyte                       % ...
        \yytext@seen=\yysubtext \yysubtext{}%     % ...
        \concat\yytext@seen\yybyte \yybyte{}%     % ...
        \yytextseenpure=\yybytepure\yybytepure{}% %
        \yytextbackuptrue
        \yytextlastchar=\yytextseenlastchar       %
                                                  %
        \yyfmark=\yyfmarklast                     % ... ...
        \yysmark=\yysmarklast                     % ... ...
        \yyfmark@accept=\yyfmark
        \yysmark@accept=\yysmark
        \yyfmarklast=\formatmarker
        \yysmarklast=\stashmarker
        \concat\yyformat\yyformatseen
        \concat\yystash\yystashseen
        \yyformatseen\yyfbyte\yyfbyte{}%
        \yystashseen\yysbyte\yysbyte{}%
    \fi                     
    \yygpswhile
}


\def\yygpswhile{%                                            ... yyllwhile:
    \yyact=\fgetelemof{yybase}\at\yycurrentstatelocal\relax% ... ... reusing \yyact ( yy_act = yy_base[yy_current_state] )
    \advance\yyact\yyclocal                                % ... ... ( yy_act = yy_act + yy_c )
    \ifnum\fgetelemof{yychk}\at\yyact=\yycurrentstatelocal % while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) {
        \yybreak\yygpsfornext                              % ... if ( yy_chk[yy_base[yy_current_state] + yy_c] == yy_current_state )
                                                           % ... ... exit the while loop
    \else                                                  % ...     return yy_current_state;
                                                           % ... else
        \yycurrentstatelocal=\fgetelemof{yydef}\at\yycurrentstatelocal\relax 
                                                           %     yy_current_state = (int) yy_def[yy_current_state];
        \ifnum\yycurrentstatelocal>\YYMAXREALCHAR\relax    %     if ( yy_current_state >= sizeof( yy_accept ) ) {
            \yyclocal=\fgetelemof{yymeta}\at\yyclocal\relax%         yy_c = yy_meta[(unsigned int) yy_c];
        \fi                                                %     }
        \yybreak\yygpswhile                                % ... goto yyllwhile;
    \yycontinue                                            % }
}

\newif\ifyyflexisjammed

\def\yygpsfornext{% this combines yy_get_previous_state() and yy_get_NUL_trans()
    \ifyyflexdebug\ferrmessage{starting in state.: \the\yycurrentstatelocal}\fi % TODO: delete
    \yycurrentstatelocal=\fgetelemof{yybase}\at\yycurrentstatelocal\relax
    \advance\yycurrentstatelocal\yyclocal
    \yycurrentstatelocal=\fgetelemof{yynxt}\at\yycurrentstatelocal\relax
    % yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
    % currently, we do not allow NULs in the input so the code below is not used
    % when NUL transitions are implemented, this code will come into play
    \ifnum\yycurrentstatelocal=\YYMAXREALCHAR\relax
        \yycurrentstatelocal=\yycurrentstatelocal@prejam\relax
        \ifyyflexdebug\ferrmessage{jammed, switching to \yycurrentstatelocal@prejam}\fi
        \yyflexisjammedtrue
    \else
        \yyflexisjammedfalse
    \fi
    %yy_is_jam = (yy_current_state == ...);
    %return yy_is_jam ? 0 : yy_current_state;
    \ifyyflexdebug\ferrmessage{switching to state.: \the\yycurrentstatelocal\space on char \the\yyclocal}\fi % TODO: delete
    \yyinput
}

\def\yyfind@ction{% we have to use this macro instead of the
                  % regular \yyfindaction because we use a stop token (\splitoffend) to terminate
                  % the `for' loop and are thus `one token behind' by the time this action is taken
                  % therefore we have to forego the `yy_cp actions' in the original \yyfindaction
    \yyact=\fgetelemof{yyaccept}\at\yycurrentstate\relax   % yy_act = yy_accept[yy_current_state];
    \ifnum\yyact=\z@                                       % if ( yy_act == 0 ) {
                                                           %     yy_cp = yyg->yy_last_accepting_cpos;
        \yycurrentstate=\yyg@yylastacceptingstate          %     yy_current_state = yyg->yy_last_accepting_state;
        \yyact=\fgetelemof{yyaccept}\at\yycurrentstate\relax%    yy_act = yy_accept[yy_current_state];
        \formatmarker=\yyfmark@accept                      % ...
        \stashmarker=\yysmark@accept                       % ...
        \ifyyflexdebug\ferrmessage{backup.: \the\yytext:\the\yytextseen}\fi
    \else
                                                           %
        \concat\yytext\yytextseen
        \concat\yytext@\yytext@seen
        \concat\yytextpure\yytextseenpure
        \concat\yytext\yybyte
        \concat\yytext@\yysubtext \yysubtext{}%
        \concat\yytext@\yybyte
        \concat\yytextpure\yybytepure
        \yybyte{}\yybytepure{}%
        \yytextseen{}\yytext@seen{}\yytextseenpure{}%
        \concat\yyformat\yyformatseen\yyformatseen{}%
        \concat\yystash\yystashseen\yystashseen{}%
        \yytextlastchar=\yytextseenlastchar
        \yyfmark=\yyfmarklast
        \yysmark=\yysmarklast
                                                           %
    \fi                                                    % }
    \concat\yytext@seen\yyfutureyytext                     % ... reinsert the tokens seen by the lexer before 
                                                           % ... \yygetpreviousaction got rolling
    \yyfutureyytext{}%
    \yytextbackuptrue
    \YYDOBEFOREACTION                                      % YY_DO_BEFORE_ACTION;
    \ifyyflexdebug
        \ferrmessage{action.: \the\yyact, state: \the\yycurrentstate\space(\the\yytext) \parsernamespace}%
    \fi
    \doaction
}

\def\YYRULESETUP{%                  %#define YY_RULE_SETUP \
    \yytoksempty{\yytext}{}{%       %	if ( yyleng > 0 ) \
        \ifnum\n=\yytextlastchar    %		YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (yytext[yyleng - 1] == '\n'); \
            \YYATBOL=\@ne           %	YY_USER_ACTION
        \else                       %#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
            \YYATBOL=\z@
            \ifyyflexdebug\ferrmessage{YYATBOL: 0}\fi
        \fi
    }%
}

%#define yy_set_bol(at_bol) \
%       { \
%       if ( ! YY_CURRENT_BUFFER ){\
%        yyensure_buffer_stack (); \
%               YY_CURRENT_BUFFER_LVALUE =    \
%            yy_create_buffer(yyin,YY_BUF_SIZE ); \
%       } \
%       YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
%       }

\def\yysetbol#1{\YYATBOL=#1\relax} % we do not switch or create buffers

%#define BEGIN yyg->yy_start = 1 + 2 *
% should be:
%#define BEGIN(state) yyg->yy_start = 1 + 2 * ( state )

\newif\iftracestates

\def\yylexstate#1{\csname flexstate\parsernamespace #1\endcsname}

\def\yyBEGIN#1{%
    \yyg@yystart
    \expandafter\ifx\csname flexstate\parsernamespace #1\endcsname\relax
        #1 \iftracestates\ferrmessage{now in state: #1}\fi
    \else
        \csname flexstate\parsernamespace #1\endcsname\relax
        \iftracestates\ferrmessage{now in state: #1 (\number\csname flexstate\parsernamespace #1\endcsname)}\fi
    \fi
    \multiply\yyg@yystart\tw@
    \advance\yyg@yystart\@ne
}

\def\yyBEGINr#1{%
    \yyg@yystart#1%
    \iftracestates\ferrmessage{new state: \the\yyg@yystart}\fi
    \multiply\yyg@yystart\tw@
    \advance\yyg@yystart\@ne
}

%#define YY_START ((yyg->yy_start - 1) / 2)

\def\YYSTART{%
    \expandafter\xdivbytwo\expandafter{\number
    \expandafter\xdecrement\expandafter{\number\yyg@yystart}}
}

\def\yypushstate#1{%
    \expandafter\yypush\expandafter{\number\YYSTART}\on\yystatestack
    \yyBEGIN{#1}%
}

\def\yypopstate{%
    \yypop\yystatestack\into{\expandafter\yyBEGIN\romannumeral0}%
    \iftracestates\ferrmessage{new state (* 2 + 1 scrambled): \the\yyg@yystart}\fi
}

\def\yytopstate#1{%
    \yyreadstack\yystatestack\at\z@\to#1%
}

\let\yylexcontinue\yylwhile % complete the while loop (requires \yylexnext)
\def\yylexcontinue{\yytext{}\yytextpure{}\yytext@{}\yylwhile} % complete the while loop

% \yylextail is the return point from the lexer

\def\yylexreturnbootstrap#1{%
    \yytext{}\yytext@{}\yytextpure{}%
    \expandafter\ifx\csname token\parsernamespace #1\endcsname\relax
                             % this token value is undefined
        \let\yylextail\yylex % so lex the next token
    \else
        \yychar\csname token\parsernamespace #1\endcsname\relax
        \let\yylextail\yyparsetail
    \fi
}

\def\yylexreturnregular#1{%
    \yychar\csname token\parsernamespace #1\endcsname\relax
    \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail
}

\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
    \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
    \yylexreturn{#1}%
}

\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
    \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}}%
    \yychar`#1\relax
    \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail
}

\def\yylexreturnchar{%
    \expandafter\yylexreturnraw\the\yytextpure
}

\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}}%
    \yychar#1\relax
    \yytext{}\yytext@{}\yytextpure{}\let\yylextail\yyparsetail
}

\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\yyfatal#1{\yycomplain{#1}\yyerrterminate}

\def\yywarn#1{\yycomplain{#1}\yylexnext}

% \yyless is slow and the macros below have not been tested in their current
% form: avoid them

\def\yyless#1{%
    \yyless@backup
    \ifnum#1=\z@
        \yyfmark=\formatmarker
        \yysmark=\stashmarker
        \ROLLBACKCURRENTTOKEN
    \else
        \let\oldyyreturn\yyreturn
        \edef\yyreturn{\noexpand\yyskipnchars{\number#1}}%
        \expandafter\yyinput\the\yytext@\yyeof
    \fi
}

\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
            \edef\yyreturn{\noexpand\yyskipnchars{\xdecrement{#1}}}%
            \yybreak@\yyinput
        \fi
    \yycontinue
}

\def\yyl@ss#1\yyeof{%
    \yyfmark=\formatmarker
    \yysmark=\stashmarker
    \yylesslaststash\yystash
    \yylesslastformat\yyformat
    \unput{#1}%
    \let\yyreturn\oldyyreturn
}

% \unput has a slightly different semantics from \flex's unput() since
% it puts back an arbitrary string rather than a character; it clobbers
% the values of \yytext, \yytext@, and \yytextpure so these must be saved before
% \unput is used

\def\unput#1{%
    \yytext@{#1}%
    \concatl\yytext@\yytext@seen
    \yytext{}\yytext@{}\yytextpure{}%
%    \yystringempty{#1}{}{\yytextbackuptrue}% TODO: just set \yytexbackuptrue
    \yytextbackuptrue
}

%#define ROLLBACK_CURRENT_TOKEN                                  \
%  do {                                                          \
%    scanner_cursor.column -= mbsnwidth (yytext, yyleng, 0);     \
%    yyless (0);                                                 \
%  } while (0)

\def\ROLLBACKCURRENTTOKEN{% this does not reset the streams
    \concatl\yytext\yytextseen
    \concatl\yytext\yytext@seen % do not rollback collected streams
    \yytext{}\yytext@{}\yytextpure{}%
    \yytextbackuptrue
}