From 2a5fe439b060eb0c5918e2abdffe570ef94f18e9 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 5 Apr 2017 20:45:42 +0100 Subject: [PATCH] Added syntax for tags with history. --- re2c/bootstrap/src/ast/lex.cc | 367 ++++++++++++++++--------------- re2c/bootstrap/src/ast/parser.cc | 2 +- re2c/src/ast/ast.cc | 7 +- re2c/src/ast/ast.h | 7 +- re2c/src/ast/lex.re | 4 +- re2c/src/ast/parser.ypp | 2 +- re2c/src/re/ast_to_re.cc | 4 +- re2c/src/re/tag.h | 9 +- 8 files changed, 206 insertions(+), 196 deletions(-) diff --git a/re2c/bootstrap/src/ast/lex.cc b/re2c/bootstrap/src/ast/lex.cc index b811e669..5ce2d4ed 100644 --- a/re2c/bootstrap/src/ast/lex.cc +++ b/re2c/bootstrap/src/ast/lex.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 on Tue Mar 7 22:52:18 2017 */ +/* Generated by re2c 0.16 on Wed Apr 5 20:36:03 2017 */ #line 1 "../src/ast/lex.re" #include "src/util/c99_stdint.h" #include @@ -888,7 +888,7 @@ scan: goto yy161; } if (yych <= '.') { - if (yych <= '$') { + if (yych <= '#') { if (yych <= '\r') { if (yych <= 0x08) goto yy159; if (yych <= '\n') goto yy164; @@ -897,40 +897,43 @@ scan: if (yych <= 0x1F) goto yy159; if (yych <= '!') goto yy167; if (yych <= '"') goto yy169; + goto yy171; } } else { - if (yych <= ')') { - if (yych <= '%') goto yy171; - if (yych <= '&') goto yy159; - if (yych <= '\'') goto yy172; - goto yy167; + if (yych <= '\'') { + if (yych == '%') goto yy172; + if (yych >= '\'') goto yy173; } else { - if (yych <= '*') goto yy174; - if (yych <= ',') goto yy167; - if (yych >= '.') goto yy175; + if (yych <= '*') { + if (yych <= ')') goto yy167; + goto yy175; + } else { + if (yych <= ',') goto yy167; + if (yych >= '.') goto yy176; + } } } } else { if (yych <= '\\') { if (yych <= '?') { - if (yych <= '/') goto yy177; - if (yych <= '9') goto yy178; - if (yych <= ':') goto yy180; + if (yych <= '/') goto yy178; + if (yych <= '9') goto yy179; + if (yych <= ':') goto yy181; goto yy167; } else { - if (yych <= '@') goto yy181; - if (yych <= 'Z') goto yy178; + if (yych <= '@') goto yy171; + if (yych <= 'Z') goto yy179; if (yych <= '[') goto yy182; goto yy167; } } else { if (yych <= 'q') { - if (yych == '_') goto yy178; - if (yych >= 'a') goto yy178; + if (yych == '_') goto yy179; + if (yych >= 'a') goto yy179; } else { if (yych <= 'z') { if (yych <= 'r') goto yy184; - goto yy178; + goto yy179; } else { if (yych <= '{') goto yy185; if (yych <= '|') goto yy167; @@ -946,7 +949,7 @@ yy160: fatalf("unexpected character: '%c'", *tok); goto scan; } -#line 950 "src/ast/lex.cc" +#line 953 "src/ast/lex.cc" yy161: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -958,7 +961,7 @@ yy161: { goto scan; } -#line 962 "src/ast/lex.cc" +#line 965 "src/ast/lex.cc" yy164: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -981,7 +984,7 @@ yy165: goto scan; } } -#line 985 "src/ast/lex.cc" +#line 988 "src/ast/lex.cc" yy166: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy164; @@ -991,99 +994,99 @@ yy167: yy168: #line 229 "../src/ast/lex.re" { return *tok; } -#line 995 "src/ast/lex.cc" +#line 998 "src/ast/lex.cc" yy169: ++YYCURSOR; #line 219 "../src/ast/lex.re" { yylval.regexp = lex_str('"'); return TOKEN_REGEXP; } -#line 1000 "src/ast/lex.cc" +#line 1003 "src/ast/lex.cc" yy171: yych = (YYCTYPE)*++YYCURSOR; - if (yych == '}') goto yy192; - goto yy160; + if (yych <= 'Z') { + if (yych <= '/') goto yy160; + if (yych <= '9') goto yy192; + if (yych <= '@') goto yy160; + goto yy192; + } else { + if (yych <= '_') { + if (yych <= '^') goto yy160; + goto yy192; + } else { + if (yych <= '`') goto yy160; + if (yych <= 'z') goto yy192; + goto yy160; + } + } yy172: + yych = (YYCTYPE)*++YYCURSOR; + if (yych == '}') goto yy195; + goto yy160; +yy173: ++YYCURSOR; #line 218 "../src/ast/lex.re" { yylval.regexp = lex_str('\''); return TOKEN_REGEXP; } -#line 1009 "src/ast/lex.cc" -yy174: +#line 1029 "src/ast/lex.cc" +yy175: yych = (YYCTYPE)*++YYCURSOR; - if (yych == '/') goto yy192; + if (yych == '/') goto yy195; goto yy168; -yy175: +yy176: ++YYCURSOR; #line 311 "../src/ast/lex.re" { yylval.regexp = ast_dot(cline, get_column()); return TOKEN_REGEXP; } -#line 1021 "src/ast/lex.cc" -yy177: +#line 1041 "src/ast/lex.cc" +yy178: yych = (YYCTYPE)*++YYCURSOR; - if (yych == '*') goto yy194; - if (yych == '/') goto yy196; + if (yych == '*') goto yy197; + if (yych == '/') goto yy199; goto yy168; -yy178: +yy179: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; -yy179: +yy180: if (yybm[0+yych] & 32) { - goto yy178; + goto yy179; } if (yych <= ' ') { if (yych == '\t') { YYCTXMARKER = YYCURSOR; - goto yy200; + goto yy203; } - if (yych <= 0x1F) goto yy198; + if (yych <= 0x1F) goto yy201; YYCTXMARKER = YYCURSOR; - goto yy200; + goto yy203; } else { if (yych <= ',') { - if (yych <= '+') goto yy198; + if (yych <= '+') goto yy201; YYCTXMARKER = YYCURSOR; - goto yy202; + goto yy205; } else { - if (yych <= '<') goto yy198; + if (yych <= '<') goto yy201; if (yych <= '>') { YYCTXMARKER = YYCURSOR; - goto yy202; + goto yy205; } - goto yy198; + goto yy201; } } -yy180: - yych = (YYCTYPE)*++YYCURSOR; - if (yych == '=') goto yy204; - goto yy160; yy181: yych = (YYCTYPE)*++YYCURSOR; - if (yych <= 'Z') { - if (yych <= '/') goto yy160; - if (yych <= '9') goto yy206; - if (yych <= '@') goto yy160; - goto yy206; - } else { - if (yych <= '_') { - if (yych <= '^') goto yy160; - goto yy206; - } else { - if (yych <= '`') goto yy160; - if (yych <= 'z') goto yy206; - goto yy160; - } - } + if (yych == '=') goto yy207; + goto yy160; yy182: yych = (YYCTYPE)*++YYCURSOR; if (yych == '^') goto yy209; #line 220 "../src/ast/lex.re" { yylval.regexp = lex_cls(false); return TOKEN_REGEXP; } -#line 1083 "src/ast/lex.cc" +#line 1086 "src/ast/lex.cc" yy184: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'e') goto yy211; - goto yy179; + goto yy180; yy185: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1108,7 +1111,7 @@ yy186: code_line = cline; goto code; } -#line 1112 "src/ast/lex.cc" +#line 1115 "src/ast/lex.cc" yy187: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1144,28 +1147,52 @@ yy190: } yy192: ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = (YYCTYPE)*YYCURSOR; + if (yych <= 'Z') { + if (yych <= '/') goto yy194; + if (yych <= '9') goto yy192; + if (yych >= 'A') goto yy192; + } else { + if (yych <= '_') { + if (yych >= '_') goto yy192; + } else { + if (yych <= '`') goto yy194; + if (yych <= 'z') goto yy192; + } + } +yy194: +#line 223 "../src/ast/lex.re" + { + const std::string *name = new std::string(tok + 1, tok_len() - 1); + yylval.regexp = ast_tag(cline, get_column(), name, tok[0] == '#'); + return TOKEN_REGEXP; + } +#line 1172 "src/ast/lex.cc" +yy195: + ++YYCURSOR; #line 213 "../src/ast/lex.re" { tok = cur; return 0; } -#line 1153 "src/ast/lex.cc" -yy194: +#line 1180 "src/ast/lex.cc" +yy197: ++YYCURSOR; #line 207 "../src/ast/lex.re" { depth = 1; goto comment; } -#line 1161 "src/ast/lex.cc" -yy196: +#line 1188 "src/ast/lex.cc" +yy199: ++YYCURSOR; #line 204 "../src/ast/lex.re" { goto nextLine; } -#line 1168 "src/ast/lex.cc" -yy198: +#line 1195 "src/ast/lex.cc" +yy201: ++YYCURSOR; YYCURSOR -= 1; #line 294 "../src/ast/lex.re" @@ -1185,15 +1212,15 @@ yy198: return TOKEN_REGEXP; } } -#line 1189 "src/ast/lex.cc" -yy200: +#line 1216 "src/ast/lex.cc" +yy203: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = (YYCTYPE)*YYCURSOR; if (yych <= ' ') { - if (yych == '\t') goto yy200; + if (yych == '\t') goto yy203; if (yych <= 0x1F) goto yy219; - goto yy200; + goto yy203; } else { if (yych <= ',') { if (yych <= '+') goto yy219; @@ -1202,7 +1229,7 @@ yy200: if (yych >= '?') goto yy219; } } -yy202: +yy205: ++YYCURSOR; YYCURSOR = YYCTXMARKER; #line 289 "../src/ast/lex.re" @@ -1210,8 +1237,8 @@ yy202: yylval.str = new std::string (tok, tok_len ()); return TOKEN_ID; } -#line 1214 "src/ast/lex.cc" -yy204: +#line 1241 "src/ast/lex.cc" +yy207: yych = (YYCTYPE)*++YYCURSOR; if (yych == '>') goto yy221; #line 197 "../src/ast/lex.re" @@ -1221,40 +1248,16 @@ yy204: code_line = cline; goto code; } -#line 1225 "src/ast/lex.cc" -yy206: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = (YYCTYPE)*YYCURSOR; - if (yych <= 'Z') { - if (yych <= '/') goto yy208; - if (yych <= '9') goto yy206; - if (yych >= 'A') goto yy206; - } else { - if (yych <= '_') { - if (yych >= '_') goto yy206; - } else { - if (yych <= '`') goto yy208; - if (yych <= 'z') goto yy206; - } - } -yy208: -#line 223 "../src/ast/lex.re" - { - const std::string *name = new std::string(tok + 1, tok_len() - 1); - yylval.regexp = ast_tag(cline, get_column(), name); - return TOKEN_REGEXP; - } -#line 1249 "src/ast/lex.cc" +#line 1252 "src/ast/lex.cc" yy209: ++YYCURSOR; #line 221 "../src/ast/lex.re" { yylval.regexp = lex_cls(true); return TOKEN_REGEXP; } -#line 1254 "src/ast/lex.cc" +#line 1257 "src/ast/lex.cc" yy211: yych = (YYCTYPE)*++YYCURSOR; if (yych == '2') goto yy223; - goto yy179; + goto yy180; yy212: ++YYCURSOR; yy213: @@ -1262,7 +1265,7 @@ yy213: { fatal("illegal closure form, use '{n}', '{n,}', '{n,m}' where n and m are numbers"); } -#line 1266 "src/ast/lex.cc" +#line 1269 "src/ast/lex.cc" yy214: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -1328,7 +1331,7 @@ yy219: return TOKEN_ID; } } -#line 1332 "src/ast/lex.cc" +#line 1335 "src/ast/lex.cc" yy221: ++YYCURSOR; YYCURSOR -= 2; @@ -1336,11 +1339,11 @@ yy221: { return *tok; } -#line 1340 "src/ast/lex.cc" +#line 1343 "src/ast/lex.cc" yy223: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'c') goto yy230; - goto yy179; + goto yy180; yy224: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1359,7 +1362,7 @@ yy225: yylval.bounds.max = yylval.bounds.min; return TOKEN_CLOSESIZE; } -#line 1363 "src/ast/lex.cc" +#line 1366 "src/ast/lex.cc" yy227: ++YYCURSOR; #line 266 "../src/ast/lex.re" @@ -1370,7 +1373,7 @@ yy227: yylval.str = new std::string (tok + 1, tok_len () - 2); // -2 to omit braces return TOKEN_ID; } -#line 1374 "src/ast/lex.cc" +#line 1377 "src/ast/lex.cc" yy229: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'n') goto yy235; @@ -1378,7 +1381,7 @@ yy229: yy230: yych = (YYCTYPE)*++YYCURSOR; if (yych == ':') goto yy236; - goto yy179; + goto yy180; yy231: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1398,7 +1401,7 @@ yy233: yylval.bounds.max = std::numeric_limits::max(); return TOKEN_CLOSESIZE; } -#line 1402 "src/ast/lex.cc" +#line 1405 "src/ast/lex.cc" yy235: yych = (YYCTYPE)*++YYCURSOR; if (yych == 'e') goto yy240; @@ -1407,7 +1410,7 @@ yy236: ++YYCURSOR; #line 274 "../src/ast/lex.re" { return TOKEN_CONF; } -#line 1411 "src/ast/lex.cc" +#line 1414 "src/ast/lex.cc" yy238: ++YYCURSOR; #line 240 "../src/ast/lex.re" @@ -1423,7 +1426,7 @@ yy238: } return TOKEN_CLOSESIZE; } -#line 1427 "src/ast/lex.cc" +#line 1430 "src/ast/lex.cc" yy240: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '0') goto yy242; @@ -1484,7 +1487,7 @@ yy247: set_sourceline (); return TOKEN_LINE_INFO; } -#line 1488 "src/ast/lex.cc" +#line 1491 "src/ast/lex.cc" yy249: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy247; @@ -1514,7 +1517,7 @@ yy253: code: -#line 1518 "src/ast/lex.cc" +#line 1521 "src/ast/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1587,7 +1590,7 @@ yy256: } goto code; } -#line 1591 "src/ast/lex.cc" +#line 1594 "src/ast/lex.cc" yy258: ++YYCURSOR; yy259: @@ -1595,7 +1598,7 @@ yy259: { goto code; } -#line 1599 "src/ast/lex.cc" +#line 1602 "src/ast/lex.cc" yy260: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1634,7 +1637,7 @@ yy261: cline++; goto code; } -#line 1638 "src/ast/lex.cc" +#line 1641 "src/ast/lex.cc" yy262: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1659,7 +1662,7 @@ yy264: } goto code; } -#line 1663 "src/ast/lex.cc" +#line 1666 "src/ast/lex.cc" yy266: ++YYCURSOR; #line 345 "../src/ast/lex.re" @@ -1675,7 +1678,7 @@ yy266: } goto code; } -#line 1679 "src/ast/lex.cc" +#line 1682 "src/ast/lex.cc" yy268: yyaccept = 2; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -1701,7 +1704,7 @@ yy269: cline++; goto code; } -#line 1705 "src/ast/lex.cc" +#line 1708 "src/ast/lex.cc" yy270: ++YYCURSOR; goto yy269; @@ -1740,7 +1743,7 @@ yy276: { goto code; } -#line 1744 "src/ast/lex.cc" +#line 1747 "src/ast/lex.cc" yy278: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -1835,7 +1838,7 @@ yy294: set_sourceline (); goto code; } -#line 1839 "src/ast/lex.cc" +#line 1842 "src/ast/lex.cc" yy296: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy294; @@ -1869,7 +1872,7 @@ yy300: comment: -#line 1873 "src/ast/lex.cc" +#line 1876 "src/ast/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -1924,7 +1927,7 @@ yy304: } goto comment; } -#line 1928 "src/ast/lex.cc" +#line 1931 "src/ast/lex.cc" yy305: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yybm[0+yych] & 32) { @@ -1942,7 +1945,7 @@ yy306: cline++; goto comment; } -#line 1946 "src/ast/lex.cc" +#line 1949 "src/ast/lex.cc" yy307: yych = (YYCTYPE)*++YYCURSOR; if (yych == '/') goto yy314; @@ -1987,7 +1990,7 @@ yy314: goto comment; } } -#line 1991 "src/ast/lex.cc" +#line 1994 "src/ast/lex.cc" yy316: ++YYCURSOR; #line 435 "../src/ast/lex.re" @@ -1996,7 +1999,7 @@ yy316: fatal("ambiguous /* found"); goto comment; } -#line 2000 "src/ast/lex.cc" +#line 2003 "src/ast/lex.cc" yy318: yych = (YYCTYPE)*++YYCURSOR; if (yych != 'i') goto yy311; @@ -2058,7 +2061,7 @@ yy328: set_sourceline (); goto comment; } -#line 2062 "src/ast/lex.cc" +#line 2065 "src/ast/lex.cc" yy330: yych = (YYCTYPE)*++YYCURSOR; if (yych == '\n') goto yy328; @@ -2088,7 +2091,7 @@ yy334: nextLine: -#line 2092 "src/ast/lex.cc" +#line 2095 "src/ast/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2101,7 +2104,7 @@ nextLine: } goto nextLine; } -#line 2105 "src/ast/lex.cc" +#line 2108 "src/ast/lex.cc" yy339: ++YYCURSOR; #line 464 "../src/ast/lex.re" @@ -2112,7 +2115,7 @@ yy339: cline++; goto scan; } -#line 2116 "src/ast/lex.cc" +#line 2119 "src/ast/lex.cc" } #line 476 "../src/ast/lex.re" @@ -2140,7 +2143,7 @@ fst: tok = cur; c = get_column(); -#line 2144 "src/ast/lex.cc" +#line 2147 "src/ast/lex.cc" { YYCTYPE yych; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2148,18 +2151,18 @@ fst: if (yych == ']') goto yy344; #line 502 "../src/ast/lex.re" { l = lex_cls_chr(); goto snd; } -#line 2152 "src/ast/lex.cc" +#line 2155 "src/ast/lex.cc" yy344: ++YYCURSOR; #line 501 "../src/ast/lex.re" { return ast_cls(cline, c0, cls, neg); } -#line 2157 "src/ast/lex.cc" +#line 2160 "src/ast/lex.cc" } #line 503 "../src/ast/lex.re" snd: -#line 2163 "src/ast/lex.cc" +#line 2166 "src/ast/lex.cc" { YYCTYPE yych; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); @@ -2168,7 +2171,7 @@ snd: yy348: #line 506 "../src/ast/lex.re" { u = l; goto add; } -#line 2172 "src/ast/lex.cc" +#line 2175 "src/ast/lex.cc" yy349: yych = (YYCTYPE)*++YYCURSOR; if (yych != ']') goto yy351; @@ -2186,7 +2189,7 @@ yy351: } goto add; } -#line 2190 "src/ast/lex.cc" +#line 2193 "src/ast/lex.cc" } #line 515 "../src/ast/lex.re" @@ -2199,7 +2202,7 @@ uint32_t Scanner::lex_cls_chr() { tok = cur; -#line 2203 "src/ast/lex.cc" +#line 2206 "src/ast/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2210,12 +2213,12 @@ uint32_t Scanner::lex_cls_chr() ++YYCURSOR; #line 530 "../src/ast/lex.re" { return static_cast(tok[0]); } -#line 2214 "src/ast/lex.cc" +#line 2217 "src/ast/lex.cc" yy357: ++YYCURSOR; #line 525 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error"); } -#line 2219 "src/ast/lex.cc" +#line 2222 "src/ast/lex.cc" yy359: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '`') { @@ -2266,7 +2269,7 @@ yy359: } #line 528 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in escape sequence"); } -#line 2270 "src/ast/lex.cc" +#line 2273 "src/ast/lex.cc" yy361: ++YYCURSOR; #line 543 "../src/ast/lex.re" @@ -2274,12 +2277,12 @@ yy361: warn.useless_escape(cline, get_column(), tok[1]); return static_cast(tok[1]); } -#line 2278 "src/ast/lex.cc" +#line 2281 "src/ast/lex.cc" yy363: ++YYCURSOR; #line 541 "../src/ast/lex.re" { return static_cast('-'); } -#line 2283 "src/ast/lex.cc" +#line 2286 "src/ast/lex.cc" yy365: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2288,7 +2291,7 @@ yy365: yy366: #line 527 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in octal escape sequence"); } -#line 2292 "src/ast/lex.cc" +#line 2295 "src/ast/lex.cc" yy367: ++YYCURSOR; goto yy366; @@ -2306,7 +2309,7 @@ yy368: yy369: #line 526 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2310 "src/ast/lex.cc" +#line 2313 "src/ast/lex.cc" yy370: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2324,47 +2327,47 @@ yy371: ++YYCURSOR; #line 540 "../src/ast/lex.re" { return static_cast('\\'); } -#line 2328 "src/ast/lex.cc" +#line 2331 "src/ast/lex.cc" yy373: ++YYCURSOR; #line 542 "../src/ast/lex.re" { return static_cast(']'); } -#line 2333 "src/ast/lex.cc" +#line 2336 "src/ast/lex.cc" yy375: ++YYCURSOR; #line 533 "../src/ast/lex.re" { return static_cast('\a'); } -#line 2338 "src/ast/lex.cc" +#line 2341 "src/ast/lex.cc" yy377: ++YYCURSOR; #line 534 "../src/ast/lex.re" { return static_cast('\b'); } -#line 2343 "src/ast/lex.cc" +#line 2346 "src/ast/lex.cc" yy379: ++YYCURSOR; #line 535 "../src/ast/lex.re" { return static_cast('\f'); } -#line 2348 "src/ast/lex.cc" +#line 2351 "src/ast/lex.cc" yy381: ++YYCURSOR; #line 536 "../src/ast/lex.re" { return static_cast('\n'); } -#line 2353 "src/ast/lex.cc" +#line 2356 "src/ast/lex.cc" yy383: ++YYCURSOR; #line 537 "../src/ast/lex.re" { return static_cast('\r'); } -#line 2358 "src/ast/lex.cc" +#line 2361 "src/ast/lex.cc" yy385: ++YYCURSOR; #line 538 "../src/ast/lex.re" { return static_cast('\t'); } -#line 2363 "src/ast/lex.cc" +#line 2366 "src/ast/lex.cc" yy387: ++YYCURSOR; #line 539 "../src/ast/lex.re" { return static_cast('\v'); } -#line 2368 "src/ast/lex.cc" +#line 2371 "src/ast/lex.cc" yy389: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2429,7 +2432,7 @@ yy395: ++YYCURSOR; #line 532 "../src/ast/lex.re" { return unesc_oct(tok, cur); } -#line 2433 "src/ast/lex.cc" +#line 2436 "src/ast/lex.cc" yy397: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2458,7 +2461,7 @@ yy399: ++YYCURSOR; #line 531 "../src/ast/lex.re" { return unesc_hex(tok, cur); } -#line 2462 "src/ast/lex.cc" +#line 2465 "src/ast/lex.cc" yy401: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2491,7 +2494,7 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = false; tok = cur; -#line 2495 "src/ast/lex.cc" +#line 2498 "src/ast/lex.cc" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -2505,12 +2508,12 @@ uint32_t Scanner::lex_str_chr(char quote, bool &end) end = tok[0] == quote; return static_cast(tok[0]); } -#line 2509 "src/ast/lex.cc" +#line 2512 "src/ast/lex.cc" yy407: ++YYCURSOR; #line 555 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error"); } -#line 2514 "src/ast/lex.cc" +#line 2517 "src/ast/lex.cc" yy409: yych = (YYCTYPE)*++YYCURSOR; if (yych <= 'a') { @@ -2558,7 +2561,7 @@ yy409: } #line 558 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in escape sequence"); } -#line 2562 "src/ast/lex.cc" +#line 2565 "src/ast/lex.cc" yy411: ++YYCURSOR; #line 574 "../src/ast/lex.re" @@ -2568,7 +2571,7 @@ yy411: } return static_cast(tok[1]); } -#line 2572 "src/ast/lex.cc" +#line 2575 "src/ast/lex.cc" yy413: yyaccept = 0; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2577,7 +2580,7 @@ yy413: yy414: #line 557 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in octal escape sequence"); } -#line 2581 "src/ast/lex.cc" +#line 2584 "src/ast/lex.cc" yy415: ++YYCURSOR; goto yy414; @@ -2595,7 +2598,7 @@ yy416: yy417: #line 556 "../src/ast/lex.re" { fatal (get_column() - tchar, "syntax error in hexadecimal escape sequence"); } -#line 2599 "src/ast/lex.cc" +#line 2602 "src/ast/lex.cc" yy418: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2613,42 +2616,42 @@ yy419: ++YYCURSOR; #line 573 "../src/ast/lex.re" { return static_cast('\\'); } -#line 2617 "src/ast/lex.cc" +#line 2620 "src/ast/lex.cc" yy421: ++YYCURSOR; #line 566 "../src/ast/lex.re" { return static_cast('\a'); } -#line 2622 "src/ast/lex.cc" +#line 2625 "src/ast/lex.cc" yy423: ++YYCURSOR; #line 567 "../src/ast/lex.re" { return static_cast('\b'); } -#line 2627 "src/ast/lex.cc" +#line 2630 "src/ast/lex.cc" yy425: ++YYCURSOR; #line 568 "../src/ast/lex.re" { return static_cast('\f'); } -#line 2632 "src/ast/lex.cc" +#line 2635 "src/ast/lex.cc" yy427: ++YYCURSOR; #line 569 "../src/ast/lex.re" { return static_cast('\n'); } -#line 2637 "src/ast/lex.cc" +#line 2640 "src/ast/lex.cc" yy429: ++YYCURSOR; #line 570 "../src/ast/lex.re" { return static_cast('\r'); } -#line 2642 "src/ast/lex.cc" +#line 2645 "src/ast/lex.cc" yy431: ++YYCURSOR; #line 571 "../src/ast/lex.re" { return static_cast('\t'); } -#line 2647 "src/ast/lex.cc" +#line 2650 "src/ast/lex.cc" yy433: ++YYCURSOR; #line 572 "../src/ast/lex.re" { return static_cast('\v'); } -#line 2652 "src/ast/lex.cc" +#line 2655 "src/ast/lex.cc" yy435: yyaccept = 1; yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); @@ -2713,7 +2716,7 @@ yy441: ++YYCURSOR; #line 565 "../src/ast/lex.re" { return unesc_oct(tok, cur); } -#line 2717 "src/ast/lex.cc" +#line 2720 "src/ast/lex.cc" yy443: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2742,7 +2745,7 @@ yy445: ++YYCURSOR; #line 564 "../src/ast/lex.re" { return unesc_hex(tok, cur); } -#line 2746 "src/ast/lex.cc" +#line 2749 "src/ast/lex.cc" yy447: yych = (YYCTYPE)*++YYCURSOR; if (yych <= '@') { @@ -2786,7 +2789,7 @@ void Scanner::set_sourceline () sourceline: tok = cur; -#line 2790 "src/ast/lex.cc" +#line 2793 "src/ast/lex.cc" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -2839,7 +2842,7 @@ yy452: { goto sourceline; } -#line 2843 "src/ast/lex.cc" +#line 2846 "src/ast/lex.cc" yy453: ++YYCURSOR; #line 610 "../src/ast/lex.re" @@ -2855,7 +2858,7 @@ yy453: tok = cur; return; } -#line 2859 "src/ast/lex.cc" +#line 2862 "src/ast/lex.cc" yy455: yych = (YYCTYPE)*(YYMARKER = ++YYCURSOR); if (yych == '\n') goto yy452; @@ -2875,7 +2878,7 @@ yy456: } goto sourceline; } -#line 2879 "src/ast/lex.cc" +#line 2882 "src/ast/lex.cc" yy459: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); @@ -2897,7 +2900,7 @@ yy462: escape (in.file_name, std::string (tok + 1, tok_len () - 2)); // -2 to omit quotes goto sourceline; } -#line 2901 "src/ast/lex.cc" +#line 2904 "src/ast/lex.cc" yy464: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); diff --git a/re2c/bootstrap/src/ast/parser.cc b/re2c/bootstrap/src/ast/parser.cc index e2e663ec..e0d431fe 100644 --- a/re2c/bootstrap/src/ast/parser.cc +++ b/re2c/bootstrap/src/ast/parser.cc @@ -1454,7 +1454,7 @@ yyreduce: { (yyval.regexp) = ast_cat(ast_cap((yyvsp[-2].regexp)), - ast_cat(ast_tag(context.input.get_cline(), 0, NULL), (yyvsp[0].regexp))); + ast_cat(ast_tag(context.input.get_cline(), 0, NULL, false), (yyvsp[0].regexp))); } break; diff --git a/re2c/src/ast/ast.cc b/re2c/src/ast/ast.cc index 9727d7aa..b8b5e0d8 100644 --- a/re2c/src/ast/ast.cc +++ b/re2c/src/ast/ast.cc @@ -19,7 +19,7 @@ AST::~AST() { flist.erase(this); if (type == TAG) { - delete tag; + delete tag.name; } else if (type == REF) { delete ref.name; } else if (type == STR) { @@ -97,10 +97,11 @@ const AST *ast_diff(const AST *a1, const AST *a2) return ast; } -const AST *ast_tag(uint32_t l, uint32_t c, const std::string *t) +const AST *ast_tag(uint32_t l, uint32_t c, const std::string *n, bool h) { AST *ast = new AST(l, c, AST::TAG); - ast->tag = t; + ast->tag.name = n; + ast->tag.history = h; return ast; } diff --git a/re2c/src/ast/ast.h b/re2c/src/ast/ast.h index 94e78098..56646dea 100644 --- a/re2c/src/ast/ast.h +++ b/re2c/src/ast/ast.h @@ -66,7 +66,10 @@ struct AST const AST *ast1; const AST *ast2; } diff; - const std::string *tag; + struct { + const std::string *name; + bool history; + } tag; const AST *cap; struct { const AST *ast; @@ -120,7 +123,7 @@ const AST *ast_alt(const AST *r1, const AST *r2); const AST *ast_cat(const AST *r1, const AST *r2); const AST *ast_iter(const AST *r, uint32_t n, uint32_t m); const AST *ast_diff(const AST *r1, const AST *r2); -const AST *ast_tag(uint32_t l, uint32_t c, const std::string *t); +const AST *ast_tag(uint32_t l, uint32_t c, const std::string *n, bool h); const AST *ast_cap(const AST *r); const AST *ast_ref(const AST *r, const std::string &n); bool ast_need_wrap(const AST *ast); diff --git a/re2c/src/ast/lex.re b/re2c/src/ast/lex.re index a028f628..43d2ea7c 100644 --- a/re2c/src/ast/lex.re +++ b/re2c/src/ast/lex.re @@ -220,9 +220,9 @@ scan: "[" { yylval.regexp = lex_cls(false); return TOKEN_REGEXP; } "[^" { yylval.regexp = lex_cls(true); return TOKEN_REGEXP; } - "@" name { + [@#] name { const std::string *name = new std::string(tok + 1, tok_len() - 1); - yylval.regexp = ast_tag(cline, get_column(), name); + yylval.regexp = ast_tag(cline, get_column(), name, tok[0] == '#'); return TOKEN_REGEXP; } diff --git a/re2c/src/ast/parser.ypp b/re2c/src/ast/parser.ypp index e4b1f919..b37da4a9 100644 --- a/re2c/src/ast/parser.ypp +++ b/re2c/src/ast/parser.ypp @@ -169,7 +169,7 @@ trailexpr $$ = ast_cap($1); } | expr '/' expr { $$ = ast_cat(ast_cap($1), - ast_cat(ast_tag(context.input.get_cline(), 0, NULL), $3)); + ast_cat(ast_tag(context.input.get_cline(), 0, NULL, false), $3)); }; expr: diff --git a/re2c/src/re/ast_to_re.cc b/re2c/src/re/ast_to_re.cc index 8484b6a8..298e6ec4 100644 --- a/re2c/src/re/ast_to_re.cc +++ b/re2c/src/re/ast_to_re.cc @@ -91,12 +91,12 @@ static RE *ast_to_re(RESpec &spec, const AST *ast, size_t &ncap) return re_cat(alc, x, y); } case AST::TAG: { - if (ast->tag && !opts->tags) { + if (ast->tag.name && !opts->tags) { fatal_error(ast->line, ast->column, "tags are only allowed with '-T, --tags' option"); } RE *t = re_tag(alc, tags.size(), false); - tags.push_back(Tag(ast->tag)); + tags.push_back(Tag(ast->tag.name, ast->tag.history)); return t; } case AST::CAP: { diff --git a/re2c/src/re/tag.h b/re2c/src/re/tag.h index a1d59958..ed49faba 100644 --- a/re2c/src/re/tag.h +++ b/re2c/src/re/tag.h @@ -25,18 +25,21 @@ struct Tag size_t ncap; size_t base; size_t dist; + bool history; - explicit Tag(const std::string *n) + Tag(const std::string *n, bool h) : name(n) , ncap(Tag::RIGHTMOST) , base(Tag::RIGHTMOST) , dist(Tag::VARDIST) + , history(h) {} explicit Tag(size_t c) : name(NULL) , ncap(c) , base(Tag::RIGHTMOST) , dist(Tag::VARDIST) + , history(false) {} }; @@ -68,9 +71,9 @@ inline bool preorbit(const std::vector &tags, size_t idx) && tags[idx + 2].ncap == ncap + 2; } -inline bool history(const Tag &/*tag*/) +inline bool history(const Tag &tag) { - return false; + return tag.history; } } // namespace re2c -- 2.40.0