/usr/share/doc/re2c/examples/c/eof
/* Generated by re2c */ #line 1 "c/eof/03_eof_rule.re" // re2c $INPUT -o $OUTPUT #include <assert.h> // expect a null-terminated string static int lex(const char *str, unsigned int len) { const char *YYCURSOR = str, *YYLIMIT = str + len, *YYMARKER; int count = 0; loop: #line 15 "c/eof/03_eof_rule.c" { char yych; yych = *YYCURSOR; switch (yych) { case ' ': goto yy4; case '\'': goto yy7; default: if (YYLIMIT <= YYCURSOR) goto yy13; goto yy2; } yy2: ++YYCURSOR; yy3: #line 16 "c/eof/03_eof_rule.re" { return -1; } #line 31 "c/eof/03_eof_rule.c" yy4: yych = *++YYCURSOR; switch (yych) { case ' ': goto yy4; default: goto yy6; } yy6: #line 19 "c/eof/03_eof_rule.re" { goto loop; } #line 41 "c/eof/03_eof_rule.c" yy7: yych = *(YYMARKER = ++YYCURSOR); if (yych >= 0x01) goto yy9; if (YYLIMIT <= YYCURSOR) goto yy3; yy8: yych = *++YYCURSOR; yy9: switch (yych) { case '\'': goto yy10; case '\\': goto yy12; default: if (YYLIMIT <= YYCURSOR) goto yy14; goto yy8; } yy10: ++YYCURSOR; #line 18 "c/eof/03_eof_rule.re" { ++count; goto loop; } #line 60 "c/eof/03_eof_rule.c" yy12: yych = *++YYCURSOR; if (yych <= 0x00) { if (YYLIMIT <= YYCURSOR) goto yy14; goto yy8; } goto yy8; yy13: #line 17 "c/eof/03_eof_rule.re" { return count; } #line 71 "c/eof/03_eof_rule.c" yy14: YYCURSOR = YYMARKER; goto yy3; } #line 21 "c/eof/03_eof_rule.re" } #define TEST(s, r) assert(lex(s, sizeof(s) - 1) == r) int main() { TEST("", 0); TEST("'qu\0tes' 'are' 'fine: \\'' ", 3); TEST("'unterminated\\'", -1); return 0; }
.
Edit
..
Edit
01_sentinel.c
Edit
01_sentinel.re
Edit
02_bounds_checking.c
Edit
02_bounds_checking.re
Edit
03_eof_rule.c
Edit
03_eof_rule.re
Edit
04_generic_api_sentinel.c
Edit
04_generic_api_sentinel.re
Edit
05_generic_api_eof_rule.c
Edit
05_generic_api_eof_rule.re
Edit