mirror of
https://github.com/brazilofmux/tinymux
synced 2026-08-13 00:23:11 -04:00
Ragel's #line values depend on the Ragel build rather than on our source, so regenerating with a different Ragel rewrites dozens of #line-only lines and leaves the tree dirty after any pull that touches a .rl. That is not cosmetic: dounix.sh packages from the working tree, not from a git export, so the churn ships -- into the tarball and into the generated .patch.gz. Stripping the directives makes each output a function of its .rl alone. Same input, same file, every box. The cost is that a debugger reports positions in the generated .c rather than the .rl, which is the accepted trade for an artifact that can be compared by hash. Applied to all five Ragel outputs, not the four in docs/generated-files.md -- date_scan.cpp is also Ragel-generated and had 102 directives. color_ops.c 194 art_scan.cpp 24 date_scan.cpp 102 ast_scan.cpp 43 muxescape.cpp 16 total 379 sed rather than sed -i: the -i spelling differs between GNU and BSD, and this has to run on Linux, macOS and FreeBSD. Deleting whole lines is safe here -- all 379 directives are anchored at column 0 and none carries trailing code, both checked before the change. Makefile.in is hand-edited to match rather than regenerated: this box has automake 1.18.1 and the tree's Makefile.in came from 1.16.5, so autoreconf would churn whole files for a five-line change (#1477). The inserted lines are identical to the Makefile.am ones. The pre-commit hook needed teaching, and this commit is the example: it rejects a generated file staged without its source, but changing how a file is generated rewrites the output while the .rl stays untouched. The build rule now counts as a source. Verified all three ways -- a bare generated file is still blocked, and staging it with either its .rl or its Makefile.am is accepted. Verified on macOS/arm64: - regeneration is idempotent: all five byte-identical across two runs - the generated diffs are 379 deletions, every one a #line, nothing added - outputs return to mode 444, no .tmp files left behind - make test 35 passed / 1 skipped / 0 failed (jit=yes stubslave=no nls=yes realitylvls=yes wodrealms=yes) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
508 lines
9.7 KiB
C++
508 lines
9.7 KiB
C++
|
|
/*! \file ast_scan.rl
|
|
* \brief Ragel-generated scanner for MUX expression tokenizer.
|
|
*
|
|
* This file is processed by Ragel to generate ast_scan.cpp.
|
|
* Do not edit ast_scan.cpp directly.
|
|
*
|
|
* Build: ragel -G2 -o ast_scan.cpp ast_scan.rl
|
|
*/
|
|
|
|
#include "copyright.h"
|
|
#include "autoconf.h"
|
|
#include "config.h"
|
|
#include "externs.h"
|
|
|
|
#include "ast.h"
|
|
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
static inline ASTTokenType ast_pct_token_type(ASTLexMode mode)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case ASTLEX_NOEVAL:
|
|
case ASTLEX_STRUCTURAL:
|
|
return ASTTOK_LIT;
|
|
case ASTLEX_EVAL:
|
|
default:
|
|
return ASTTOK_PCT;
|
|
}
|
|
}
|
|
|
|
// Helper: construct token text view from Ragel ts/te pointers.
|
|
// Views point directly into the input buffer — no allocation.
|
|
//
|
|
#define TOK_TEXT() std::string_view(reinterpret_cast<const char *>(ts), \
|
|
static_cast<size_t>(te - ts))
|
|
|
|
|
|
|
|
|
|
// Ragel state table data.
|
|
//
|
|
|
|
static const int ast_scanner_start = 2;
|
|
static const int ast_scanner_error = 0;
|
|
|
|
static const int ast_scanner_en_main = 2;
|
|
|
|
|
|
|
|
std::vector<ASTToken> ast_tokenize_mode(const UTF8 *input, size_t nLen,
|
|
ASTLexMode mode)
|
|
{
|
|
std::vector<ASTToken> tokens;
|
|
|
|
// Find actual length (stop at NUL or nLen).
|
|
//
|
|
size_t actualLen = 0;
|
|
while (actualLen < nLen && input[actualLen] != '\0')
|
|
{
|
|
actualLen++;
|
|
}
|
|
|
|
if (0 == actualLen)
|
|
{
|
|
tokens.push_back({ASTTOK_EOF, ""});
|
|
return tokens;
|
|
}
|
|
|
|
// Ragel scanner variables.
|
|
//
|
|
const UTF8 *p = input;
|
|
const UTF8 *pe = input + actualLen;
|
|
const UTF8 *eof = pe;
|
|
const UTF8 *ts;
|
|
const UTF8 *te;
|
|
int cs;
|
|
int act;
|
|
|
|
|
|
{
|
|
cs = ast_scanner_start;
|
|
ts = 0;
|
|
te = 0;
|
|
act = 0;
|
|
}
|
|
|
|
|
|
{
|
|
if ( p == pe )
|
|
goto _test_eof;
|
|
switch ( cs )
|
|
{
|
|
tr0:
|
|
{{p = ((te))-1;}{
|
|
tokens.push_back({ASTTOK_LIT, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr6:
|
|
{te = p+1;{
|
|
if ( !tokens.empty()
|
|
&& tokens.back().type == ASTTOK_LIT)
|
|
{
|
|
tokens.back().type = ASTTOK_FUNC;
|
|
}
|
|
tokens.push_back({ASTTOK_LPAREN, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr7:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_RPAREN, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr8:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_COMMA, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr9:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_SEMI, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr10:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_LBRACK, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr12:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_RBRACK, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr13:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_LBRACE, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr14:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_RBRACE, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr15:
|
|
{te = p;p--;{
|
|
tokens.push_back({ASTTOK_LIT, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr17:
|
|
{te = p;p--;{
|
|
tokens.push_back({ASTTOK_SPACE, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr18:
|
|
{te = p;p--;{
|
|
tokens.push_back({ASTTOK_LIT, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr19:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr20:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr21:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr22:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr28:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr30:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr31:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr32:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr33:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr35:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr36:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr37:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr38:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr40:
|
|
{te = p;p--;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr41:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr42:
|
|
{te = p+1;{
|
|
tokens.push_back({ast_pct_token_type(mode), TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr43:
|
|
{te = p;p--;{
|
|
tokens.push_back({ASTTOK_ESC, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
tr44:
|
|
{te = p+1;{
|
|
tokens.push_back({ASTTOK_ESC, TOK_TEXT()});
|
|
}}
|
|
goto st2;
|
|
st2:
|
|
{ts = 0;}
|
|
if ( ++p == pe )
|
|
goto _test_eof2;
|
|
case 2:
|
|
{ts = p;}
|
|
switch( (*p) ) {
|
|
case 0u: goto st0;
|
|
case 32u: goto st4;
|
|
case 35u: goto st5;
|
|
case 37u: goto st6;
|
|
case 40u: goto tr6;
|
|
case 41u: goto tr7;
|
|
case 44u: goto tr8;
|
|
case 59u: goto tr9;
|
|
case 91u: goto tr10;
|
|
case 92u: goto st15;
|
|
case 93u: goto tr12;
|
|
case 123u: goto tr13;
|
|
case 125u: goto tr14;
|
|
}
|
|
goto tr1;
|
|
st0:
|
|
cs = 0;
|
|
goto _out;
|
|
tr1:
|
|
{te = p+1;}
|
|
goto st3;
|
|
st3:
|
|
if ( ++p == pe )
|
|
goto _test_eof3;
|
|
case 3:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr15;
|
|
case 32u: goto tr15;
|
|
case 35u: goto st1;
|
|
case 37u: goto tr15;
|
|
case 44u: goto tr15;
|
|
case 59u: goto tr15;
|
|
case 123u: goto tr15;
|
|
case 125u: goto tr15;
|
|
}
|
|
if ( (*p) > 41u ) {
|
|
if ( 91u <= (*p) && (*p) <= 93u )
|
|
goto tr15;
|
|
} else if ( (*p) >= 40u )
|
|
goto tr15;
|
|
goto tr1;
|
|
st1:
|
|
if ( ++p == pe )
|
|
goto _test_eof1;
|
|
case 1:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr0;
|
|
case 32u: goto tr0;
|
|
case 44u: goto tr0;
|
|
case 59u: goto tr0;
|
|
case 64u: goto tr0;
|
|
case 123u: goto tr0;
|
|
case 125u: goto tr0;
|
|
}
|
|
if ( (*p) < 40u ) {
|
|
if ( 35u <= (*p) && (*p) <= 37u )
|
|
goto tr0;
|
|
} else if ( (*p) > 41u ) {
|
|
if ( 91u <= (*p) && (*p) <= 93u )
|
|
goto tr0;
|
|
} else
|
|
goto tr0;
|
|
goto tr1;
|
|
st4:
|
|
if ( ++p == pe )
|
|
goto _test_eof4;
|
|
case 4:
|
|
if ( (*p) == 32u )
|
|
goto st4;
|
|
goto tr17;
|
|
st5:
|
|
if ( ++p == pe )
|
|
goto _test_eof5;
|
|
case 5:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr18;
|
|
case 32u: goto tr18;
|
|
case 37u: goto tr18;
|
|
case 44u: goto tr18;
|
|
case 59u: goto tr18;
|
|
case 64u: goto tr19;
|
|
case 123u: goto tr18;
|
|
case 125u: goto tr18;
|
|
}
|
|
if ( (*p) < 40u ) {
|
|
if ( 35u <= (*p) && (*p) <= 36u )
|
|
goto tr19;
|
|
} else if ( (*p) > 41u ) {
|
|
if ( 91u <= (*p) && (*p) <= 93u )
|
|
goto tr18;
|
|
} else
|
|
goto tr18;
|
|
goto tr1;
|
|
st6:
|
|
if ( ++p == pe )
|
|
goto _test_eof6;
|
|
case 6:
|
|
switch( (*p) ) {
|
|
case 61u: goto st7;
|
|
case 67u: goto st9;
|
|
case 73u: goto st11;
|
|
case 81u: goto st12;
|
|
case 86u: goto st14;
|
|
case 88u: goto st9;
|
|
case 99u: goto st9;
|
|
case 105u: goto st11;
|
|
case 113u: goto st12;
|
|
case 118u: goto st14;
|
|
case 120u: goto st9;
|
|
}
|
|
if ( 48u <= (*p) && (*p) <= 57u )
|
|
goto tr22;
|
|
goto tr21;
|
|
st7:
|
|
if ( ++p == pe )
|
|
goto _test_eof7;
|
|
case 7:
|
|
if ( (*p) == 60u )
|
|
goto st8;
|
|
goto tr28;
|
|
st8:
|
|
if ( ++p == pe )
|
|
goto _test_eof8;
|
|
case 8:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr30;
|
|
case 41u: goto tr30;
|
|
case 44u: goto tr30;
|
|
case 62u: goto tr31;
|
|
case 91u: goto tr30;
|
|
case 93u: goto tr30;
|
|
case 123u: goto tr30;
|
|
case 125u: goto tr30;
|
|
}
|
|
goto st8;
|
|
st9:
|
|
if ( ++p == pe )
|
|
goto _test_eof9;
|
|
case 9:
|
|
if ( (*p) == 60u )
|
|
goto st10;
|
|
goto tr33;
|
|
st10:
|
|
if ( ++p == pe )
|
|
goto _test_eof10;
|
|
case 10:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr35;
|
|
case 41u: goto tr35;
|
|
case 44u: goto tr35;
|
|
case 62u: goto tr36;
|
|
case 91u: goto tr35;
|
|
case 93u: goto tr35;
|
|
case 123u: goto tr35;
|
|
case 125u: goto tr35;
|
|
}
|
|
goto st10;
|
|
st11:
|
|
if ( ++p == pe )
|
|
goto _test_eof11;
|
|
case 11:
|
|
if ( 48u <= (*p) && (*p) <= 57u )
|
|
goto tr37;
|
|
goto tr32;
|
|
st12:
|
|
if ( ++p == pe )
|
|
goto _test_eof12;
|
|
case 12:
|
|
if ( (*p) == 60u )
|
|
goto st13;
|
|
goto tr38;
|
|
st13:
|
|
if ( ++p == pe )
|
|
goto _test_eof13;
|
|
case 13:
|
|
switch( (*p) ) {
|
|
case 0u: goto tr40;
|
|
case 41u: goto tr40;
|
|
case 44u: goto tr40;
|
|
case 62u: goto tr41;
|
|
case 91u: goto tr40;
|
|
case 93u: goto tr40;
|
|
case 123u: goto tr40;
|
|
case 125u: goto tr40;
|
|
}
|
|
goto st13;
|
|
st14:
|
|
if ( ++p == pe )
|
|
goto _test_eof14;
|
|
case 14:
|
|
if ( (*p) > 90u ) {
|
|
if ( 97u <= (*p) && (*p) <= 122u )
|
|
goto tr42;
|
|
} else if ( (*p) >= 65u )
|
|
goto tr42;
|
|
goto tr32;
|
|
st15:
|
|
if ( ++p == pe )
|
|
goto _test_eof15;
|
|
case 15:
|
|
goto tr44;
|
|
}
|
|
_test_eof2: cs = 2; goto _test_eof;
|
|
_test_eof3: cs = 3; goto _test_eof;
|
|
_test_eof1: cs = 1; goto _test_eof;
|
|
_test_eof4: cs = 4; goto _test_eof;
|
|
_test_eof5: cs = 5; goto _test_eof;
|
|
_test_eof6: cs = 6; goto _test_eof;
|
|
_test_eof7: cs = 7; goto _test_eof;
|
|
_test_eof8: cs = 8; goto _test_eof;
|
|
_test_eof9: cs = 9; goto _test_eof;
|
|
_test_eof10: cs = 10; goto _test_eof;
|
|
_test_eof11: cs = 11; goto _test_eof;
|
|
_test_eof12: cs = 12; goto _test_eof;
|
|
_test_eof13: cs = 13; goto _test_eof;
|
|
_test_eof14: cs = 14; goto _test_eof;
|
|
_test_eof15: cs = 15; goto _test_eof;
|
|
|
|
_test_eof: {}
|
|
if ( p == eof )
|
|
{
|
|
switch ( cs ) {
|
|
case 3: goto tr15;
|
|
case 1: goto tr0;
|
|
case 4: goto tr17;
|
|
case 5: goto tr18;
|
|
case 6: goto tr20;
|
|
case 7: goto tr28;
|
|
case 8: goto tr30;
|
|
case 9: goto tr32;
|
|
case 10: goto tr35;
|
|
case 11: goto tr32;
|
|
case 12: goto tr32;
|
|
case 13: goto tr40;
|
|
case 14: goto tr32;
|
|
case 15: goto tr43;
|
|
}
|
|
}
|
|
|
|
_out: {}
|
|
}
|
|
|
|
|
|
tokens.push_back({ASTTOK_EOF, ""});
|
|
return tokens;
|
|
}
|
|
|
|
std::vector<ASTToken> ast_tokenize(const UTF8 *input, size_t nLen)
|
|
{
|
|
return ast_tokenize_mode(input, nLen, ASTLEX_EVAL);
|
|
}
|