From: Ulya Trofimovich Date: Wed, 12 Aug 2015 21:32:24 +0000 (+0100) Subject: Fixed '#27 re2c crashes reading files containing %{ %}' (patch by Rui) X-Git-Tag: 0.15~125 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1c414cebba51cabf258b0773e1df7cb213cf1f7;p=re2c Fixed '#27 re2c crashes reading files containing %{ %}' (patch by Rui) merged commit b068f3ad2ea7b01aa1eb63cb655c3357f856e85b from master. --- diff --git a/re2c/bootstrap/src/parse/scanner_lex.cc b/re2c/bootstrap/src/parse/scanner_lex.cc index 49b03500..820cf8f4 100644 --- a/re2c/bootstrap/src/parse/scanner_lex.cc +++ b/re2c/bootstrap/src/parse/scanner_lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Wed Aug 12 18:50:00 2015 */ +/* Generated by re2c 0.14.3 on Wed Aug 12 22:30:20 2015 */ #line 1 "../src/parse/scanner_lex.re" #include #include @@ -109,11 +109,11 @@ echo: } } ++YYCURSOR; -#line 195 "../src/parse/scanner_lex.re" +#line 199 "../src/parse/scanner_lex.re" { if (!(ignore_eoc || DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok) - 1); + out.write(tok, cur - tok - 1); // -1 so we don't write out the \0 } if(cur == eof) @@ -125,7 +125,7 @@ echo: yy4: ++YYCURSOR; yy5: -#line 206 "../src/parse/scanner_lex.re" +#line 210 "../src/parse/scanner_lex.re" { goto echo; } @@ -138,7 +138,7 @@ yy6: } if (yych == '#') goto yy91; yy7: -#line 182 "../src/parse/scanner_lex.re" +#line 186 "../src/parse/scanner_lex.re" { if (ignore_eoc) { @@ -146,7 +146,7 @@ yy7: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; cline++; @@ -236,7 +236,7 @@ yy21: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 84 "../src/parse/scanner_lex.re" +#line 87 "../src/parse/scanner_lex.re" { if (rFlag) { @@ -263,12 +263,15 @@ yy32: } if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(&cur[-7]) - (const char*)(tok)); + const size_t lexeme_len = cur[-1] == '{' + ? sizeof ("%{") - 1 + : sizeof ("/*!re2c") - 1; + out.write(tok, cur - tok - lexeme_len); } tok = cur; return Parse; } -#line 272 "src/parse/scanner_lex.cc" +#line 275 "src/parse/scanner_lex.cc" yy34: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'e') goto yy12; @@ -283,7 +286,7 @@ yy34: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 96 "../src/parse/scanner_lex.re" +#line 99 "../src/parse/scanner_lex.re" { if (!rFlag) { @@ -292,12 +295,13 @@ yy34: reuse(); if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(&cur[-11]) - (const char*)(tok)); + const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; + out.write(tok, cur - tok - lexeme_len); } tok = cur; return Reuse; } -#line 301 "src/parse/scanner_lex.cc" +#line 305 "src/parse/scanner_lex.cc" yy42: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'x') goto yy12; @@ -312,7 +316,7 @@ yy42: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 109 "../src/parse/scanner_lex.re" +#line 113 "../src/parse/scanner_lex.re" { if (!DFlag) { @@ -322,7 +326,7 @@ yy42: ignore_eoc = true; goto echo; } -#line 326 "src/parse/scanner_lex.cc" +#line 330 "src/parse/scanner_lex.cc" yy50: yych = (YYCTYPE)*++YYCURSOR; if (yych != 't') goto yy12; @@ -347,14 +351,14 @@ yy50: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 118 "../src/parse/scanner_lex.re" +#line 122 "../src/parse/scanner_lex.re" { tok = pos = cur; out.insert_state_goto (topIndent); ignore_eoc = true; goto echo; } -#line 358 "src/parse/scanner_lex.cc" +#line 362 "src/parse/scanner_lex.cc" yy63: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'n') goto yy12; @@ -375,13 +379,13 @@ yy63: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 124 "../src/parse/scanner_lex.re" +#line 128 "../src/parse/scanner_lex.re" { tok = pos = cur; ignore_eoc = true; goto echo; } -#line 385 "src/parse/scanner_lex.cc" +#line 389 "src/parse/scanner_lex.cc" yy74: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'p') goto yy12; @@ -400,7 +404,7 @@ yy74: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'c') goto yy12; ++YYCURSOR; -#line 129 "../src/parse/scanner_lex.re" +#line 133 "../src/parse/scanner_lex.re" { tok = pos = cur; ignore_eoc = true; @@ -414,14 +418,14 @@ yy74: } goto echo; } -#line 418 "src/parse/scanner_lex.cc" +#line 422 "src/parse/scanner_lex.cc" yy84: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy87; if (yych == '\r') goto yy86; yy85: -#line 160 "../src/parse/scanner_lex.re" +#line 164 "../src/parse/scanner_lex.re" { if (ignore_eoc) { @@ -435,18 +439,18 @@ yy85: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; goto echo; } -#line 444 "src/parse/scanner_lex.cc" +#line 448 "src/parse/scanner_lex.cc" yy86: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy12; yy87: ++YYCURSOR; -#line 142 "../src/parse/scanner_lex.re" +#line 146 "../src/parse/scanner_lex.re" { cline++; if (ignore_eoc) @@ -460,12 +464,12 @@ yy87: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; goto echo; } -#line 469 "src/parse/scanner_lex.cc" +#line 473 "src/parse/scanner_lex.cc" yy89: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -540,12 +544,12 @@ yy101: yy103: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 178 "../src/parse/scanner_lex.re" +#line 182 "../src/parse/scanner_lex.re" { set_sourceline (); goto echo; } -#line 549 "src/parse/scanner_lex.cc" +#line 553 "src/parse/scanner_lex.cc" yy105: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy103; @@ -570,7 +574,7 @@ yy109: if (yych == '\r') goto yy105; goto yy12; } -#line 209 "../src/parse/scanner_lex.re" +#line 213 "../src/parse/scanner_lex.re" } @@ -592,7 +596,7 @@ scan: start: -#line 596 "src/parse/scanner_lex.cc" +#line 600 "src/parse/scanner_lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -707,22 +711,22 @@ start: yy112: ++YYCURSOR; yy113: -#line 427 "../src/parse/scanner_lex.re" +#line 431 "../src/parse/scanner_lex.re" { fatalf("unexpected character: '%c'", *tok); goto scan; } -#line 716 "src/parse/scanner_lex.cc" +#line 720 "src/parse/scanner_lex.cc" yy114: ++YYCURSOR; yych = (YYCTYPE)*YYCURSOR; goto yy248; yy115: -#line 411 "../src/parse/scanner_lex.re" +#line 415 "../src/parse/scanner_lex.re" { goto scan; } -#line 726 "src/parse/scanner_lex.cc" +#line 730 "src/parse/scanner_lex.cc" yy116: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -733,14 +737,14 @@ yy116: if (yych == '#') goto yy228; } yy117: -#line 420 "../src/parse/scanner_lex.re" +#line 424 "../src/parse/scanner_lex.re" { if (cur == eof) return 0; pos = cur; cline++; goto scan; } -#line 744 "src/parse/scanner_lex.cc" +#line 748 "src/parse/scanner_lex.cc" yy118: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy225; @@ -750,11 +754,11 @@ yy119: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych != '\n') goto yy221; yy120: -#line 285 "../src/parse/scanner_lex.re" +#line 289 "../src/parse/scanner_lex.re" { fatal("unterminated string constant (missing \")"); } -#line 758 "src/parse/scanner_lex.cc" +#line 762 "src/parse/scanner_lex.cc" yy121: yych = (YYCTYPE)*++YYCURSOR; if (yych == '}') goto yy213; @@ -764,44 +768,44 @@ yy122: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych != '\n') goto yy216; yy123: -#line 288 "../src/parse/scanner_lex.re" +#line 292 "../src/parse/scanner_lex.re" { fatal("unterminated string constant (missing ')"); } -#line 772 "src/parse/scanner_lex.cc" +#line 776 "src/parse/scanner_lex.cc" yy124: ++YYCURSOR; yy125: -#line 314 "../src/parse/scanner_lex.re" +#line 318 "../src/parse/scanner_lex.re" { return *tok; } -#line 780 "src/parse/scanner_lex.cc" +#line 784 "src/parse/scanner_lex.cc" yy126: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '/') goto yy213; -#line 318 "../src/parse/scanner_lex.re" +#line 322 "../src/parse/scanner_lex.re" { yylval.op = *tok; return STAR; } -#line 789 "src/parse/scanner_lex.cc" +#line 793 "src/parse/scanner_lex.cc" yy128: ++YYCURSOR; -#line 322 "../src/parse/scanner_lex.re" +#line 326 "../src/parse/scanner_lex.re" { yylval.op = *tok; return CLOSE; } -#line 797 "src/parse/scanner_lex.cc" +#line 801 "src/parse/scanner_lex.cc" yy130: ++YYCURSOR; -#line 406 "../src/parse/scanner_lex.re" +#line 410 "../src/parse/scanner_lex.re" { yylval.regexp = mkDot(); return RANGE; } -#line 805 "src/parse/scanner_lex.cc" +#line 809 "src/parse/scanner_lex.cc" yy132: yych = (YYCTYPE)*++YYCURSOR; if (yych == '*') goto yy209; @@ -829,11 +833,11 @@ yy136: if (yych == '^') goto yy188; goto yy187; yy137: -#line 304 "../src/parse/scanner_lex.re" +#line 308 "../src/parse/scanner_lex.re" { fatal("unterminated range (missing ])"); } -#line 837 "src/parse/scanner_lex.cc" +#line 841 "src/parse/scanner_lex.cc" yy138: YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; @@ -859,12 +863,12 @@ yy139: } } yy140: -#line 230 "../src/parse/scanner_lex.re" +#line 234 "../src/parse/scanner_lex.re" { depth = 1; goto code; } -#line 868 "src/parse/scanner_lex.cc" +#line 872 "src/parse/scanner_lex.cc" yy141: yych = (YYCTYPE)*++YYCURSOR; if (yych == ',') goto yy160; @@ -936,14 +940,14 @@ yy145: yy147: ++YYCURSOR; yy148: -#line 350 "../src/parse/scanner_lex.re" +#line 354 "../src/parse/scanner_lex.re" { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 944 "src/parse/scanner_lex.cc" +#line 948 "src/parse/scanner_lex.cc" yy149: ++YYCURSOR; -#line 354 "../src/parse/scanner_lex.re" +#line 358 "../src/parse/scanner_lex.re" { if (!FFlag) { fatal("curly braces for names only allowed with -F switch"); @@ -951,16 +955,16 @@ yy149: yylval.str = new std::string (tok + 1, cur - tok - 2); return ID; } -#line 955 "src/parse/scanner_lex.cc" +#line 959 "src/parse/scanner_lex.cc" yy151: ++YYCURSOR; -#line 332 "../src/parse/scanner_lex.re" +#line 336 "../src/parse/scanner_lex.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = atoi((char *)tok+1); return CLOSESIZE; } -#line 964 "src/parse/scanner_lex.cc" +#line 968 "src/parse/scanner_lex.cc" yy153: yyaccept = 6; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -968,13 +972,13 @@ yy153: if (yych <= '9') goto yy156; if (yych != '}') goto yy148; ++YYCURSOR; -#line 344 "../src/parse/scanner_lex.re" +#line 348 "../src/parse/scanner_lex.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = -1; return CLOSESIZE; } -#line 978 "src/parse/scanner_lex.cc" +#line 982 "src/parse/scanner_lex.cc" yy156: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -983,13 +987,13 @@ yy156: if (yych <= '9') goto yy156; if (yych != '}') goto yy142; ++YYCURSOR; -#line 338 "../src/parse/scanner_lex.re" +#line 342 "../src/parse/scanner_lex.re" { yylval.extop.minsize = atoi((char *)tok+1); yylval.extop.maxsize = MAX(yylval.extop.minsize,atoi(strchr((char *)tok, ',')+1)); return CLOSESIZE; } -#line 993 "src/parse/scanner_lex.cc" +#line 997 "src/parse/scanner_lex.cc" yy160: yyaccept = 6; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -997,17 +1001,17 @@ yy160: if (yych <= '9') goto yy156; if (yych != '}') goto yy148; ++YYCURSOR; -#line 327 "../src/parse/scanner_lex.re" +#line 331 "../src/parse/scanner_lex.re" { yylval.op = '*'; return CLOSE; } -#line 1006 "src/parse/scanner_lex.cc" +#line 1010 "src/parse/scanner_lex.cc" yy163: ++YYCURSOR; yy164: YYCURSOR = YYCTXMARKER; -#line 387 "../src/parse/scanner_lex.re" +#line 391 "../src/parse/scanner_lex.re" { if (!FFlag) { yylval.str = new std::string (tok, cur - tok); @@ -1026,7 +1030,7 @@ yy164: return STRING; } } -#line 1030 "src/parse/scanner_lex.cc" +#line 1034 "src/parse/scanner_lex.cc" yy165: yych = (YYCTYPE)*++YYCURSOR; goto yy184; @@ -1034,12 +1038,12 @@ yy166: ++YYCURSOR; yy167: YYCURSOR = YYCTXMARKER; -#line 382 "../src/parse/scanner_lex.re" +#line 386 "../src/parse/scanner_lex.re" { yylval.str = new std::string (tok, cur - tok); return ID; } -#line 1043 "src/parse/scanner_lex.cc" +#line 1047 "src/parse/scanner_lex.cc" yy168: YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; @@ -1118,14 +1122,14 @@ yy174: } } yy176: -#line 362 "../src/parse/scanner_lex.re" +#line 366 "../src/parse/scanner_lex.re" { tok += 5; /* skip "re2c:" */ lexer_state = LEX_CONFIG; yylval.str = new std::string (tok, cur - tok); return CONFIG; } -#line 1129 "src/parse/scanner_lex.cc" +#line 1133 "src/parse/scanner_lex.cc" yy177: yych = (YYCTYPE)*++YYCURSOR; if (yych <= 'Z') { @@ -1184,7 +1188,7 @@ yy179: yy181: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 369 "../src/parse/scanner_lex.re" +#line 373 "../src/parse/scanner_lex.re" { yylval.str = new std::string (tok, cur - tok); if (FFlag) @@ -1197,7 +1201,7 @@ yy181: return ID; } } -#line 1201 "src/parse/scanner_lex.cc" +#line 1205 "src/parse/scanner_lex.cc" yy183: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1243,13 +1247,13 @@ yy190: goto yy186; yy191: ++YYCURSOR; -#line 298 "../src/parse/scanner_lex.re" +#line 302 "../src/parse/scanner_lex.re" { SubStr s (tok, cur - tok); yylval.regexp = ranToRE (s); return RANGE; } -#line 1253 "src/parse/scanner_lex.cc" +#line 1257 "src/parse/scanner_lex.cc" yy193: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1258,20 +1262,20 @@ yy193: goto yy188; yy194: ++YYCURSOR; -#line 292 "../src/parse/scanner_lex.re" +#line 296 "../src/parse/scanner_lex.re" { SubStr s (tok, cur - tok); yylval.regexp = invToRE (s); return RANGE; } -#line 1268 "src/parse/scanner_lex.cc" +#line 1272 "src/parse/scanner_lex.cc" yy196: ++YYCURSOR; -#line 311 "../src/parse/scanner_lex.re" +#line 315 "../src/parse/scanner_lex.re" { return SETUP; } -#line 1275 "src/parse/scanner_lex.cc" +#line 1279 "src/parse/scanner_lex.cc" yy198: YYCTXMARKER = YYCURSOR + 1; yych = (YYCTYPE)*++YYCURSOR; @@ -1301,11 +1305,11 @@ yy200: yy201: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 308 "../src/parse/scanner_lex.re" +#line 312 "../src/parse/scanner_lex.re" { return NOCOND; } -#line 1309 "src/parse/scanner_lex.cc" +#line 1313 "src/parse/scanner_lex.cc" yy203: yych = (YYCTYPE)*++YYCURSOR; if (yych == '>') goto yy201; @@ -1317,44 +1321,44 @@ yy204: yy205: ++YYCURSOR; if ((yych = (YYCTYPE)*YYCURSOR) == '>') goto yy207; -#line 239 "../src/parse/scanner_lex.re" +#line 243 "../src/parse/scanner_lex.re" { tok += 2; /* skip ":=" */ depth = 0; goto code; } -#line 1327 "src/parse/scanner_lex.cc" +#line 1331 "src/parse/scanner_lex.cc" yy207: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 235 "../src/parse/scanner_lex.re" +#line 239 "../src/parse/scanner_lex.re" { return *tok; } -#line 1335 "src/parse/scanner_lex.cc" +#line 1339 "src/parse/scanner_lex.cc" yy209: ++YYCURSOR; -#line 248 "../src/parse/scanner_lex.re" +#line 252 "../src/parse/scanner_lex.re" { depth = 1; goto comment; } -#line 1343 "src/parse/scanner_lex.cc" +#line 1347 "src/parse/scanner_lex.cc" yy211: ++YYCURSOR; -#line 245 "../src/parse/scanner_lex.re" +#line 249 "../src/parse/scanner_lex.re" { goto nextLine; } -#line 1350 "src/parse/scanner_lex.cc" +#line 1354 "src/parse/scanner_lex.cc" yy213: ++YYCURSOR; -#line 254 "../src/parse/scanner_lex.re" +#line 258 "../src/parse/scanner_lex.re" { tok = cur; return 0; } -#line 1358 "src/parse/scanner_lex.cc" +#line 1362 "src/parse/scanner_lex.cc" yy215: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1372,7 +1376,7 @@ yy216: goto yy215; yy218: ++YYCURSOR; -#line 272 "../src/parse/scanner_lex.re" +#line 276 "../src/parse/scanner_lex.re" { SubStr s (tok + 1, cur - tok - 2); if (bCaseInverted) @@ -1385,7 +1389,7 @@ yy218: } return STRING; } -#line 1389 "src/parse/scanner_lex.cc" +#line 1393 "src/parse/scanner_lex.cc" yy220: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1403,7 +1407,7 @@ yy221: goto yy220; yy223: ++YYCURSOR; -#line 259 "../src/parse/scanner_lex.re" +#line 263 "../src/parse/scanner_lex.re" { SubStr s (tok + 1, cur - tok - 2); if (bCaseInsensitive || bCaseInverted) @@ -1416,7 +1420,7 @@ yy223: } return STRING; } -#line 1420 "src/parse/scanner_lex.cc" +#line 1424 "src/parse/scanner_lex.cc" yy225: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1509,12 +1513,12 @@ yy238: yy240: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 415 "../src/parse/scanner_lex.re" +#line 419 "../src/parse/scanner_lex.re" { set_sourceline (); goto scan; } -#line 1518 "src/parse/scanner_lex.cc" +#line 1522 "src/parse/scanner_lex.cc" yy242: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy240; @@ -1549,12 +1553,12 @@ yy248: if (yych == ' ') goto yy247; goto yy115; } -#line 431 "../src/parse/scanner_lex.re" +#line 435 "../src/parse/scanner_lex.re" flex_name: -#line 1558 "src/parse/scanner_lex.cc" +#line 1562 "src/parse/scanner_lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1563,22 +1567,22 @@ flex_name: if (yych == '\r') goto yy255; ++YYCURSOR; yy252: -#line 442 "../src/parse/scanner_lex.re" +#line 446 "../src/parse/scanner_lex.re" { YYCURSOR = tok; goto start; } -#line 1572 "src/parse/scanner_lex.cc" +#line 1576 "src/parse/scanner_lex.cc" yy253: ++YYCURSOR; yy254: -#line 436 "../src/parse/scanner_lex.re" +#line 440 "../src/parse/scanner_lex.re" { YYCURSOR = tok; lexer_state = LEX_NORMAL; return FID_END; } -#line 1582 "src/parse/scanner_lex.cc" +#line 1586 "src/parse/scanner_lex.cc" yy255: yych = (YYCTYPE)*++YYCURSOR; if (yych != '\n') goto yy252; @@ -1586,12 +1590,12 @@ yy255: yych = (YYCTYPE)*YYCURSOR; goto yy254; } -#line 446 "../src/parse/scanner_lex.re" +#line 450 "../src/parse/scanner_lex.re" code: -#line 1595 "src/parse/scanner_lex.cc" +#line 1599 "src/parse/scanner_lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1652,7 +1656,7 @@ code: } yy259: ++YYCURSOR; -#line 509 "../src/parse/scanner_lex.re" +#line 513 "../src/parse/scanner_lex.re" { if (cur == eof) { @@ -1664,15 +1668,15 @@ yy259: } goto code; } -#line 1668 "src/parse/scanner_lex.cc" +#line 1672 "src/parse/scanner_lex.cc" yy261: ++YYCURSOR; yy262: -#line 523 "../src/parse/scanner_lex.re" +#line 527 "../src/parse/scanner_lex.re" { goto code; } -#line 1676 "src/parse/scanner_lex.cc" +#line 1680 "src/parse/scanner_lex.cc" yy263: YYCTXMARKER = YYCURSOR + 1; yyaccept = 0; @@ -1692,7 +1696,7 @@ yy263: } } yy264: -#line 490 "../src/parse/scanner_lex.re" +#line 494 "../src/parse/scanner_lex.re" { if (depth == 0) { @@ -1712,7 +1716,7 @@ yy264: cline++; goto code; } -#line 1716 "src/parse/scanner_lex.cc" +#line 1720 "src/parse/scanner_lex.cc" yy265: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1725,7 +1729,7 @@ yy266: goto yy272; yy267: ++YYCURSOR; -#line 462 "../src/parse/scanner_lex.re" +#line 466 "../src/parse/scanner_lex.re" { if (depth == 0) { @@ -1737,10 +1741,10 @@ yy267: } goto code; } -#line 1741 "src/parse/scanner_lex.cc" +#line 1745 "src/parse/scanner_lex.cc" yy269: ++YYCURSOR; -#line 450 "../src/parse/scanner_lex.re" +#line 454 "../src/parse/scanner_lex.re" { if (depth == 0) { @@ -1753,7 +1757,7 @@ yy269: } goto code; } -#line 1757 "src/parse/scanner_lex.cc" +#line 1761 "src/parse/scanner_lex.cc" yy271: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1784,11 +1788,11 @@ yy274: goto yy271; yy275: ++YYCURSOR; -#line 520 "../src/parse/scanner_lex.re" +#line 524 "../src/parse/scanner_lex.re" { goto code; } -#line 1792 "src/parse/scanner_lex.cc" +#line 1796 "src/parse/scanner_lex.cc" yy277: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1815,7 +1819,7 @@ yy280: } yy281: YYCURSOR = YYCTXMARKER; -#line 477 "../src/parse/scanner_lex.re" +#line 481 "../src/parse/scanner_lex.re" { if (depth == 0) { @@ -1829,7 +1833,7 @@ yy281: cline++; goto code; } -#line 1833 "src/parse/scanner_lex.cc" +#line 1837 "src/parse/scanner_lex.cc" yy282: yych = (YYCTYPE)*++YYCURSOR; goto yy281; @@ -1896,12 +1900,12 @@ yy293: yy295: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 473 "../src/parse/scanner_lex.re" +#line 477 "../src/parse/scanner_lex.re" { set_sourceline (); goto code; } -#line 1905 "src/parse/scanner_lex.cc" +#line 1909 "src/parse/scanner_lex.cc" yy297: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy295; @@ -1940,12 +1944,12 @@ yy302: goto yy273; } } -#line 526 "../src/parse/scanner_lex.re" +#line 530 "../src/parse/scanner_lex.re" comment: -#line 1949 "src/parse/scanner_lex.cc" +#line 1953 "src/parse/scanner_lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -1992,7 +1996,7 @@ comment: } ++YYCURSOR; yy307: -#line 558 "../src/parse/scanner_lex.re" +#line 562 "../src/parse/scanner_lex.re" { if (cur == eof) { @@ -2000,7 +2004,7 @@ yy307: } goto comment; } -#line 2004 "src/parse/scanner_lex.cc" +#line 2008 "src/parse/scanner_lex.cc" yy308: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yybm[0+yych] & 32) { @@ -2008,7 +2012,7 @@ yy308: } if (yych == '#') goto yy319; yy309: -#line 549 "../src/parse/scanner_lex.re" +#line 553 "../src/parse/scanner_lex.re" { if (cur == eof) { @@ -2018,7 +2022,7 @@ yy309: cline++; goto comment; } -#line 2022 "src/parse/scanner_lex.cc" +#line 2026 "src/parse/scanner_lex.cc" yy310: yych = (YYCTYPE)*++YYCURSOR; if (yych == '/') goto yy314; @@ -2027,16 +2031,16 @@ yy311: yych = (YYCTYPE)*++YYCURSOR; if (yych != '*') goto yy307; ++YYCURSOR; -#line 540 "../src/parse/scanner_lex.re" +#line 544 "../src/parse/scanner_lex.re" { ++depth; fatal("ambiguous /* found"); goto comment; } -#line 2037 "src/parse/scanner_lex.cc" +#line 2041 "src/parse/scanner_lex.cc" yy314: ++YYCURSOR; -#line 530 "../src/parse/scanner_lex.re" +#line 534 "../src/parse/scanner_lex.re" { if (--depth == 0) { @@ -2047,7 +2051,7 @@ yy314: goto comment; } } -#line 2051 "src/parse/scanner_lex.cc" +#line 2055 "src/parse/scanner_lex.cc" yy316: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2125,12 +2129,12 @@ yy329: yy331: ++YYCURSOR; YYCURSOR = YYCTXMARKER; -#line 545 "../src/parse/scanner_lex.re" +#line 549 "../src/parse/scanner_lex.re" { set_sourceline (); goto comment; } -#line 2134 "src/parse/scanner_lex.cc" +#line 2138 "src/parse/scanner_lex.cc" yy333: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy331; @@ -2155,28 +2159,28 @@ yy337: if (yych == '\r') goto yy333; goto yy318; } -#line 565 "../src/parse/scanner_lex.re" +#line 569 "../src/parse/scanner_lex.re" nextLine: -#line 2164 "src/parse/scanner_lex.cc" +#line 2168 "src/parse/scanner_lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych == '\n') goto yy342; ++YYCURSOR; -#line 576 "../src/parse/scanner_lex.re" +#line 580 "../src/parse/scanner_lex.re" { if(cur == eof) { return 0; } goto nextLine; } -#line 2177 "src/parse/scanner_lex.cc" +#line 2181 "src/parse/scanner_lex.cc" yy342: ++YYCURSOR; -#line 569 "../src/parse/scanner_lex.re" +#line 573 "../src/parse/scanner_lex.re" { if(cur == eof) { return 0; } @@ -2184,14 +2188,14 @@ yy342: cline++; goto scan; } -#line 2188 "src/parse/scanner_lex.cc" +#line 2192 "src/parse/scanner_lex.cc" } -#line 581 "../src/parse/scanner_lex.re" +#line 585 "../src/parse/scanner_lex.re" config: -#line 2195 "src/parse/scanner_lex.cc" +#line 2199 "src/parse/scanner_lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2237,32 +2241,32 @@ config: if (yych == '=') goto yy350; } ++YYCURSOR; -#line 592 "../src/parse/scanner_lex.re" +#line 596 "../src/parse/scanner_lex.re" { fatal("missing '='"); } -#line 2245 "src/parse/scanner_lex.cc" +#line 2249 "src/parse/scanner_lex.cc" yy348: ++YYCURSOR; yych = (YYCTYPE)*YYCURSOR; goto yy355; yy349: -#line 585 "../src/parse/scanner_lex.re" +#line 589 "../src/parse/scanner_lex.re" { goto config; } -#line 2255 "src/parse/scanner_lex.cc" +#line 2259 "src/parse/scanner_lex.cc" yy350: ++YYCURSOR; yych = (YYCTYPE)*YYCURSOR; goto yy353; yy351: -#line 588 "../src/parse/scanner_lex.re" +#line 592 "../src/parse/scanner_lex.re" { lexer_state = LEX_CONFIG_VALUE; return '='; } -#line 2266 "src/parse/scanner_lex.cc" +#line 2270 "src/parse/scanner_lex.cc" yy352: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2281,12 +2285,12 @@ yy355: if (yych == ' ') goto yy354; goto yy349; } -#line 595 "../src/parse/scanner_lex.re" +#line 599 "../src/parse/scanner_lex.re" value: -#line 2290 "src/parse/scanner_lex.cc" +#line 2294 "src/parse/scanner_lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2353,26 +2357,26 @@ value: } } yy358: -#line 604 "../src/parse/scanner_lex.re" +#line 608 "../src/parse/scanner_lex.re" { yylval.str = new std::string (tok, cur - tok); lexer_state = LEX_NORMAL; return VALUE; } -#line 2363 "src/parse/scanner_lex.cc" +#line 2367 "src/parse/scanner_lex.cc" yy359: ++YYCURSOR; if (yybm[0+(yych = (YYCTYPE)*YYCURSOR)] & 8) { goto yy364; } yy360: -#line 599 "../src/parse/scanner_lex.re" +#line 603 "../src/parse/scanner_lex.re" { yylval.number = atoi(std::string (tok, cur - tok).c_str()); lexer_state = LEX_NORMAL; return NUMBER; } -#line 2376 "src/parse/scanner_lex.cc" +#line 2380 "src/parse/scanner_lex.cc" yy361: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '0') goto yy365; @@ -2515,7 +2519,7 @@ yy379: if (yych == '\n') goto yy372; goto yy376; } -#line 609 "../src/parse/scanner_lex.re" +#line 613 "../src/parse/scanner_lex.re" } @@ -2538,7 +2542,7 @@ void Scanner::set_sourceline () sourceline: tok = cur; -#line 2542 "src/parse/scanner_lex.cc" +#line 2546 "src/parse/scanner_lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2587,14 +2591,14 @@ sourceline: yy382: ++YYCURSOR; yy383: -#line 651 "../src/parse/scanner_lex.re" +#line 655 "../src/parse/scanner_lex.re" { goto sourceline; } -#line 2595 "src/parse/scanner_lex.cc" +#line 2599 "src/parse/scanner_lex.cc" yy384: ++YYCURSOR; -#line 639 "../src/parse/scanner_lex.re" +#line 643 "../src/parse/scanner_lex.re" { if (cur == eof) { @@ -2607,7 +2611,7 @@ yy384: tok = cur; return; } -#line 2611 "src/parse/scanner_lex.cc" +#line 2615 "src/parse/scanner_lex.cc" yy386: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy383; @@ -2617,12 +2621,12 @@ yy387: yych = (YYCTYPE)*YYCURSOR; goto yy390; yy388: -#line 631 "../src/parse/scanner_lex.re" +#line 635 "../src/parse/scanner_lex.re" { cline = atoi(std::string (tok, cur - tok).c_str()); goto sourceline; } -#line 2626 "src/parse/scanner_lex.cc" +#line 2630 "src/parse/scanner_lex.cc" yy389: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2654,14 +2658,14 @@ yy394: goto yy391; yy395: ++YYCURSOR; -#line 635 "../src/parse/scanner_lex.re" +#line 639 "../src/parse/scanner_lex.re" { escape (in.file_name, std::string (tok + 1, cur - tok - 2)); goto sourceline; } -#line 2663 "src/parse/scanner_lex.cc" +#line 2667 "src/parse/scanner_lex.cc" } -#line 654 "../src/parse/scanner_lex.re" +#line 658 "../src/parse/scanner_lex.re" } diff --git a/re2c/src/parse/scanner_lex.re b/re2c/src/parse/scanner_lex.re index 342eccce..6683be0d 100644 --- a/re2c/src/parse/scanner_lex.re +++ b/re2c/src/parse/scanner_lex.re @@ -76,7 +76,10 @@ echo: } if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(&cur[-7]) - (const char*)(tok)); + const size_t lexeme_len = cur[-1] == '{' + ? sizeof ("%{") - 1 + : sizeof ("/*!re2c") - 1; + out.write(tok, cur - tok - lexeme_len); } tok = cur; return Parse; @@ -101,7 +104,8 @@ echo: reuse(); if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(&cur[-11]) - (const char*)(tok)); + const size_t lexeme_len = sizeof ("/*!use:re2c") - 1; + out.write(tok, cur - tok - lexeme_len); } tok = cur; return Reuse; @@ -152,7 +156,7 @@ echo: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; goto echo; @@ -170,7 +174,7 @@ echo: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; goto echo; @@ -186,7 +190,7 @@ echo: } else if (!(DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok)); + out.write(tok, cur - tok); } tok = pos = cur; cline++; @@ -195,7 +199,7 @@ echo: zero { if (!(ignore_eoc || DFlag || flag_skeleton)) { - out.write((const char*)(tok), (const char*)(cur) - (const char*)(tok) - 1); + out.write(tok, cur - tok - 1); // -1 so we don't write out the \0 } if(cur == eof)