From: Ulya Trofimovich Date: Wed, 28 Aug 2019 21:43:03 +0000 (+0100) Subject: Respect 're2c:define:YYFILL:naked' and 're2c:yyfill:parameter' configurations with... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=257b3184396addfe51d4227d4c005646f6953349;p=re2c Respect 're2c:define:YYFILL:naked' and 're2c:yyfill:parameter' configurations with EOF rule. Thanks to Nazim Can Bedir for the bug report. --- diff --git a/src/codegen/emit_action.cc b/src/codegen/emit_action.cc index 07bb2fb0..b31b7e67 100644 --- a/src/codegen/emit_action.cc +++ b/src/codegen/emit_action.cc @@ -382,7 +382,8 @@ void gen_on_eof(code_lines_t &code, const opt_t *opts, const DFA &dfa } flushln(code, o); - o << opts->indString << opts->fill << "();"; + o << opts->indString << opts->fill + << (opts->fill_naked ? "" : opts->fill_arg_use ? "();" : ";"); flushln(code, o); o << opts->indString << opts->labelPrefix << "eof" << fillidx << ":;"; @@ -392,8 +393,10 @@ void gen_on_eof(code_lines_t &code, const opt_t *opts, const DFA &dfa } else { if (opts->fill_use) { - o << opts->indString << "if (" << opts->fill << " () == 0) " - << "goto " << opts->labelPrefix << retry->label << "_;"; + o << opts->indString << "if (" << opts->fill + << (opts->fill_naked ? "" + : opts->fill_arg_use ? " () == 0" : " == 0") + << ") goto " << opts->labelPrefix << retry->label << "_;"; flushln(code, o); } gen_on_eof_fail(code, opts, dfa, from, to, o); diff --git a/test/eof/eof_yyfill_naked_1.i.c b/test/eof/eof_yyfill_naked_1.i.c new file mode 100644 index 00000000..7f3a91c6 --- /dev/null +++ b/test/eof/eof_yyfill_naked_1.i.c @@ -0,0 +1,106 @@ +/* Generated by re2c */ + + + +{ + YYCTYPE yych; +yy1_: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: + if (YYLIMIT <= YYCURSOR) { + if (fill() == 0) goto yy1_; + goto yyeof; + } + goto yy2; + } +yy2: + ++YYCURSOR; +yy3: + { return FAIL; } +yy4: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } +} + + + +{ + YYCTYPE yych; +yy7_: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy10; + default: + if (YYLIMIT <= YYCURSOR) { + if (fill() == 0) goto yy7_; + goto yyeof; + } + goto yy8; + } +yy8: + ++YYCURSOR; +yy9: + { return FAIL; } +yy10: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } +} + + + +{ + YYCTYPE yych; +yy13_: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy16; + default: + if (YYLIMIT <= YYCURSOR) { + if (fill () == 0) goto yy13_; + goto yyeof; + } + goto yy14; + } +yy14: + ++YYCURSOR; +yy15: + { return FAIL; } +yy16: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } +} + + + +{ + YYCTYPE yych; +yy19_: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy22; + default: + if (YYLIMIT <= YYCURSOR) { + if (fill() == 0) goto yy19_; + goto yyeof; + } + goto yy20; + } +yy20: + ++YYCURSOR; +yy21: + { return FAIL; } +yy22: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } +} + diff --git a/test/eof/eof_yyfill_naked_1.i.re b/test/eof/eof_yyfill_naked_1.i.re new file mode 100644 index 00000000..eaf9cde9 --- /dev/null +++ b/test/eof/eof_yyfill_naked_1.i.re @@ -0,0 +1,39 @@ +/*!re2c + re2c:eof = 0; +*/ + +/*!re2c + re2c:define:YYFILL = "fill() == 0"; + re2c:define:YYFILL:naked = 1; + re2c:yyfill:parameter = 1; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill() == 0"; + re2c:define:YYFILL:naked = 1; + re2c:yyfill:parameter = 0; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill"; + re2c:define:YYFILL:naked = 0; + re2c:yyfill:parameter = 1; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill()"; + re2c:define:YYFILL:naked = 0; + re2c:yyfill:parameter = 0; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ diff --git a/test/eof/eof_yyfill_naked_2.if.c b/test/eof/eof_yyfill_naked_2.if.c new file mode 100644 index 00000000..5f4bef75 --- /dev/null +++ b/test/eof/eof_yyfill_naked_2.if.c @@ -0,0 +1,114 @@ +/* Generated by re2c */ + + + + + switch (YYGETSTATE()) { + default: goto yy0; + case 0: if (YYLIMIT <= YYCURSOR) goto yyeof0; goto yyFillLabel0; + case 1: if (YYLIMIT <= YYCURSOR) goto yyeof1; goto yyFillLabel1; + case 2: if (YYLIMIT <= YYCURSOR) goto yyeof2; goto yyFillLabel2; + case 3: if (YYLIMIT <= YYCURSOR) goto yyeof3; goto yyFillLabel3; + } +yy0: +yyFillLabel0: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: + if (YYLIMIT <= YYCURSOR) { + YYSETSTATE(0); + fill(); + yyeof0:; + goto yyeof; + } + goto yy2; + } +yy2: + ++YYCURSOR; +yy3: + { return FAIL; } +yy4: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } + + + + +yyFillLabel1: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy10; + default: + if (YYLIMIT <= YYCURSOR) { + YYSETSTATE(1); + fill(); + yyeof1:; + goto yyeof; + } + goto yy8; + } +yy8: + ++YYCURSOR; +yy9: + { return FAIL; } +yy10: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } + + + + +yyFillLabel2: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy16; + default: + if (YYLIMIT <= YYCURSOR) { + YYSETSTATE(2); + fill(); + yyeof2:; + goto yyeof; + } + goto yy14; + } +yy14: + ++YYCURSOR; +yy15: + { return FAIL; } +yy16: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } + + + + +yyFillLabel3: + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy22; + default: + if (YYLIMIT <= YYCURSOR) { + YYSETSTATE(3); + fill(); + yyeof3:; + goto yyeof; + } + goto yy20; + } +yy20: + ++YYCURSOR; +yy21: + { return FAIL; } +yy22: + ++YYCURSOR; + { return OK; } +yyeof: + { return EOF; } + diff --git a/test/eof/eof_yyfill_naked_2.if.re b/test/eof/eof_yyfill_naked_2.if.re new file mode 100644 index 00000000..7e2a59d6 --- /dev/null +++ b/test/eof/eof_yyfill_naked_2.if.re @@ -0,0 +1,39 @@ +/*!re2c + re2c:eof = 0; +*/ + +/*!re2c + re2c:define:YYFILL = "fill();"; + re2c:define:YYFILL:naked = 1; + re2c:yyfill:parameter = 1; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill();"; + re2c:define:YYFILL:naked = 1; + re2c:yyfill:parameter = 0; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill"; + re2c:define:YYFILL:naked = 0; + re2c:yyfill:parameter = 1; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ + +/*!re2c + re2c:define:YYFILL = "fill()"; + re2c:define:YYFILL:naked = 0; + re2c:yyfill:parameter = 0; + * { return FAIL; } + $ { return EOF; } + [a] { return OK; } +*/ diff --git a/test/eof/utf8_any.i.re b/test/eof/utf8_any.i.re index 30c45fb7..192587e1 100644 --- a/test/eof/utf8_any.i.re +++ b/test/eof/utf8_any.i.re @@ -104,6 +104,7 @@ static Result lex1_simple(uint8_t *cur, uint8_t* end, uint8_t* /* unused */) uint8_t *YYMARKER, *tok = cur; /*!re2c re2c:yyfill:enable = 1; + re2c:define:YYFILL:naked = 0; re2c:define:YYFILL = fill; re2c:eof = 0;