From: Ulya Trofimovich Date: Sat, 2 Apr 2016 16:25:23 +0000 (+0100) Subject: Lexer: unified handling of various re2c directives. X-Git-Tag: 1.0~39^2~335 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7280f0ea5c0cf4c5b6a591e34dcfc0d792c3ba94;p=re2c Lexer: unified handling of various re2c directives. Now when lexer encounters the beginning of a new directive, it dumps all the intermediate code to the output. Before this commit re2c lexer dumped intermediate code on each newline that occured in the input. So this commit affects two aspects: - Intermediate code is dumped much less often: it's good for performance, but it becomes more probable that the intermediate code will occasionally occupy too much buffer space and incur buffer resize. - Some re2c directives ignored characters right before the (on the same line). These unfortunate characters are no longer ignored. --- diff --git a/re2c/bootstrap/src/parse/lex.cc b/re2c/bootstrap/src/parse/lex.cc index 83a8c631..4dda0a6f 100644 --- a/re2c/bootstrap/src/parse/lex.cc +++ b/re2c/bootstrap/src/parse/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Sat Apr 2 15:20:14 2016 */ +/* Generated by re2c 0.16 on Sat Apr 2 17:18:35 2016 */ #line 1 "../src/parse/lex.re" #include "src/util/c99_stdint.h" #include @@ -55,8 +55,10 @@ Scanner::ParseMode Scanner::echo() tok = cur; echo: + const char *start = cur; -#line 60 "src/parse/lex.cc" + +#line 62 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -114,23 +116,22 @@ echo: } } ++YYCURSOR; -#line 172 "../src/parse/lex.re" +#line 157 "../src/parse/lex.re" { if (opts->target == opt_t::CODE) { - out.wraw(tok, tok_len () - 1); - // -1 so we don't write out the \0 + out.wraw(tok, start); } if (cur == eof) { return Stop; } } -#line 128 "src/parse/lex.cc" +#line 129 "src/parse/lex.cc" yy4: ++YYCURSOR; yy5: -#line 182 "../src/parse/lex.re" +#line 177 "../src/parse/lex.re" { goto echo; } -#line 134 "src/parse/lex.cc" +#line 135 "src/parse/lex.cc" yy6: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -139,16 +140,13 @@ yy6: } if (yych == '#') goto yy14; yy7: -#line 163 "../src/parse/lex.re" +#line 171 "../src/parse/lex.re" { - if (opts->target == opt_t::CODE) { - out.wraw(tok, tok_len ()); - } cline++; - tok = pos = cur; + pos = cur; goto echo; } -#line 152 "src/parse/lex.cc" +#line 150 "src/parse/lex.cc" yy8: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy6; @@ -191,23 +189,17 @@ yy14: } yy16: ++YYCURSOR; -#line 77 "../src/parse/lex.re" +#line 78 "../src/parse/lex.re" { - if (opts->rFlag) - { - fatal("found standard 're2c' block while using -r flag"); - } - if (opts->target == opt_t::CODE) - { - const size_t lexeme_len = cur[-1] == '{' - ? sizeof ("%{") - 1 - : sizeof ("/*!re2c") - 1; - out.wraw(tok, tok_len () - lexeme_len); - } - tok = cur; - return Parse; - } -#line 211 "src/parse/lex.cc" + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (opts->rFlag) { + fatal("found standard 're2c' block while using -r flag"); + } + return Parse; + } +#line 203 "src/parse/lex.cc" yy18: yych = (YYCTYPE)*++YYCURSOR; if (yych == '!') goto yy20; @@ -437,12 +429,12 @@ yy65: yy67: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 158 "../src/parse/lex.re" +#line 166 "../src/parse/lex.re" { set_sourceline(); goto echo; } -#line 446 "src/parse/lex.cc" +#line 438 "src/parse/lex.cc" yy69: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy67; @@ -538,14 +530,15 @@ yy90: goto yy13; yy91: ++YYCURSOR; -#line 121 "../src/parse/lex.re" +#line 118 "../src/parse/lex.re" { if (opts->target == opt_t::CODE) { - out.wdelay_yymaxfill(); + out.wraw(tok, start) + .wdelay_yymaxfill(); } goto eoc; } -#line 549 "src/parse/lex.cc" +#line 542 "src/parse/lex.cc" yy93: yych = (YYCTYPE)*++YYCURSOR; if (yych == '2') goto yy100; @@ -556,22 +549,18 @@ yy94: goto yy13; yy95: ++YYCURSOR; -#line 104 "../src/parse/lex.re" +#line 100 "../src/parse/lex.re" { - if (!opts->rFlag) - { - fatal("found 'use:re2c' block without -r flag"); - } - reuse(); - if (opts->target == opt_t::CODE) - { - const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; - out.wraw(tok, tok_len () - lexeme_len); - } - tok = cur; - return Reuse; - } -#line 575 "src/parse/lex.cc" + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (!opts->rFlag) { + fatal("found 'use:re2c' block without -r flag"); + } + reuse(); + return Reuse; + } +#line 564 "src/parse/lex.cc" yy97: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'r') goto yy102; @@ -606,32 +595,32 @@ yy104: goto yy13; yy105: ++YYCURSOR; -#line 92 "../src/parse/lex.re" +#line 88 "../src/parse/lex.re" { - if (opts->rFlag) - { - opts.reset_mapCodeName (); - } - else - { - fatal("found 'rules:re2c' block without -r flag"); - } - tok = cur; - return Rules; - } -#line 623 "src/parse/lex.cc" + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (opts->rFlag) { + opts.reset_mapCodeName (); + } else { + fatal("found 'rules:re2c' block without -r flag"); + } + return Rules; + } +#line 611 "src/parse/lex.cc" yy107: ++YYCURSOR; -#line 135 "../src/parse/lex.re" +#line 134 "../src/parse/lex.re" { if (opts->target == opt_t::CODE) { - out.wdelay_line_info().ws("\n") + out.wraw(tok, start) + .wdelay_line_info().ws("\n") .wdelay_types().ws("\n") .wline_info(cline, get_fname().c_str()); } goto eoc; } -#line 635 "src/parse/lex.cc" +#line 624 "src/parse/lex.cc" yy109: yych = (YYCTYPE)*++YYCURSOR; if (yych == '2') goto yy113; @@ -642,9 +631,14 @@ yy110: goto yy13; yy111: ++YYCURSOR; -#line 119 "../src/parse/lex.re" - { goto eoc; } -#line 648 "src/parse/lex.cc" +#line 111 "../src/parse/lex.re" + { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + goto eoc; + } +#line 642 "src/parse/lex.cc" yy113: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'c') goto yy115; @@ -658,8 +652,7 @@ yy115: #line 144 "../src/parse/lex.re" { if (opts->target == opt_t::CODE) { - const size_t len = sizeof("/*!contexts:re2c") - 1; - out.wraw(tok, tok_len() - len); + out.wraw(tok, start); } ConfContexts *conf = new ConfContexts; lex_conf_contexts(*conf); @@ -669,24 +662,25 @@ yy115: tok = pos = cur; goto echo; } -#line 673 "src/parse/lex.cc" +#line 666 "src/parse/lex.cc" yy117: ++YYCURSOR; -#line 128 "../src/parse/lex.re" +#line 126 "../src/parse/lex.re" { if (opts->target == opt_t::CODE) { - out.wdelay_state_goto(opts->topIndent); + out.wraw(tok, start) + .wdelay_state_goto(opts->topIndent); } goto eoc; } -#line 683 "src/parse/lex.cc" +#line 677 "src/parse/lex.cc" } -#line 183 "../src/parse/lex.re" +#line 178 "../src/parse/lex.re" eoc: -#line 690 "src/parse/lex.cc" +#line 684 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -702,20 +696,20 @@ eoc: } yy121: ++YYCURSOR; -#line 187 "../src/parse/lex.re" +#line 182 "../src/parse/lex.re" { fatal("expected end of block"); } -#line 708 "src/parse/lex.cc" +#line 702 "src/parse/lex.cc" yy123: ++YYCURSOR; yy124: -#line 188 "../src/parse/lex.re" +#line 183 "../src/parse/lex.re" { goto eoc; } -#line 714 "src/parse/lex.cc" +#line 708 "src/parse/lex.cc" yy125: ++YYCURSOR; -#line 189 "../src/parse/lex.re" +#line 184 "../src/parse/lex.re" { ++ignored; goto eoc; } -#line 719 "src/parse/lex.cc" +#line 713 "src/parse/lex.cc" yy127: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy125; @@ -724,7 +718,7 @@ yy128: yych = (YYCTYPE)*++YYCURSOR; if (yych != '/') goto yy124; ++YYCURSOR; -#line 190 "../src/parse/lex.re" +#line 185 "../src/parse/lex.re" { if (ignored > 0) { cline += ignored; @@ -734,9 +728,9 @@ yy128: tok = pos = cur; goto echo; } -#line 738 "src/parse/lex.cc" +#line 732 "src/parse/lex.cc" } -#line 199 "../src/parse/lex.re" +#line 194 "../src/parse/lex.re" } @@ -756,7 +750,7 @@ scan: start: -#line 760 "src/parse/lex.cc" +#line 754 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -862,12 +856,12 @@ start: yy133: ++YYCURSOR; yy134: -#line 377 "../src/parse/lex.re" +#line 372 "../src/parse/lex.re" { fatalf("unexpected character: '%c'", *tok); goto scan; } -#line 871 "src/parse/lex.cc" +#line 865 "src/parse/lex.cc" yy135: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -875,11 +869,11 @@ yy135: if (yybm[0+yych] & 16) { goto yy135; } -#line 361 "../src/parse/lex.re" +#line 356 "../src/parse/lex.re" { goto scan; } -#line 883 "src/parse/lex.cc" +#line 877 "src/parse/lex.cc" yy138: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -890,65 +884,65 @@ yy138: if (yych == '#') goto yy167; } yy139: -#line 370 "../src/parse/lex.re" +#line 365 "../src/parse/lex.re" { if (cur == eof) return 0; pos = cur; cline++; goto scan; } -#line 901 "src/parse/lex.cc" +#line 895 "src/parse/lex.cc" yy140: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy138; goto yy134; yy141: ++YYCURSOR; -#line 248 "../src/parse/lex.re" +#line 243 "../src/parse/lex.re" { yylval.regexp = lex_str('"', opts->bCaseInsensitive || opts->bCaseInverted); return TOKEN_REGEXP; } -#line 910 "src/parse/lex.cc" +#line 904 "src/parse/lex.cc" yy143: yych = (YYCTYPE)*++YYCURSOR; if (yych == '}') goto yy169; goto yy134; yy144: ++YYCURSOR; -#line 247 "../src/parse/lex.re" +#line 242 "../src/parse/lex.re" { yylval.regexp = lex_str('\'', opts->bCaseInsensitive || !opts->bCaseInverted); return TOKEN_REGEXP; } -#line 919 "src/parse/lex.cc" +#line 913 "src/parse/lex.cc" yy146: ++YYCURSOR; yy147: -#line 264 "../src/parse/lex.re" +#line 259 "../src/parse/lex.re" { return *tok; } -#line 927 "src/parse/lex.cc" +#line 921 "src/parse/lex.cc" yy148: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '/') goto yy169; -#line 268 "../src/parse/lex.re" +#line 263 "../src/parse/lex.re" { yylval.op = *tok; return TOKEN_STAR; } -#line 936 "src/parse/lex.cc" +#line 930 "src/parse/lex.cc" yy150: ++YYCURSOR; -#line 272 "../src/parse/lex.re" +#line 267 "../src/parse/lex.re" { yylval.op = *tok; return TOKEN_CLOSE; } -#line 944 "src/parse/lex.cc" +#line 938 "src/parse/lex.cc" yy152: ++YYCURSOR; -#line 356 "../src/parse/lex.re" +#line 351 "../src/parse/lex.re" { yylval.regexp = mkDot(); return TOKEN_REGEXP; } -#line 952 "src/parse/lex.cc" +#line 946 "src/parse/lex.cc" yy154: yych = (YYCTYPE)*++YYCURSOR; if (yych == '*') goto yy171; @@ -988,9 +982,9 @@ yy158: yy159: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '^') goto yy190; -#line 249 "../src/parse/lex.re" +#line 244 "../src/parse/lex.re" { yylval.regexp = lex_cls(false); return TOKEN_REGEXP; } -#line 994 "src/parse/lex.cc" +#line 988 "src/parse/lex.cc" yy161: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1014,12 +1008,12 @@ yy162: } } yy163: -#line 218 "../src/parse/lex.re" +#line 213 "../src/parse/lex.re" { depth = 1; goto code; } -#line 1023 "src/parse/lex.cc" +#line 1017 "src/parse/lex.cc" yy164: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1059,31 +1053,31 @@ yy167: } yy169: ++YYCURSOR; -#line 242 "../src/parse/lex.re" +#line 237 "../src/parse/lex.re" { tok = cur; return 0; } -#line 1068 "src/parse/lex.cc" +#line 1062 "src/parse/lex.cc" yy171: ++YYCURSOR; -#line 236 "../src/parse/lex.re" +#line 231 "../src/parse/lex.re" { depth = 1; goto comment; } -#line 1076 "src/parse/lex.cc" +#line 1070 "src/parse/lex.cc" yy173: ++YYCURSOR; -#line 233 "../src/parse/lex.re" +#line 228 "../src/parse/lex.re" { goto nextLine; } -#line 1083 "src/parse/lex.cc" +#line 1077 "src/parse/lex.cc" yy175: ++YYCURSOR; YYCURSOR -= 1; -#line 340 "../src/parse/lex.re" +#line 335 "../src/parse/lex.re" { if (!opts->FFlag) { yylval.str = new std::string (tok, tok_len()); @@ -1099,19 +1093,19 @@ yy175: return TOKEN_REGEXP; } } -#line 1103 "src/parse/lex.cc" +#line 1097 "src/parse/lex.cc" yy177: yych = (YYCTYPE)*++YYCURSOR; goto yy203; yy178: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 335 "../src/parse/lex.re" +#line 330 "../src/parse/lex.re" { yylval.str = new std::string (tok, tok_len ()); return TOKEN_ID; } -#line 1115 "src/parse/lex.cc" +#line 1109 "src/parse/lex.cc" yy180: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1138,20 +1132,20 @@ yy181: yy182: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '>') goto yy204; -#line 227 "../src/parse/lex.re" +#line 222 "../src/parse/lex.re" { tok += 2; /* skip ":=" */ depth = 0; goto code; } -#line 1148 "src/parse/lex.cc" +#line 1142 "src/parse/lex.cc" yy184: ++YYCURSOR; -#line 255 "../src/parse/lex.re" +#line 250 "../src/parse/lex.re" { return TOKEN_SETUP; } -#line 1155 "src/parse/lex.cc" +#line 1149 "src/parse/lex.cc" yy186: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1173,17 +1167,17 @@ yy187: } } yy189: -#line 259 "../src/parse/lex.re" +#line 254 "../src/parse/lex.re" { yylval.str = new std::string(tok + 1, tok_len() - 1); return TOKEN_CTX; } -#line 1182 "src/parse/lex.cc" +#line 1176 "src/parse/lex.cc" yy190: ++YYCURSOR; -#line 250 "../src/parse/lex.re" +#line 245 "../src/parse/lex.re" { yylval.regexp = lex_cls(true); return TOKEN_REGEXP; } -#line 1187 "src/parse/lex.cc" +#line 1181 "src/parse/lex.cc" yy192: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1192,11 +1186,11 @@ yy192: yy193: ++YYCURSOR; yy194: -#line 308 "../src/parse/lex.re" +#line 303 "../src/parse/lex.re" { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 1200 "src/parse/lex.cc" +#line 1194 "src/parse/lex.cc" yy195: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1249,7 +1243,7 @@ yy199: yy200: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 322 "../src/parse/lex.re" +#line 317 "../src/parse/lex.re" { yylval.str = new std::string (tok, tok_len ()); if (opts->FFlag) @@ -1262,7 +1256,7 @@ yy200: return TOKEN_ID; } } -#line 1266 "src/parse/lex.cc" +#line 1260 "src/parse/lex.cc" yy202: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1285,11 +1279,11 @@ yy203: yy204: ++YYCURSOR; YYCURSOR -= 2; -#line 223 "../src/parse/lex.re" +#line 218 "../src/parse/lex.re" { return *tok; } -#line 1293 "src/parse/lex.cc" +#line 1287 "src/parse/lex.cc" yy206: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1323,11 +1317,11 @@ yy209: yy210: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 252 "../src/parse/lex.re" +#line 247 "../src/parse/lex.re" { return TOKEN_NOCOND; } -#line 1331 "src/parse/lex.cc" +#line 1325 "src/parse/lex.cc" yy212: yych = (YYCTYPE)*++YYCURSOR; YYCTXMARKER = YYCURSOR; @@ -1342,7 +1336,7 @@ yy213: goto yy194; yy214: ++YYCURSOR; -#line 277 "../src/parse/lex.re" +#line 272 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 1, yylval.extop.min)) { @@ -1351,10 +1345,10 @@ yy214: yylval.extop.max = yylval.extop.min; return TOKEN_CLOSESIZE; } -#line 1355 "src/parse/lex.cc" +#line 1349 "src/parse/lex.cc" yy216: ++YYCURSOR; -#line 312 "../src/parse/lex.re" +#line 307 "../src/parse/lex.re" { if (!opts->FFlag) { fatal("curly braces for names only allowed with -F switch"); @@ -1362,7 +1356,7 @@ yy216: yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces return TOKEN_ID; } -#line 1366 "src/parse/lex.cc" +#line 1360 "src/parse/lex.cc" yy218: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'n') goto yy224; @@ -1382,7 +1376,7 @@ yy220: goto yy166; yy222: ++YYCURSOR; -#line 299 "../src/parse/lex.re" +#line 294 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok + 1, cur - 2, yylval.extop.min)) { @@ -1391,19 +1385,19 @@ yy222: yylval.extop.max = std::numeric_limits::max(); return TOKEN_CLOSESIZE; } -#line 1395 "src/parse/lex.cc" +#line 1389 "src/parse/lex.cc" yy224: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'e') goto yy229; goto yy166; yy225: ++YYCURSOR; -#line 320 "../src/parse/lex.re" +#line 315 "../src/parse/lex.re" { lex_conf (); return TOKEN_CONF; } -#line 1404 "src/parse/lex.cc" +#line 1398 "src/parse/lex.cc" yy227: ++YYCURSOR; -#line 286 "../src/parse/lex.re" +#line 281 "../src/parse/lex.re" { const char * p = strchr (tok, ','); if (!s_to_u32_unsafe (tok + 1, p, yylval.extop.min)) @@ -1416,7 +1410,7 @@ yy227: } return TOKEN_CLOSESIZE; } -#line 1420 "src/parse/lex.cc" +#line 1414 "src/parse/lex.cc" yy229: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '0') goto yy231; @@ -1472,12 +1466,12 @@ yy234: yy236: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 365 "../src/parse/lex.re" +#line 360 "../src/parse/lex.re" { set_sourceline (); goto scan; } -#line 1481 "src/parse/lex.cc" +#line 1475 "src/parse/lex.cc" yy238: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy236; @@ -1502,12 +1496,12 @@ yy242: if (yych == '\n') goto yy166; goto yy239; } -#line 381 "../src/parse/lex.re" +#line 376 "../src/parse/lex.re" flex_name: -#line 1511 "src/parse/lex.cc" +#line 1505 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1516,32 +1510,32 @@ flex_name: if (yych == '\r') goto yy249; ++YYCURSOR; yy246: -#line 392 "../src/parse/lex.re" +#line 387 "../src/parse/lex.re" { YYCURSOR = tok; goto start; } -#line 1525 "src/parse/lex.cc" +#line 1519 "src/parse/lex.cc" yy247: ++YYCURSOR; -#line 386 "../src/parse/lex.re" +#line 381 "../src/parse/lex.re" { YYCURSOR = tok; lexer_state = LEX_NORMAL; return TOKEN_FID_END; } -#line 1534 "src/parse/lex.cc" +#line 1528 "src/parse/lex.cc" yy249: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '\n') goto yy247; goto yy246; } -#line 396 "../src/parse/lex.re" +#line 391 "../src/parse/lex.re" code: -#line 1545 "src/parse/lex.cc" +#line 1539 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1602,7 +1596,7 @@ code: } yy252: ++YYCURSOR; -#line 459 "../src/parse/lex.re" +#line 454 "../src/parse/lex.re" { if (cur == eof) { @@ -1614,15 +1608,15 @@ yy252: } goto code; } -#line 1618 "src/parse/lex.cc" +#line 1612 "src/parse/lex.cc" yy254: ++YYCURSOR; yy255: -#line 473 "../src/parse/lex.re" +#line 468 "../src/parse/lex.re" { goto code; } -#line 1626 "src/parse/lex.cc" +#line 1620 "src/parse/lex.cc" yy256: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1641,7 +1635,7 @@ yy256: } } yy257: -#line 440 "../src/parse/lex.re" +#line 435 "../src/parse/lex.re" { if (depth == 0) { @@ -1661,7 +1655,7 @@ yy257: cline++; goto code; } -#line 1665 "src/parse/lex.cc" +#line 1659 "src/parse/lex.cc" yy258: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1674,7 +1668,7 @@ yy259: goto yy276; yy260: ++YYCURSOR; -#line 412 "../src/parse/lex.re" +#line 407 "../src/parse/lex.re" { if (depth == 0) { @@ -1686,10 +1680,10 @@ yy260: } goto code; } -#line 1690 "src/parse/lex.cc" +#line 1684 "src/parse/lex.cc" yy262: ++YYCURSOR; -#line 400 "../src/parse/lex.re" +#line 395 "../src/parse/lex.re" { if (depth == 0) { @@ -1702,7 +1696,7 @@ yy262: } goto code; } -#line 1706 "src/parse/lex.cc" +#line 1700 "src/parse/lex.cc" yy264: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1714,7 +1708,7 @@ yy264: } yy265: YYCURSOR -= 1; -#line 427 "../src/parse/lex.re" +#line 422 "../src/parse/lex.re" { if (depth == 0) { @@ -1728,7 +1722,7 @@ yy265: cline++; goto code; } -#line 1732 "src/parse/lex.cc" +#line 1726 "src/parse/lex.cc" yy266: yych = (YYCTYPE)*++YYCURSOR; goto yy265; @@ -1763,11 +1757,11 @@ yy271: if (yych >= '#') goto yy274; yy272: ++YYCURSOR; -#line 470 "../src/parse/lex.re" +#line 465 "../src/parse/lex.re" { goto code; } -#line 1771 "src/parse/lex.cc" +#line 1765 "src/parse/lex.cc" yy274: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1857,12 +1851,12 @@ yy288: yy290: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 423 "../src/parse/lex.re" +#line 418 "../src/parse/lex.re" { set_sourceline (); goto code; } -#line 1866 "src/parse/lex.cc" +#line 1860 "src/parse/lex.cc" yy292: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy290; @@ -1891,12 +1885,12 @@ yy296: if (yych == '\n') goto yy269; goto yy293; } -#line 476 "../src/parse/lex.re" +#line 471 "../src/parse/lex.re" comment: -#line 1900 "src/parse/lex.cc" +#line 1894 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -1943,7 +1937,7 @@ comment: } ++YYCURSOR; yy300: -#line 508 "../src/parse/lex.re" +#line 503 "../src/parse/lex.re" { if (cur == eof) { @@ -1951,7 +1945,7 @@ yy300: } goto comment; } -#line 1955 "src/parse/lex.cc" +#line 1949 "src/parse/lex.cc" yy301: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yybm[0+yych] & 32) { @@ -1959,7 +1953,7 @@ yy301: } if (yych == '#') goto yy308; yy302: -#line 499 "../src/parse/lex.re" +#line 494 "../src/parse/lex.re" { if (cur == eof) { @@ -1969,7 +1963,7 @@ yy302: cline++; goto comment; } -#line 1973 "src/parse/lex.cc" +#line 1967 "src/parse/lex.cc" yy303: yych = (YYCTYPE)*++YYCURSOR; if (yych == '/') goto yy310; @@ -2003,7 +1997,7 @@ yy308: } yy310: ++YYCURSOR; -#line 480 "../src/parse/lex.re" +#line 475 "../src/parse/lex.re" { if (--depth == 0) { @@ -2014,16 +2008,16 @@ yy310: goto comment; } } -#line 2018 "src/parse/lex.cc" +#line 2012 "src/parse/lex.cc" yy312: ++YYCURSOR; -#line 490 "../src/parse/lex.re" +#line 485 "../src/parse/lex.re" { ++depth; fatal("ambiguous /* found"); goto comment; } -#line 2027 "src/parse/lex.cc" +#line 2021 "src/parse/lex.cc" yy314: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'i') goto yy307; @@ -2080,12 +2074,12 @@ yy322: yy324: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 495 "../src/parse/lex.re" +#line 490 "../src/parse/lex.re" { set_sourceline (); goto comment; } -#line 2089 "src/parse/lex.cc" +#line 2083 "src/parse/lex.cc" yy326: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy324; @@ -2110,28 +2104,28 @@ yy330: if (yych == '\n') goto yy307; goto yy327; } -#line 515 "../src/parse/lex.re" +#line 510 "../src/parse/lex.re" nextLine: -#line 2119 "src/parse/lex.cc" +#line 2113 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == '\n') goto yy335; ++YYCURSOR; -#line 526 "../src/parse/lex.re" +#line 521 "../src/parse/lex.re" { if(cur == eof) { return 0; } goto nextLine; } -#line 2132 "src/parse/lex.cc" +#line 2126 "src/parse/lex.cc" yy335: ++YYCURSOR; -#line 519 "../src/parse/lex.re" +#line 514 "../src/parse/lex.re" { if(cur == eof) { return 0; } @@ -2139,9 +2133,9 @@ yy335: cline++; goto scan; } -#line 2143 "src/parse/lex.cc" +#line 2137 "src/parse/lex.cc" } -#line 531 "../src/parse/lex.re" +#line 526 "../src/parse/lex.re" } @@ -2165,35 +2159,35 @@ const RegExp *Scanner::lex_cls(bool neg) uint32_t u, l; fst: -#line 2169 "src/parse/lex.cc" +#line 2163 "src/parse/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == ']') goto yy340; -#line 555 "../src/parse/lex.re" +#line 550 "../src/parse/lex.re" { l = lex_cls_chr(); goto snd; } -#line 2177 "src/parse/lex.cc" +#line 2171 "src/parse/lex.cc" yy340: ++YYCURSOR; -#line 554 "../src/parse/lex.re" +#line 549 "../src/parse/lex.re" { goto end; } -#line 2182 "src/parse/lex.cc" +#line 2176 "src/parse/lex.cc" } -#line 556 "../src/parse/lex.re" +#line 551 "../src/parse/lex.re" snd: -#line 2188 "src/parse/lex.cc" +#line 2182 "src/parse/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = (YYCTYPE)*(YYMARKER = YYCURSOR); if (yych == '-') goto yy345; yy344: -#line 559 "../src/parse/lex.re" +#line 554 "../src/parse/lex.re" { u = l; goto add; } -#line 2197 "src/parse/lex.cc" +#line 2191 "src/parse/lex.cc" yy345: yych = (YYCTYPE)*++YYCURSOR; if (yych != ']') goto yy347; @@ -2202,7 +2196,7 @@ yy345: yy347: ++YYCURSOR; YYCURSOR -= 1; -#line 560 "../src/parse/lex.re" +#line 555 "../src/parse/lex.re" { u = lex_cls_chr(); if (l > u) { @@ -2211,9 +2205,9 @@ yy347: } goto add; } -#line 2215 "src/parse/lex.cc" +#line 2209 "src/parse/lex.cc" } -#line 568 "../src/parse/lex.re" +#line 563 "../src/parse/lex.re" add: if (!(s = opts->encoding.encodeRange(l, u))) { @@ -2232,7 +2226,7 @@ uint32_t Scanner::lex_cls_chr() { tok = cur; -#line 2236 "src/parse/lex.cc" +#line 2230 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2241,14 +2235,14 @@ uint32_t Scanner::lex_cls_chr() if (yych == '\n') goto yy353; if (yych == '\\') goto yy355; ++YYCURSOR; -#line 591 "../src/parse/lex.re" +#line 586 "../src/parse/lex.re" { return static_cast(tok[0]); } -#line 2247 "src/parse/lex.cc" +#line 2241 "src/parse/lex.cc" yy353: ++YYCURSOR; -#line 586 "../src/parse/lex.re" +#line 581 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2252 "src/parse/lex.cc" +#line 2246 "src/parse/lex.cc" yy355: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= '`') { @@ -2297,31 +2291,31 @@ yy355: } } } -#line 589 "../src/parse/lex.re" +#line 584 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2303 "src/parse/lex.cc" +#line 2297 "src/parse/lex.cc" yy357: ++YYCURSOR; -#line 604 "../src/parse/lex.re" +#line 599 "../src/parse/lex.re" { warn.useless_escape(tline, tok - pos, tok[1]); return static_cast(tok[1]); } -#line 2311 "src/parse/lex.cc" +#line 2305 "src/parse/lex.cc" yy359: ++YYCURSOR; -#line 602 "../src/parse/lex.re" +#line 597 "../src/parse/lex.re" { return static_cast('-'); } -#line 2316 "src/parse/lex.cc" +#line 2310 "src/parse/lex.cc" yy361: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych <= '/') goto yy362; if (yych <= '7') goto yy386; yy362: -#line 588 "../src/parse/lex.re" +#line 583 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2325 "src/parse/lex.cc" +#line 2319 "src/parse/lex.cc" yy363: yych = (YYCTYPE)*++YYCURSOR; goto yy362; @@ -2337,9 +2331,9 @@ yy364: if (yych <= 'f') goto yy388; } yy365: -#line 587 "../src/parse/lex.re" +#line 582 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2343 "src/parse/lex.cc" +#line 2337 "src/parse/lex.cc" yy366: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2355,49 +2349,49 @@ yy366: } yy367: ++YYCURSOR; -#line 601 "../src/parse/lex.re" +#line 596 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2361 "src/parse/lex.cc" +#line 2355 "src/parse/lex.cc" yy369: ++YYCURSOR; -#line 603 "../src/parse/lex.re" +#line 598 "../src/parse/lex.re" { return static_cast(']'); } -#line 2366 "src/parse/lex.cc" +#line 2360 "src/parse/lex.cc" yy371: ++YYCURSOR; -#line 594 "../src/parse/lex.re" +#line 589 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2371 "src/parse/lex.cc" +#line 2365 "src/parse/lex.cc" yy373: ++YYCURSOR; -#line 595 "../src/parse/lex.re" +#line 590 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2376 "src/parse/lex.cc" +#line 2370 "src/parse/lex.cc" yy375: ++YYCURSOR; -#line 596 "../src/parse/lex.re" +#line 591 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2381 "src/parse/lex.cc" +#line 2375 "src/parse/lex.cc" yy377: ++YYCURSOR; -#line 597 "../src/parse/lex.re" +#line 592 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2386 "src/parse/lex.cc" +#line 2380 "src/parse/lex.cc" yy379: ++YYCURSOR; -#line 598 "../src/parse/lex.re" +#line 593 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2391 "src/parse/lex.cc" +#line 2385 "src/parse/lex.cc" yy381: ++YYCURSOR; -#line 599 "../src/parse/lex.re" +#line 594 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2396 "src/parse/lex.cc" +#line 2390 "src/parse/lex.cc" yy383: ++YYCURSOR; -#line 600 "../src/parse/lex.re" +#line 595 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2401 "src/parse/lex.cc" +#line 2395 "src/parse/lex.cc" yy385: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2460,9 +2454,9 @@ yy390: } yy391: ++YYCURSOR; -#line 593 "../src/parse/lex.re" +#line 588 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2466 "src/parse/lex.cc" +#line 2460 "src/parse/lex.cc" yy393: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2489,9 +2483,9 @@ yy394: } yy395: ++YYCURSOR; -#line 592 "../src/parse/lex.re" +#line 587 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2495 "src/parse/lex.cc" +#line 2489 "src/parse/lex.cc" yy397: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2515,7 +2509,7 @@ yy398: goto yy387; } } -#line 608 "../src/parse/lex.re" +#line 603 "../src/parse/lex.re" } @@ -2524,7 +2518,7 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = false; tok = cur; -#line 2528 "src/parse/lex.cc" +#line 2522 "src/parse/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2533,17 +2527,17 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) if (yych == '\n') goto yy403; if (yych == '\\') goto yy405; ++YYCURSOR; -#line 621 "../src/parse/lex.re" +#line 616 "../src/parse/lex.re" { end = tok[0] == quote; return static_cast(tok[0]); } -#line 2542 "src/parse/lex.cc" +#line 2536 "src/parse/lex.cc" yy403: ++YYCURSOR; -#line 616 "../src/parse/lex.re" +#line 611 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error"); } -#line 2547 "src/parse/lex.cc" +#line 2541 "src/parse/lex.cc" yy405: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) <= 'a') { @@ -2589,28 +2583,28 @@ yy405: } } } -#line 619 "../src/parse/lex.re" +#line 614 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in escape sequence"); } -#line 2595 "src/parse/lex.cc" +#line 2589 "src/parse/lex.cc" yy407: ++YYCURSOR; -#line 635 "../src/parse/lex.re" +#line 630 "../src/parse/lex.re" { if (tok[1] != quote) { warn.useless_escape(tline, tok - pos, tok[1]); } return static_cast(tok[1]); } -#line 2605 "src/parse/lex.cc" +#line 2599 "src/parse/lex.cc" yy409: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych <= '/') goto yy410; if (yych <= '7') goto yy432; yy410: -#line 618 "../src/parse/lex.re" +#line 613 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in octal escape sequence"); } -#line 2614 "src/parse/lex.cc" +#line 2608 "src/parse/lex.cc" yy411: yych = (YYCTYPE)*++YYCURSOR; goto yy410; @@ -2626,9 +2620,9 @@ yy412: if (yych <= 'f') goto yy434; } yy413: -#line 617 "../src/parse/lex.re" +#line 612 "../src/parse/lex.re" { fatal ((tok - pos) - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2632 "src/parse/lex.cc" +#line 2626 "src/parse/lex.cc" yy414: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2644,44 +2638,44 @@ yy414: } yy415: ++YYCURSOR; -#line 634 "../src/parse/lex.re" +#line 629 "../src/parse/lex.re" { return static_cast('\\'); } -#line 2650 "src/parse/lex.cc" +#line 2644 "src/parse/lex.cc" yy417: ++YYCURSOR; -#line 627 "../src/parse/lex.re" +#line 622 "../src/parse/lex.re" { return static_cast('\a'); } -#line 2655 "src/parse/lex.cc" +#line 2649 "src/parse/lex.cc" yy419: ++YYCURSOR; -#line 628 "../src/parse/lex.re" +#line 623 "../src/parse/lex.re" { return static_cast('\b'); } -#line 2660 "src/parse/lex.cc" +#line 2654 "src/parse/lex.cc" yy421: ++YYCURSOR; -#line 629 "../src/parse/lex.re" +#line 624 "../src/parse/lex.re" { return static_cast('\f'); } -#line 2665 "src/parse/lex.cc" +#line 2659 "src/parse/lex.cc" yy423: ++YYCURSOR; -#line 630 "../src/parse/lex.re" +#line 625 "../src/parse/lex.re" { return static_cast('\n'); } -#line 2670 "src/parse/lex.cc" +#line 2664 "src/parse/lex.cc" yy425: ++YYCURSOR; -#line 631 "../src/parse/lex.re" +#line 626 "../src/parse/lex.re" { return static_cast('\r'); } -#line 2675 "src/parse/lex.cc" +#line 2669 "src/parse/lex.cc" yy427: ++YYCURSOR; -#line 632 "../src/parse/lex.re" +#line 627 "../src/parse/lex.re" { return static_cast('\t'); } -#line 2680 "src/parse/lex.cc" +#line 2674 "src/parse/lex.cc" yy429: ++YYCURSOR; -#line 633 "../src/parse/lex.re" +#line 628 "../src/parse/lex.re" { return static_cast('\v'); } -#line 2685 "src/parse/lex.cc" +#line 2679 "src/parse/lex.cc" yy431: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2744,9 +2738,9 @@ yy436: } yy437: ++YYCURSOR; -#line 626 "../src/parse/lex.re" +#line 621 "../src/parse/lex.re" { return unesc_oct(tok, cur); } -#line 2750 "src/parse/lex.cc" +#line 2744 "src/parse/lex.cc" yy439: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2773,9 +2767,9 @@ yy440: } yy441: ++YYCURSOR; -#line 625 "../src/parse/lex.re" +#line 620 "../src/parse/lex.re" { return unesc_hex(tok, cur); } -#line 2779 "src/parse/lex.cc" +#line 2773 "src/parse/lex.cc" yy443: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2799,7 +2793,7 @@ yy444: goto yy433; } } -#line 641 "../src/parse/lex.re" +#line 636 "../src/parse/lex.re" } @@ -2820,7 +2814,7 @@ void Scanner::set_sourceline () sourceline: tok = cur; -#line 2824 "src/parse/lex.cc" +#line 2818 "src/parse/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2869,14 +2863,14 @@ sourceline: yy447: ++YYCURSOR; yy448: -#line 684 "../src/parse/lex.re" +#line 679 "../src/parse/lex.re" { goto sourceline; } -#line 2877 "src/parse/lex.cc" +#line 2871 "src/parse/lex.cc" yy449: ++YYCURSOR; -#line 672 "../src/parse/lex.re" +#line 667 "../src/parse/lex.re" { if (cur == eof) { @@ -2889,7 +2883,7 @@ yy449: tok = cur; return; } -#line 2893 "src/parse/lex.cc" +#line 2887 "src/parse/lex.cc" yy451: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy448; @@ -2901,7 +2895,7 @@ yy452: if (yybm[0+yych] & 64) { goto yy452; } -#line 661 "../src/parse/lex.re" +#line 656 "../src/parse/lex.re" { if (!s_to_u32_unsafe (tok, cur, cline)) { @@ -2909,7 +2903,7 @@ yy452: } goto sourceline; } -#line 2913 "src/parse/lex.cc" +#line 2907 "src/parse/lex.cc" yy455: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2926,12 +2920,12 @@ yy457: goto yy448; yy458: ++YYCURSOR; -#line 668 "../src/parse/lex.re" +#line 663 "../src/parse/lex.re" { escape (in.file_name, std::string (tok + 1, tok_len () - 2)); // -2 to omit quotes goto sourceline; } -#line 2935 "src/parse/lex.cc" +#line 2929 "src/parse/lex.cc" yy460: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2939,7 +2933,7 @@ yy460: if (yych == '\n') goto yy457; goto yy455; } -#line 687 "../src/parse/lex.re" +#line 682 "../src/parse/lex.re" } diff --git a/re2c/src/codegen/output.cc b/re2c/src/codegen/output.cc index 3599572f..e037211e 100644 --- a/re2c/src/codegen/output.cc +++ b/re2c/src/codegen/output.cc @@ -101,9 +101,9 @@ std::ostream & OutputFile::stream () return blocks.back ()->fragments.back ()->stream; } -OutputFile & OutputFile::wraw (const char * s, size_t n) +OutputFile &OutputFile::wraw(const char *s, const char *e) { - stream ().write (s, static_cast (n)); + stream().write(s, static_cast(e - s)); return *this; } diff --git a/re2c/src/codegen/output.h b/re2c/src/codegen/output.h index 87bda7dd..0af7cfc3 100644 --- a/re2c/src/codegen/output.h +++ b/re2c/src/codegen/output.h @@ -86,7 +86,7 @@ public: void new_block (); // immediate output - OutputFile & wraw (const char * s, size_t n); + OutputFile & wraw (const char *s, const char *e); OutputFile & wc (char c); OutputFile & wc_hex (uint32_t n); OutputFile & wu32 (uint32_t n); diff --git a/re2c/src/parse/lex.re b/re2c/src/parse/lex.re index d59cf7fc..f199cf04 100644 --- a/re2c/src/parse/lex.re +++ b/re2c/src/parse/lex.re @@ -72,69 +72,69 @@ Scanner::ParseMode Scanner::echo() tok = cur; echo: + const char *start = cur; + /*!re2c - beginRE = "%{" | "/*!re2c"; - beginRE { - if (opts->rFlag) - { - fatal("found standard 're2c' block while using -r flag"); - } - if (opts->target == opt_t::CODE) - { - const size_t lexeme_len = cur[-1] == '{' - ? sizeof ("%{") - 1 - : sizeof ("/*!re2c") - 1; - out.wraw(tok, tok_len () - lexeme_len); - } - tok = cur; - return Parse; - } - "/*!rules:re2c" { - if (opts->rFlag) - { - opts.reset_mapCodeName (); - } - else - { - fatal("found 'rules:re2c' block without -r flag"); - } - tok = cur; - return Rules; - } - "/*!use:re2c" { - if (!opts->rFlag) - { - fatal("found 'use:re2c' block without -r flag"); - } - reuse(); - if (opts->target == opt_t::CODE) - { - const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; - out.wraw(tok, tok_len () - lexeme_len); - } - tok = cur; - return Reuse; - } + "%{" | "/*!re2c" { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (opts->rFlag) { + fatal("found standard 're2c' block while using -r flag"); + } + return Parse; + } - "/*!ignore:re2c" { goto eoc; } + "/*!rules:re2c" { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (opts->rFlag) { + opts.reset_mapCodeName (); + } else { + fatal("found 'rules:re2c' block without -r flag"); + } + return Rules; + } + + "/*!use:re2c" { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (!opts->rFlag) { + fatal("found 'use:re2c' block without -r flag"); + } + reuse(); + return Reuse; + } + + "/*!ignore:re2c" { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + goto eoc; + } "/*!max:re2c" { if (opts->target == opt_t::CODE) { - out.wdelay_yymaxfill(); + out.wraw(tok, start) + .wdelay_yymaxfill(); } goto eoc; } "/*!getstate:re2c" { if (opts->target == opt_t::CODE) { - out.wdelay_state_goto(opts->topIndent); + out.wraw(tok, start) + .wdelay_state_goto(opts->topIndent); } goto eoc; } "/*!types:re2c" { if (opts->target == opt_t::CODE) { - out.wdelay_line_info().ws("\n") + out.wraw(tok, start) + .wdelay_line_info().ws("\n") .wdelay_types().ws("\n") .wline_info(cline, get_fname().c_str()); } @@ -143,8 +143,7 @@ echo: "/*!contexts:re2c" { if (opts->target == opt_t::CODE) { - const size_t len = sizeof("/*!contexts:re2c") - 1; - out.wraw(tok, tok_len() - len); + out.wraw(tok, start); } ConfContexts *conf = new ConfContexts; lex_conf_contexts(*conf); @@ -155,30 +154,26 @@ echo: goto echo; } + zero { + if (opts->target == opt_t::CODE) { + out.wraw(tok, start); + } + if (cur == eof) { + return Stop; + } + } + eol space* "#" space* "line" space+ / lineinf { set_sourceline(); goto echo; } eol { - if (opts->target == opt_t::CODE) { - out.wraw(tok, tok_len ()); - } cline++; - tok = pos = cur; + pos = cur; goto echo; } - zero { - if (opts->target == opt_t::CODE) { - out.wraw(tok, tok_len () - 1); - // -1 so we don't write out the \0 - } - if (cur == eof) { - return Stop; - } - } - * { goto echo; } */