diff --git a/bootstrap/doc/re2c.1 b/bootstrap/doc/re2c.1 index 4d83b2694..1ccf3e133 100644 --- a/bootstrap/doc/re2c.1 +++ b/bootstrap/doc/re2c.1 @@ -60,7 +60,7 @@ bool lex(const char *s) { const char *YYCURSOR = s; /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; [1\-9][0\-9]* { return true; } * { return false; } @@ -2383,7 +2383,7 @@ static int lex(const char *YYCURSOR) { for (;;) { /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; * { return \-1; } @@ -2439,7 +2439,7 @@ static int lex(const char *str, unsigned int len) { for (;;) { /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; re2c:eof = 0; @@ -2511,8 +2511,8 @@ static int lex(const char *str, unsigned int len) { loop: /*!re2c re2c:api:style = free\-form; - re2c:YYCTYPE = char; - re2c:YYFILL = \(dqgoto fail;\(dq; + re2c:define:YYCTYPE = char; + re2c:define:YYFILL = \(dqgoto fail;\(dq; str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq]; @@ -2577,11 +2577,11 @@ static int lex(const char *str, unsigned int len) { for (;;) { /*!re2c re2c:yyfill:enable = 0; - re2c:api = generic; + re2c:api = custom; re2c:api:style = free\-form; - re2c:YYCTYPE = char; - re2c:YYPEEK = \(dqcur < lim ? *cur : 0\(dq; // fake null - re2c:YYSKIP = \(dq++cur;\(dq; + re2c:define:YYCTYPE = char; + re2c:define:YYPEEK = \(dqcur < lim ? *cur : 0\(dq; // fake null + re2c:define:YYSKIP = \(dq++cur;\(dq; * { count = \-1; break; } [\ex00] { break;; } @@ -2703,45 +2703,44 @@ Here is an example of a program that reads input file \fBinput.txt\fP in chunks struct Input { FILE *file; - char buffer[BUFSIZE + 1]; // +1 for sentinel - char *yylimit; - char *yycursor; - char *yymarker; - char *token; + char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; // +1 for sentinel bool eof; }; static int fill(Input &in) { if (in.eof) return 1; - const size_t shift = in.token \- in.buffer; - const size_t used = in.yylimit \- in.token; + const size_t shift = in.tok \- in.buf; + const size_t used = in.lim \- in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < 1) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit \-= shift; - in.yycursor \-= shift; - in.yymarker \-= shift; - in.token \-= shift; + memmove(in.buf, in.tok, used); + in.lim \-= shift; + in.cur \-= shift; + in.mar \-= shift; + in.tok \-= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE \- used, in.file); - in.yylimit[0] = 0; - in.eof = in.yylimit < in.buffer + BUFSIZE; + in.lim += fread(in.lim, 1, BUFSIZE \- used, in.file); + in.lim[0] = 0; + in.eof = in.lim < in.buf + BUFSIZE; return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord\->token = yyrecord\->yycursor; + in.tok = in.cur; /*!re2c - re2c:api = record; - re2c:YYCTYPE = char; - re2c:YYFILL = \(dqfill(*yyrecord) == 0\(dq; + re2c:api:style = free\-form; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = \(dqfill(in) == 0\(dq; re2c:eof = 0; str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq]; @@ -2769,13 +2768,13 @@ int main() { // Initialize lexer state: all pointers are at the end of buffer. Input in; in.file = fopen(fname, \(dqr\(dq); - in.yycursor = in.yymarker = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.mar = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Sentinel (at YYLIMIT pointer) is set to zero, which triggers YYFILL. - in.yylimit[0] = 0; + in.lim[0] = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); @@ -2845,56 +2844,55 @@ Here is an example of a program that reads input file \fBinput.txt\fP in chunks struct Input { FILE *file; - char buffer[BUFSIZE + YYMAXFILL]; - char *yylimit; - char *yycursor; - char *token; + char buf[BUFSIZE + YYMAXFILL], *lim, *cur, *tok; bool eof; }; static int fill(Input &in, size_t need) { if (in.eof) return 1; - const size_t shift = in.token \- in.buffer; - const size_t used = in.yylimit \- in.token; + const size_t shift = in.tok \- in.buf; + const size_t used = in.lim \- in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < need) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit \-= shift; - in.yycursor \-= shift; - in.token \-= shift; + memmove(in.buf, in.tok, used); + in.lim \-= shift; + in.cur \-= shift; + in.tok \-= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE \- used, in.file); + in.lim += fread(in.lim, 1, BUFSIZE \- used, in.file); // If read less than expected, this is end of input => add zero padding // so that the lexer can access characters at the end of buffer. - if (in.yylimit < in.buffer + BUFSIZE) { + if (in.lim < in.buf + BUFSIZE) { in.eof = true; - memset(in.yylimit, 0, YYMAXFILL); - in.yylimit += YYMAXFILL; + memset(in.lim, 0, YYMAXFILL); + in.lim += YYMAXFILL; } return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord\->token = yyrecord\->yycursor; + in.tok = in.cur; /*!re2c - re2c:api = record; - re2c:YYCTYPE = char; - re2c:YYFILL = \(dqif (fill(*yyrecord, @@) != 0) return \-1;\(dq; + re2c:api:style = free\-form; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = \(dqif (fill(in, @@) != 0) return \-1;\(dq; str = [\(aq] ([^\(aq\e\e] | [\e\e][^])* [\(aq]; [\ex00] { // Check that it is the sentinel, not some unexpected null. - return yyrecord\->token == yyrecord\->yylimit \- YYMAXFILL ? count : \-1; + return in.tok == in.lim \- YYMAXFILL ? count : \-1; } str { ++count; goto loop; } [ ]+ { goto loop; } @@ -2916,14 +2914,14 @@ int main() { int count = 3 * BUFSIZE; // number of quoted strings written to file // Initialize lexer state: all pointers are at the end of buffer. - // This immediately triggers YYFILL, as the check \(gain.yycursor < in.yylimit\(ga fails. + // This immediately triggers YYFILL, as the check \(gain.cur < in.lim\(ga fails. Input in; in.file = fopen(fname, \(dqr\(dq); - in.yycursor = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); @@ -2979,7 +2977,7 @@ static uint64_t parse_u32(const char *s) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; end = \(dq\ex00\(dq; @@ -3140,9 +3138,9 @@ static uint64_t parse_u32(const char *s) { /*!re2c re2c:api:style = free\-form; - re2c:YYCTYPE = char; - re2c:YYGETCOND = \(dqc\(dq; - re2c:YYSETCOND = \(dqc = @@;\(dq; + re2c:define:YYCTYPE = char; + re2c:define:YYGETCONDITION = \(dqc\(dq; + re2c:define:YYSETCONDITION = \(dqc = @@;\(dq; re2c:yyfill:enable = 0; <*> * { return ERROR; } @@ -3279,13 +3277,13 @@ static Status lex(State &st, unsigned int *recv) { st.tok = st.cur; /*!re2c re2c:api:style = free\-form; - re2c:YYCTYPE = \(dqchar\(dq; - re2c:YYCURSOR = \(dqst.cur\(dq; - re2c:YYMARKER = \(dqst.mar\(dq; - re2c:YYLIMIT = \(dqst.lim\(dq; - re2c:YYGETSTATE = \(dqst.state\(dq; - re2c:YYSETSTATE = \(dqst.state = @@;\(dq; - re2c:YYFILL = \(dqreturn WAITING;\(dq; + re2c:define:YYCTYPE = \(dqchar\(dq; + re2c:define:YYCURSOR = \(dqst.cur\(dq; + re2c:define:YYMARKER = \(dqst.mar\(dq; + re2c:define:YYLIMIT = \(dqst.lim\(dq; + re2c:define:YYGETSTATE = \(dqst.state\(dq; + re2c:define:YYSETSTATE = \(dqst.state = @@;\(dq; + re2c:define:YYFILL = \(dqreturn WAITING;\(dq; re2c:eof = 0; packet = [a\-z]+[;]; @@ -3298,7 +3296,7 @@ static Status lex(State &st, unsigned int *recv) { } void test(const char **packets, Status expect) { - // Create a pipe (open the same file for reading and writing). + // Create a \(dqsocket\(dq (open the same file for reading and writing). const char *fname = \(dqpipe\(dq; FILE *fw = fopen(fname, \(dqw\(dq); FILE *fr = fopen(fname, \(dqr\(dq); @@ -3434,7 +3432,7 @@ static What lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; !use:fish; !use:colors; @@ -3475,7 +3473,7 @@ int main() { static int lex_utf8(const uint8_t *s) { const uint8_t *YYCURSOR = s, *YYMARKER; /*!use:re2c - re2c:YYCTYPE = uint8_t; + re2c:define:YYCTYPE = uint8_t; re2c:encoding:utf8 = 1; */ } @@ -3483,7 +3481,7 @@ static int lex_utf8(const uint8_t *s) { static int lex_utf32(const uint32_t *s) { const uint32_t *YYCURSOR = s, *YYMARKER; /*!use:re2c - re2c:YYCTYPE = uint32_t; + re2c:define:YYCTYPE = uint32_t; re2c:encoding:utf32 = 1; */ } @@ -3620,15 +3618,15 @@ static int s2n(const char *s, const char *e) { // pre\-parsed string to number static bool lex(const char *str, SemVer &ver) { const char *YYCURSOR = str, *YYMARKER; - // Final tag variables available in semantic action. - /*!svars:re2c format = \(dqconst char *@@;\en\(dq; */ + // User\-defined tag variables that are available in semantic action. + const char *t1, *t2, *t3, *t4, *t5; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. /*!stags:re2c format = \(aqconst char *@@;\en\(aq; */ /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:tags = 1; num = [0\-9]+; @@ -3680,7 +3678,7 @@ rather than the buffer, which may be the case with m\-tags. struct Input { FILE *file; char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; - // Intermediate tag variables must be part of the lexer state passed to YYFILL. + // Tag variables must be part of the lexer state passed to YYFILL. // They don\(aqt correspond to tags and should be autogenerated by re2c. /*!stags:re2c format = \(aqconst char *@@;\(aq; */ bool eof; @@ -3726,19 +3724,20 @@ static int fill(Input &in) { } static bool lex(Input &in, std::vector &vers) { - // Final tag variables available in semantic action. - /*!svars:re2c format = \(aqconst char *@@;\en\(aq; */ - + // User\-defined local variables that store final tag values. + // They are different from tag variables autogenerated with \(gastags:re2c\(ga, + // as they are set at the end of match and used only in semantic actions. + const char *t1, *t2, *t3, *t4; for (;;) { in.tok = in.cur; /*!re2c re2c:eof = 0; re2c:api:style = free\-form; - re2c:YYCTYPE = char; - re2c:YYCURSOR = in.cur; - re2c:YYMARKER = in.mar; - re2c:YYLIMIT = in.lim; - re2c:YYFILL = \(dqfill(in) == 0\(dq; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = \(dqfill(in) == 0\(dq; re2c:tags:expression = \(dqin.@@\(dq; num = [0\-9]+; @@ -3821,7 +3820,7 @@ static bool lex(const char *str, SemVer &ver) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:captvars = 1; num = [0\-9]+; @@ -3914,21 +3913,21 @@ static bool parse(const char *str, Ver &ver) { const char *YYCURSOR = str, *YYMARKER; MtagTrie mt; - // Final tag variables available in semantic action. - /*!svars:re2c format = \(aqconst char *@@;\(aq; */ - /*!mvars:re2c format = \(aqint @@;\(aq; */ + // User\-defined tag variables that are available in semantic action. + const char *t1, *t2; + int t3, t4; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. /*!stags:re2c format = \(aqconst char *@@ = NULL;\(aq; */ /*!mtags:re2c format = \(aqint @@ = MTAG_ROOT;\(aq; */ /*!re2c re2c:api:style = free\-form; - re2c:YYCTYPE = char; - re2c:YYSTAGP = \(dq@@ = YYCURSOR;\(dq; - re2c:YYSTAGN = \(dq@@ = NULL;\(dq; - re2c:YYMTAGP = \(dqadd_mtag(mt, @@, YYCURSOR);\(dq; - re2c:YYMTAGN = \(dqadd_mtag(mt, @@, NULL);\(dq; + re2c:define:YYCTYPE = char; + re2c:define:YYSTAGP = \(dq@@ = YYCURSOR;\(dq; + re2c:define:YYSTAGN = \(dq@@ = NULL;\(dq; + re2c:define:YYMTAGP = \(dqadd_mtag(mt, @@, YYCURSOR);\(dq; + re2c:define:YYMTAGN = \(dqadd_mtag(mt, @@, NULL);\(dq; re2c:yyfill:enable = 0; re2c:tags = 1; @@ -4025,7 +4024,7 @@ Below is an example of a lexer for UTF8 encoded Unicode identifiers. static int lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c - re2c:YYCTYPE = \(aqunsigned char\(aq; + re2c:define:YYCTYPE = \(aqunsigned char\(aq; re2c:yyfill:enable = 0; // Simplified \(dqUnicode Identifier and Pattern Syntax\(dq @@ -4109,7 +4108,7 @@ float { return OK; } Result lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; * { return FAIL; } @@ -4157,28 +4156,29 @@ grammar and is unknown to the programmer). /*!header:re2c:on*/ struct LexerState { - const char *str, *yycursor; + const char *str, *cur; /*!stags:re2c format = \(dqconst char *@@;\(dq; */ }; /*!header:re2c:off*/ -long lex(LexerState* yyrecord) { +long lex(LexerState& st) { const char *t; /*!re2c re2c:header = \(dqlexer/state.h\(dq; - re2c:api = record; re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = \(dqst.cur\(dq; re2c:tags = 1; + re2c:tags:expression = \(dqst.@@\(dq; - [a]* @t [b]* { return t \- yyrecord\->str; } + [a]* @t [b]* { return t \- st.str; } */ } int main() { const char *s = \(dqab\(dq; LexerState st = { s, s /*!stags:re2c format = \(dq, NULL\(dq; */ }; - assert(lex(&st) == 1); + assert(lex(st) == 1); return 0; } @@ -4196,7 +4196,7 @@ int main() { typedef struct { - const char *str, *yycursor; + const char *str, *cur; const char *yyt1; } LexerState; diff --git a/examples/c/01_basic.re b/examples/c/01_basic.re index f0e57e122..9dbdea0d8 100644 --- a/examples/c/01_basic.re +++ b/examples/c/01_basic.re @@ -5,7 +5,7 @@ bool lex(const char *s) { const char *YYCURSOR = s; /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; [1-9][0-9]* { return true; } * { return false; } diff --git a/examples/c/conditions/parse_u32_blocks.re b/examples/c/conditions/parse_u32_blocks.re index 5f392f960..0ae940dcd 100644 --- a/examples/c/conditions/parse_u32_blocks.re +++ b/examples/c/conditions/parse_u32_blocks.re @@ -16,7 +16,7 @@ static uint64_t parse_u32(const char *s) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; end = "\x00"; diff --git a/examples/c/conditions/parse_u32_conditions.re b/examples/c/conditions/parse_u32_conditions.re index 7ce7690d9..8fcaaf6de 100644 --- a/examples/c/conditions/parse_u32_conditions.re +++ b/examples/c/conditions/parse_u32_conditions.re @@ -18,9 +18,9 @@ static uint64_t parse_u32(const char *s) { /*!re2c re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYGETCOND = "c"; - re2c:YYSETCOND = "c = @@;"; + re2c:define:YYCTYPE = char; + re2c:define:YYGETCONDITION = "c"; + re2c:define:YYSETCONDITION = "c = @@;"; re2c:yyfill:enable = 0; <*> * { return ERROR; } diff --git a/examples/c/encodings/unicode_identifier.re b/examples/c/encodings/unicode_identifier.re index b5ec78f8a..6a612d68a 100644 --- a/examples/c/encodings/unicode_identifier.re +++ b/examples/c/encodings/unicode_identifier.re @@ -7,7 +7,7 @@ static int lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c - re2c:YYCTYPE = 'unsigned char'; + re2c:define:YYCTYPE = 'unsigned char'; re2c:yyfill:enable = 0; // Simplified "Unicode Identifier and Pattern Syntax" diff --git a/examples/c/eof/01_sentinel.re b/examples/c/eof/01_sentinel.re index 0b554813f..ed7f99a83 100644 --- a/examples/c/eof/01_sentinel.re +++ b/examples/c/eof/01_sentinel.re @@ -7,7 +7,7 @@ static int lex(const char *YYCURSOR) { for (;;) { /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; * { return -1; } diff --git a/examples/c/eof/02_bounds_checking.re b/examples/c/eof/02_bounds_checking.re index 2f0bf2847..8a7b56498 100644 --- a/examples/c/eof/02_bounds_checking.re +++ b/examples/c/eof/02_bounds_checking.re @@ -17,8 +17,8 @@ static int lex(const char *str, unsigned int len) { loop: /*!re2c re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYFILL = "goto fail;"; + re2c:define:YYCTYPE = char; + re2c:define:YYFILL = "goto fail;"; str = ['] ([^'\\] | [\\][^])* [']; diff --git a/examples/c/eof/03_eof_rule.re b/examples/c/eof/03_eof_rule.re index 2e250c82c..c44b335e0 100644 --- a/examples/c/eof/03_eof_rule.re +++ b/examples/c/eof/03_eof_rule.re @@ -8,7 +8,7 @@ static int lex(const char *str, unsigned int len) { for (;;) { /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; re2c:eof = 0; diff --git a/examples/c/eof/04_fake_sentinel.re b/examples/c/eof/04_fake_sentinel.re index f3cd5367d..9bf05e177 100644 --- a/examples/c/eof/04_fake_sentinel.re +++ b/examples/c/eof/04_fake_sentinel.re @@ -14,11 +14,11 @@ static int lex(const char *str, unsigned int len) { for (;;) { /*!re2c re2c:yyfill:enable = 0; - re2c:api = generic; + re2c:api = custom; re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYPEEK = "cur < lim ? *cur : 0"; // fake null - re2c:YYSKIP = "++cur;"; + re2c:define:YYCTYPE = char; + re2c:define:YYPEEK = "cur < lim ? *cur : 0"; // fake null + re2c:define:YYSKIP = "++cur;"; * { count = -1; break; } [\x00] { break;; } diff --git a/examples/c/eof/05_fake_sentinel_eof_rule.re b/examples/c/eof/05_fake_sentinel_eof_rule.re index 483089e18..7f1709a2b 100644 --- a/examples/c/eof/05_fake_sentinel_eof_rule.re +++ b/examples/c/eof/05_fake_sentinel_eof_rule.re @@ -15,14 +15,14 @@ static int lex(const char *str, unsigned int len) { /*!re2c re2c:yyfill:enable = 0; re2c:eof = 0; - re2c:api = generic; + re2c:api = custom; re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYLESSTHAN = "cur >= lim"; - re2c:YYPEEK = "cur < lim ? *cur : 0"; // fake null - re2c:YYSKIP = "++cur;"; - re2c:YYBACKUP = "mar = cur;"; - re2c:YYRESTORE = "cur = mar;"; + re2c:define:YYCTYPE = char; + re2c:define:YYLESSTHAN = "cur >= lim"; + re2c:define:YYPEEK = "cur < lim ? *cur : 0"; // fake null + re2c:define:YYSKIP = "++cur;"; + re2c:define:YYBACKUP = "mar = cur;"; + re2c:define:YYRESTORE = "cur = mar;"; str = ['] ([^'\\] | [\\][^])* [']; diff --git a/examples/c/fill/01_fill.c b/examples/c/fill/01_fill.c index 8def7a7d4..0d9906f84 100644 --- a/examples/c/fill/01_fill.c +++ b/examples/c/fill/01_fill.c @@ -9,130 +9,125 @@ struct Input { FILE *file; - char buffer[BUFSIZE + 1]; // +1 for sentinel - char *yylimit; - char *yycursor; - char *yymarker; - char *token; + char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; // +1 for sentinel bool eof; }; static int fill(Input &in) { if (in.eof) return 1; - const size_t shift = in.token - in.buffer; - const size_t used = in.yylimit - in.token; + const size_t shift = in.tok - in.buf; + const size_t used = in.lim - in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < 1) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit -= shift; - in.yycursor -= shift; - in.yymarker -= shift; - in.token -= shift; + memmove(in.buf, in.tok, used); + in.lim -= shift; + in.cur -= shift; + in.mar -= shift; + in.tok -= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE - used, in.file); - in.yylimit[0] = 0; - in.eof = in.yylimit < in.buffer + BUFSIZE; + in.lim += fread(in.lim, 1, BUFSIZE - used, in.file); + in.lim[0] = 0; + in.eof = in.lim < in.buf + BUFSIZE; return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord->token = yyrecord->yycursor; + in.tok = in.cur; -#line 49 "c/fill/01_fill.c" +#line 45 "c/fill/01_fill.c" { char yych; yyFillLabel0: - yych = *yyrecord->yycursor; + yych = *in.cur; switch (yych) { case ' ': goto yy3; case '\'': goto yy5; default: - if (yyrecord->yylimit <= yyrecord->yycursor) { - if (fill(*yyrecord) == 0) goto yyFillLabel0; + if (in.lim <= in.cur) { + if (fill(in) == 0) goto yyFillLabel0; goto yy10; } goto yy1; } yy1: - ++yyrecord->yycursor; + ++in.cur; yy2: -#line 53 "c/fill/01_fill.re" +#line 52 "c/fill/01_fill.re" { return -1; } -#line 69 "c/fill/01_fill.c" +#line 65 "c/fill/01_fill.c" yy3: - ++yyrecord->yycursor; + ++in.cur; yyFillLabel1: - yych = *yyrecord->yycursor; + yych = *in.cur; switch (yych) { case ' ': goto yy3; default: - if (yyrecord->yylimit <= yyrecord->yycursor) { - if (fill(*yyrecord) == 0) goto yyFillLabel1; + if (in.lim <= in.cur) { + if (fill(in) == 0) goto yyFillLabel1; } goto yy4; } yy4: -#line 56 "c/fill/01_fill.re" +#line 55 "c/fill/01_fill.re" { goto loop; } -#line 85 "c/fill/01_fill.c" +#line 81 "c/fill/01_fill.c" yy5: - ++yyrecord->yycursor; - yyrecord->yymarker = yyrecord->yycursor; + in.mar = ++in.cur; yyFillLabel2: - yych = *yyrecord->yycursor; + yych = *in.cur; if (yych >= 0x01) goto yy7; - if (yyrecord->yylimit <= yyrecord->yycursor) { - if (fill(*yyrecord) == 0) goto yyFillLabel2; + if (in.lim <= in.cur) { + if (fill(in) == 0) goto yyFillLabel2; goto yy2; } yy6: - ++yyrecord->yycursor; + ++in.cur; yyFillLabel3: - yych = *yyrecord->yycursor; + yych = *in.cur; yy7: switch (yych) { case '\'': goto yy8; case '\\': goto yy9; default: - if (yyrecord->yylimit <= yyrecord->yycursor) { - if (fill(*yyrecord) == 0) goto yyFillLabel3; + if (in.lim <= in.cur) { + if (fill(in) == 0) goto yyFillLabel3; goto yy11; } goto yy6; } yy8: - ++yyrecord->yycursor; -#line 55 "c/fill/01_fill.re" + ++in.cur; +#line 54 "c/fill/01_fill.re" { ++count; goto loop; } -#line 115 "c/fill/01_fill.c" +#line 110 "c/fill/01_fill.c" yy9: - ++yyrecord->yycursor; + ++in.cur; yyFillLabel4: - yych = *yyrecord->yycursor; + yych = *in.cur; if (yych <= 0x00) { - if (yyrecord->yylimit <= yyrecord->yycursor) { - if (fill(*yyrecord) == 0) goto yyFillLabel4; + if (in.lim <= in.cur) { + if (fill(in) == 0) goto yyFillLabel4; goto yy11; } goto yy6; } goto yy6; yy10: -#line 54 "c/fill/01_fill.re" +#line 53 "c/fill/01_fill.re" { return count; } -#line 131 "c/fill/01_fill.c" +#line 126 "c/fill/01_fill.c" yy11: - yyrecord->yycursor = yyrecord->yymarker; + in.cur = in.mar; goto yy2; } -#line 57 "c/fill/01_fill.re" +#line 56 "c/fill/01_fill.re" } @@ -152,13 +147,13 @@ int main() { // Initialize lexer state: all pointers are at the end of buffer. Input in; in.file = fopen(fname, "r"); - in.yycursor = in.yymarker = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.mar = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Sentinel (at YYLIMIT pointer) is set to zero, which triggers YYFILL. - in.yylimit[0] = 0; + in.lim[0] = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); diff --git a/examples/c/fill/01_fill.re b/examples/c/fill/01_fill.re index 91901e870..0b76db596 100644 --- a/examples/c/fill/01_fill.re +++ b/examples/c/fill/01_fill.re @@ -7,45 +7,44 @@ struct Input { FILE *file; - char buffer[BUFSIZE + 1]; // +1 for sentinel - char *yylimit; - char *yycursor; - char *yymarker; - char *token; + char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; // +1 for sentinel bool eof; }; static int fill(Input &in) { if (in.eof) return 1; - const size_t shift = in.token - in.buffer; - const size_t used = in.yylimit - in.token; + const size_t shift = in.tok - in.buf; + const size_t used = in.lim - in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < 1) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit -= shift; - in.yycursor -= shift; - in.yymarker -= shift; - in.token -= shift; + memmove(in.buf, in.tok, used); + in.lim -= shift; + in.cur -= shift; + in.mar -= shift; + in.tok -= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE - used, in.file); - in.yylimit[0] = 0; - in.eof = in.yylimit < in.buffer + BUFSIZE; + in.lim += fread(in.lim, 1, BUFSIZE - used, in.file); + in.lim[0] = 0; + in.eof = in.lim < in.buf + BUFSIZE; return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord->token = yyrecord->yycursor; + in.tok = in.cur; /*!re2c - re2c:api = record; - re2c:YYCTYPE = char; - re2c:YYFILL = "fill(*yyrecord) == 0"; + re2c:api:style = free-form; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = "fill(in) == 0"; re2c:eof = 0; str = ['] ([^'\\] | [\\][^])* [']; @@ -73,13 +72,13 @@ int main() { // Initialize lexer state: all pointers are at the end of buffer. Input in; in.file = fopen(fname, "r"); - in.yycursor = in.yymarker = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.mar = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Sentinel (at YYLIMIT pointer) is set to zero, which triggers YYFILL. - in.yylimit[0] = 0; + in.lim[0] = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); diff --git a/examples/c/fill/02_fill.c b/examples/c/fill/02_fill.c index e13d32096..9b8f2820b 100644 --- a/examples/c/fill/02_fill.c +++ b/examples/c/fill/02_fill.c @@ -13,52 +13,49 @@ struct Input { FILE *file; - char buffer[BUFSIZE + YYMAXFILL]; - char *yylimit; - char *yycursor; - char *token; + char buf[BUFSIZE + YYMAXFILL], *lim, *cur, *tok; bool eof; }; static int fill(Input &in, size_t need) { if (in.eof) return 1; - const size_t shift = in.token - in.buffer; - const size_t used = in.yylimit - in.token; + const size_t shift = in.tok - in.buf; + const size_t used = in.lim - in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < need) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit -= shift; - in.yycursor -= shift; - in.token -= shift; + memmove(in.buf, in.tok, used); + in.lim -= shift; + in.cur -= shift; + in.tok -= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE - used, in.file); + in.lim += fread(in.lim, 1, BUFSIZE - used, in.file); // If read less than expected, this is end of input => add zero padding // so that the lexer can access characters at the end of buffer. - if (in.yylimit < in.buffer + BUFSIZE) { + if (in.lim < in.buf + BUFSIZE) { in.eof = true; - memset(in.yylimit, 0, YYMAXFILL); - in.yylimit += YYMAXFILL; + memset(in.lim, 0, YYMAXFILL); + in.lim += YYMAXFILL; } return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord->token = yyrecord->yycursor; + in.tok = in.cur; -#line 58 "c/fill/02_fill.c" +#line 55 "c/fill/02_fill.c" { char yych; - if (yyrecord->yylimit <= yyrecord->yycursor) if (fill(*yyrecord, 1) != 0) return -1; - yych = *yyrecord->yycursor; + if (in.lim <= in.cur) if (fill(in, 1) != 0) return -1; + yych = *in.cur; switch (yych) { case 0x00: goto yy1; case ' ': goto yy3; @@ -66,50 +63,50 @@ static int lex(Input *yyrecord) { default: goto yy2; } yy1: - ++yyrecord->yycursor; -#line 58 "c/fill/02_fill.re" + ++in.cur; +#line 57 "c/fill/02_fill.re" { // Check that it is the sentinel, not some unexpected null. - return yyrecord->token == yyrecord->yylimit - YYMAXFILL ? count : -1; + return in.tok == in.lim - YYMAXFILL ? count : -1; } -#line 76 "c/fill/02_fill.c" +#line 73 "c/fill/02_fill.c" yy2: - ++yyrecord->yycursor; -#line 64 "c/fill/02_fill.re" + ++in.cur; +#line 63 "c/fill/02_fill.re" { return -1; } -#line 81 "c/fill/02_fill.c" +#line 78 "c/fill/02_fill.c" yy3: - ++yyrecord->yycursor; - if (yyrecord->yylimit <= yyrecord->yycursor) if (fill(*yyrecord, 1) != 0) return -1; - yych = *yyrecord->yycursor; + ++in.cur; + if (in.lim <= in.cur) if (fill(in, 1) != 0) return -1; + yych = *in.cur; switch (yych) { case ' ': goto yy3; default: goto yy4; } yy4: -#line 63 "c/fill/02_fill.re" +#line 62 "c/fill/02_fill.re" { goto loop; } -#line 93 "c/fill/02_fill.c" +#line 90 "c/fill/02_fill.c" yy5: - ++yyrecord->yycursor; - if (yyrecord->yylimit <= yyrecord->yycursor) if (fill(*yyrecord, 1) != 0) return -1; - yych = *yyrecord->yycursor; + ++in.cur; + if (in.lim <= in.cur) if (fill(in, 1) != 0) return -1; + yych = *in.cur; switch (yych) { case '\'': goto yy6; case '\\': goto yy7; default: goto yy5; } yy6: - ++yyrecord->yycursor; -#line 62 "c/fill/02_fill.re" + ++in.cur; +#line 61 "c/fill/02_fill.re" { ++count; goto loop; } -#line 107 "c/fill/02_fill.c" +#line 104 "c/fill/02_fill.c" yy7: - ++yyrecord->yycursor; - if (yyrecord->yylimit <= yyrecord->yycursor) if (fill(*yyrecord, 1) != 0) return -1; + ++in.cur; + if (in.lim <= in.cur) if (fill(in, 1) != 0) return -1; goto yy5; } -#line 65 "c/fill/02_fill.re" +#line 64 "c/fill/02_fill.re" } @@ -127,14 +124,14 @@ int main() { int count = 3 * BUFSIZE; // number of quoted strings written to file // Initialize lexer state: all pointers are at the end of buffer. - // This immediately triggers YYFILL, as the check `in.yycursor < in.yylimit` fails. + // This immediately triggers YYFILL, as the check `in.cur < in.lim` fails. Input in; in.file = fopen(fname, "r"); - in.yycursor = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); diff --git a/examples/c/fill/02_fill.re b/examples/c/fill/02_fill.re index 0e9865ddb..6a416603b 100644 --- a/examples/c/fill/02_fill.re +++ b/examples/c/fill/02_fill.re @@ -8,56 +8,55 @@ struct Input { FILE *file; - char buffer[BUFSIZE + YYMAXFILL]; - char *yylimit; - char *yycursor; - char *token; + char buf[BUFSIZE + YYMAXFILL], *lim, *cur, *tok; bool eof; }; static int fill(Input &in, size_t need) { if (in.eof) return 1; - const size_t shift = in.token - in.buffer; - const size_t used = in.yylimit - in.token; + const size_t shift = in.tok - in.buf; + const size_t used = in.lim - in.tok; // Error: lexeme too long. In real life could reallocate a larger buffer. if (shift < need) return 2; // Shift buffer contents (discard everything up to the current token). - memmove(in.buffer, in.token, used); - in.yylimit -= shift; - in.yycursor -= shift; - in.token -= shift; + memmove(in.buf, in.tok, used); + in.lim -= shift; + in.cur -= shift; + in.tok -= shift; // Fill free space at the end of buffer with new data from file. - in.yylimit += fread(in.yylimit, 1, BUFSIZE - used, in.file); + in.lim += fread(in.lim, 1, BUFSIZE - used, in.file); // If read less than expected, this is end of input => add zero padding // so that the lexer can access characters at the end of buffer. - if (in.yylimit < in.buffer + BUFSIZE) { + if (in.lim < in.buf + BUFSIZE) { in.eof = true; - memset(in.yylimit, 0, YYMAXFILL); - in.yylimit += YYMAXFILL; + memset(in.lim, 0, YYMAXFILL); + in.lim += YYMAXFILL; } return 0; } -static int lex(Input *yyrecord) { +static int lex(Input &in) { int count = 0; loop: - yyrecord->token = yyrecord->yycursor; + in.tok = in.cur; /*!re2c - re2c:api = record; - re2c:YYCTYPE = char; - re2c:YYFILL = "if (fill(*yyrecord, @@) != 0) return -1;"; + re2c:api:style = free-form; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = "if (fill(in, @@) != 0) return -1;"; str = ['] ([^'\\] | [\\][^])* [']; [\x00] { // Check that it is the sentinel, not some unexpected null. - return yyrecord->token == yyrecord->yylimit - YYMAXFILL ? count : -1; + return in.tok == in.lim - YYMAXFILL ? count : -1; } str { ++count; goto loop; } [ ]+ { goto loop; } @@ -79,14 +78,14 @@ int main() { int count = 3 * BUFSIZE; // number of quoted strings written to file // Initialize lexer state: all pointers are at the end of buffer. - // This immediately triggers YYFILL, as the check `in.yycursor < in.yylimit` fails. + // This immediately triggers YYFILL, as the check `in.cur < in.lim` fails. Input in; in.file = fopen(fname, "r"); - in.yycursor = in.token = in.yylimit = in.buffer + BUFSIZE; + in.cur = in.tok = in.lim = in.buf + BUFSIZE; in.eof = 0; // Run the lexer. - assert(lex(&in) == count); + assert(lex(in) == count); // Cleanup: remove input file. fclose(in.file); diff --git a/examples/c/generic_api/ifstream.re b/examples/c/generic_api/ifstream.re index 2e2aa3bed..1cf265606 100644 --- a/examples/c/generic_api/ifstream.re +++ b/examples/c/generic_api/ifstream.re @@ -8,13 +8,13 @@ static void convert_newlines(std::ifstream &in, std::ostringstream &out) { std::streampos mar; for (;;) { /*!re2c - re2c:api = generic; + re2c:api= custom; re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYPEEK = "in.peek()"; - re2c:YYSKIP = "{ in.ignore(); if (in.eof()) return; }"; - re2c:YYBACKUP = "mar = in.tellg();"; - re2c:YYRESTORE = "in.seekg(mar);"; + re2c:define:YYCTYPE = char; + re2c:define:YYPEEK = "in.peek()"; + re2c:define:YYSKIP = "{ in.ignore(); if (in.eof()) return; }"; + re2c:define:YYBACKUP = "mar = in.tellg();"; + re2c:define:YYRESTORE = "in.seekg(mar);"; re2c:yyfill:enable = 0; * { out.put(yych); continue; } diff --git a/examples/c/headers/header.c b/examples/c/headers/header.c index a777b469f..a3eefc7bd 100644 --- a/examples/c/headers/header.c +++ b/examples/c/headers/header.c @@ -6,31 +6,30 @@ -long lex(LexerState* yyrecord) { +long lex(LexerState& st) { const char *t; { char yych; goto yy0; yy1: - ++yyrecord->yycursor; + ++st.cur; yy0: - yych = *yyrecord->yycursor; + yych = *st.cur; switch (yych) { case 'a': goto yy1; case 'b': - yyrecord->yyt1 = yyrecord->yycursor; + st.yyt1 = st.cur; goto yy3; default: - yyrecord->yyt1 = yyrecord->yycursor; + st.yyt1 = st.cur; goto yy2; } yy2: - t = yyrecord->yyt1; - { return t - yyrecord->str; } + t = st.yyt1; + { return t - st.str; } yy3: - ++yyrecord->yycursor; - yych = *yyrecord->yycursor; + yych = *++st.cur; switch (yych) { case 'b': goto yy3; default: goto yy2; @@ -42,13 +41,13 @@ long lex(LexerState* yyrecord) { int main() { const char *s = "ab"; LexerState st = { s, s , NULL }; - assert(lex(&st) == 1); + assert(lex(st) == 1); return 0; } /* Generated by re2c */ struct LexerState { - const char *str, *yycursor; + const char *str, *cur; const char *yyt1; }; -c/headers/header.re:22:21: warning: rule matches empty string [-Wmatch-empty-string] +c/headers/header.re:23:21: warning: rule matches empty string [-Wmatch-empty-string] diff --git a/examples/c/headers/header.re b/examples/c/headers/header.re index 8d60db372..f8dcac06a 100644 --- a/examples/c/headers/header.re +++ b/examples/c/headers/header.re @@ -5,27 +5,28 @@ /*!header:re2c:on*/ struct LexerState { - const char *str, *yycursor; + const char *str, *cur; /*!stags:re2c format = "const char *@@;"; */ }; /*!header:re2c:off*/ -long lex(LexerState* yyrecord) { +long lex(LexerState& st) { const char *t; /*!re2c re2c:header = "lexer/state.h"; - re2c:api = record; re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = "st.cur"; re2c:tags = 1; + re2c:tags:expression = "st.@@"; - [a]* @t [b]* { return t - yyrecord->str; } + [a]* @t [b]* { return t - st.str; } */ } int main() { const char *s = "ab"; LexerState st = { s, s /*!stags:re2c format = ", NULL"; */ }; - assert(lex(&st) == 1); + assert(lex(st) == 1); return 0; } diff --git a/examples/c/headers/lexer/state.h b/examples/c/headers/lexer/state.h index 32ed196ec..9b204968c 100644 --- a/examples/c/headers/lexer/state.h +++ b/examples/c/headers/lexer/state.h @@ -2,7 +2,7 @@ typedef struct { - const char *str, *yycursor; + const char *str, *cur; const char *yyt1; } LexerState; diff --git a/examples/c/includes/include.re b/examples/c/includes/include.re index 5a59ad814..44998a667 100644 --- a/examples/c/includes/include.re +++ b/examples/c/includes/include.re @@ -5,7 +5,7 @@ Result lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; * { return FAIL; } diff --git a/examples/c/real_world/cxx98.re b/examples/c/real_world/cxx98.re index 04ccd13c2..a1e5ba171 100644 --- a/examples/c/real_world/cxx98.re +++ b/examples/c/real_world/cxx98.re @@ -51,7 +51,7 @@ struct input_t { } }; -/*!re2c re2c:YYCTYPE = "unsigned char"; */ +/*!re2c re2c:define:YYCTYPE = "unsigned char"; */ template static bool adddgt(unsigned long &u, unsigned long d) @@ -88,7 +88,7 @@ static bool lex_hex(const unsigned char *s, const unsigned char *e, unsigned lon for (u = 0, s += 2; s < e;) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCURSOR = s; + re2c:define:YYCURSOR = s; * { if (!adddgt<16>(u, s[-1] - 0x30u)) return false; continue; } [a-f] { if (!adddgt<16>(u, s[-1] - 0x61u + 10)) return false; continue; } [A-F] { if (!adddgt<16>(u, s[-1] - 0x41u + 10)) return false; continue; } @@ -104,11 +104,11 @@ static bool lex_str(input_t &in, unsigned char q) in.tok = in.cur; /*!re2c re2c:yyfill:enable = 1; - re2c:YYCURSOR = in.cur; - re2c:YYMARKER = in.mar; - re2c:YYLIMIT = in.lim; - re2c:YYFILL = "if (!in.fill(@@)) return false;"; - re2c:YYFILL:naked = 1; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = "if (!in.fill(@@)) return false;"; + re2c:define:YYFILL:naked = 1; * { return false; } [^\n\\] { u = in.tok[0]; if (u == q) break; continue; } "\\a" { u = '\a'; continue; } @@ -139,7 +139,7 @@ static bool lex_flt(const unsigned char *s) int e = 0; /*!re2c re2c:yyfill:enable = 0; - re2c:YYCURSOR = s; + re2c:define:YYCURSOR = s; */ mant_int: /*!re2c @@ -180,11 +180,11 @@ static bool lex(input_t &in) in.tok = in.cur; /*!re2c re2c:yyfill:enable = 1; - re2c:YYCURSOR = in.cur; - re2c:YYMARKER = in.mar; - re2c:YYLIMIT = in.lim; - re2c:YYFILL = "if (!in.fill(@@)) return false;"; - re2c:YYFILL:naked = 1; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = "if (!in.fill(@@)) return false;"; + re2c:define:YYFILL:naked = 1; end = "\x00"; diff --git a/examples/c/reuse/braille.re b/examples/c/reuse/braille.re index 76e42b3b7..f7bd8f28e 100644 --- a/examples/c/reuse/braille.re +++ b/examples/c/reuse/braille.re @@ -44,8 +44,8 @@ struct out_t { re2c:yyfill:enable = 0; re2c:api:style = free-form; re2c:encoding:utf8 = 1; - re2c:YYGETCOND = "c"; - re2c:YYSETCOND = "c = @@;"; + re2c:define:YYGETCONDITION = "c"; + re2c:define:YYSETCONDITION = "c = @@;"; // letters l = "\u2830"; @@ -135,7 +135,7 @@ static void lex_utf8(const iutf8_t & in) int c = yycl; out_t out; /*!use:re2c - re2c:YYCTYPE = "unsigned char"; + re2c:define:YYCTYPE = "unsigned char"; re2c:encoding:utf8 = 1; */ } @@ -146,7 +146,7 @@ static void lex_utf16(const iutf16_t & in) int c = yycl; out_t out; /*!use:re2c - re2c:YYCTYPE = "unsigned int"; + re2c:define:YYCTYPE = "unsigned int"; re2c:encoding:utf16 = 1; */ } @@ -157,7 +157,7 @@ static void lex_utf32(const iutf32_t & in) int c = yycl; out_t out; /*!use:re2c - re2c:YYCTYPE = "unsigned int"; + re2c:define:YYCTYPE = "unsigned int"; re2c:encoding:utf32 = 1; */ } @@ -168,7 +168,7 @@ static void lex_ucs2(const iucs2_t & in) int c = yycl; out_t out; /*!use:re2c - re2c:YYCTYPE = "unsigned int"; + re2c:define:YYCTYPE = "unsigned int"; re2c:encoding:ucs2 = 1; */ } diff --git a/examples/c/reuse/reuse.re b/examples/c/reuse/reuse.re index 0104a43dd..612a6e0c9 100644 --- a/examples/c/reuse/reuse.re +++ b/examples/c/reuse/reuse.re @@ -15,7 +15,7 @@ static int lex_utf8(const uint8_t *s) { const uint8_t *YYCURSOR = s, *YYMARKER; /*!use:re2c - re2c:YYCTYPE = uint8_t; + re2c:define:YYCTYPE = uint8_t; re2c:encoding:utf8 = 1; */ } @@ -23,7 +23,7 @@ static int lex_utf8(const uint8_t *s) { static int lex_utf32(const uint32_t *s) { const uint32_t *YYCURSOR = s, *YYMARKER; /*!use:re2c - re2c:YYCTYPE = uint32_t; + re2c:define:YYCTYPE = uint32_t; re2c:encoding:utf32 = 1; */ } diff --git a/examples/c/reuse/usedir.re b/examples/c/reuse/usedir.re index 5ddab7c8d..61bb9776d 100644 --- a/examples/c/reuse/usedir.re +++ b/examples/c/reuse/usedir.re @@ -23,7 +23,7 @@ static What lex(const char *s) { const char *YYCURSOR = s, *YYMARKER; /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; !use:fish; !use:colors; diff --git a/examples/c/state/push.c b/examples/c/state/push.c index 467f23e8b..d6f87a789 100644 --- a/examples/c/state/push.c +++ b/examples/c/state/push.c @@ -208,7 +208,7 @@ switch (st.state) { } void test(const char **packets, Status expect) { - // Create a pipe (open the same file for reading and writing). + // Create a "socket" (open the same file for reading and writing). const char *fname = "pipe"; FILE *fw = fopen(fname, "w"); FILE *fr = fopen(fname, "r"); diff --git a/examples/c/state/push.re b/examples/c/state/push.re index e8c6053de..e8f74c757 100644 --- a/examples/c/state/push.re +++ b/examples/c/state/push.re @@ -49,13 +49,13 @@ static Status lex(State &st, unsigned int *recv) { st.tok = st.cur; /*!re2c re2c:api:style = free-form; - re2c:YYCTYPE = "char"; - re2c:YYCURSOR = "st.cur"; - re2c:YYMARKER = "st.mar"; - re2c:YYLIMIT = "st.lim"; - re2c:YYGETSTATE = "st.state"; - re2c:YYSETSTATE = "st.state = @@;"; - re2c:YYFILL = "return WAITING;"; + re2c:define:YYCTYPE = "char"; + re2c:define:YYCURSOR = "st.cur"; + re2c:define:YYMARKER = "st.mar"; + re2c:define:YYLIMIT = "st.lim"; + re2c:define:YYGETSTATE = "st.state"; + re2c:define:YYSETSTATE = "st.state = @@;"; + re2c:define:YYFILL = "return WAITING;"; re2c:eof = 0; packet = [a-z]+[;]; @@ -68,7 +68,7 @@ static Status lex(State &st, unsigned int *recv) { } void test(const char **packets, Status expect) { - // Create a pipe (open the same file for reading and writing). + // Create a "socket" (open the same file for reading and writing). const char *fname = "pipe"; FILE *fw = fopen(fname, "w"); FILE *fr = fopen(fname, "r"); diff --git a/examples/c/submatch/01_stags.c b/examples/c/submatch/01_stags.c index 7e27dd4b7..78cfc2c07 100644 --- a/examples/c/submatch/01_stags.c +++ b/examples/c/submatch/01_stags.c @@ -15,20 +15,12 @@ static int s2n(const char *s, const char *e) { // pre-parsed string to number static bool lex(const char *str, SemVer &ver) { const char *YYCURSOR = str, *YYMARKER; - // Final tag variables available in semantic action. - -#line 21 "c/submatch/01_stags.c" -const char *t1; -const char *t2; -const char *t3; -const char *t4; -const char *t5; -#line 17 "c/submatch/01_stags.re" - + // User-defined tag variables that are available in semantic action. + const char *t1, *t2, *t3, *t4, *t5; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. -#line 32 "c/submatch/01_stags.c" +#line 24 "c/submatch/01_stags.c" const char *yyt1; const char *yyt2; const char *yyt3; @@ -37,7 +29,7 @@ const char *yyt4; -#line 41 "c/submatch/01_stags.c" +#line 33 "c/submatch/01_stags.c" { char yych; yych = *YYCURSOR; @@ -61,7 +53,7 @@ const char *yyt4; yy2: #line 35 "c/submatch/01_stags.re" { return false; } -#line 65 "c/submatch/01_stags.c" +#line 57 "c/submatch/01_stags.c" yy3: yych = *(YYMARKER = ++YYCURSOR); switch (yych) { @@ -151,7 +143,7 @@ const char *yyt4; ver.patch = t5 != NULL ? s2n(t5, YYCURSOR - 1) : 0; return true; } -#line 155 "c/submatch/01_stags.c" +#line 147 "c/submatch/01_stags.c" yy9: yych = *++YYCURSOR; switch (yych) { diff --git a/examples/c/submatch/01_stags.re b/examples/c/submatch/01_stags.re index 0a6bd812d..1c9a83857 100644 --- a/examples/c/submatch/01_stags.re +++ b/examples/c/submatch/01_stags.re @@ -13,15 +13,15 @@ static int s2n(const char *s, const char *e) { // pre-parsed string to number static bool lex(const char *str, SemVer &ver) { const char *YYCURSOR = str, *YYMARKER; - // Final tag variables available in semantic action. - /*!svars:re2c format = "const char *@@;\n"; */ + // User-defined tag variables that are available in semantic action. + const char *t1, *t2, *t3, *t4, *t5; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. /*!stags:re2c format = 'const char *@@;\n'; */ /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:tags = 1; num = [0-9]+; diff --git a/examples/c/submatch/01_stags_fill.c b/examples/c/submatch/01_stags_fill.c index c0334a1bd..4a8fe8e55 100644 --- a/examples/c/submatch/01_stags_fill.c +++ b/examples/c/submatch/01_stags_fill.c @@ -12,7 +12,7 @@ struct Input { FILE *file; char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; - // Intermediate tag variables must be part of the lexer state passed to YYFILL. + // Tag variables must be part of the lexer state passed to YYFILL. // They don't correspond to tags and should be autogenerated by re2c. #line 19 "c/submatch/01_stags_fill.c" @@ -68,20 +68,14 @@ if (in.yyt3) in.yyt3 -= shift; } static bool lex(Input &in, std::vector &vers) { - // Final tag variables available in semantic action. - -#line 74 "c/submatch/01_stags_fill.c" -const char *t1; -const char *t2; -const char *t3; -const char *t4; -#line 60 "c/submatch/01_stags_fill.re" - - + // User-defined local variables that store final tag values. + // They are different from tag variables autogenerated with `stags:re2c`, + // as they are set at the end of match and used only in semantic actions. + const char *t1, *t2, *t3, *t4; for (;;) { in.tok = in.cur; -#line 85 "c/submatch/01_stags_fill.c" +#line 79 "c/submatch/01_stags_fill.c" { char yych; yyFillLabel0: @@ -107,9 +101,9 @@ const char *t4; yy1: ++in.cur; yy2: -#line 85 "c/submatch/01_stags_fill.re" +#line 86 "c/submatch/01_stags_fill.re" { return false; } -#line 113 "c/submatch/01_stags_fill.c" +#line 107 "c/submatch/01_stags_fill.c" yy3: in.mar = ++in.cur; yyFillLabel1: @@ -215,7 +209,7 @@ const char *t4; t4 = in.yyt3; t1 = in.yyt1; t1 -= 1; -#line 76 "c/submatch/01_stags_fill.re" +#line 77 "c/submatch/01_stags_fill.re" { int major = s2n(in.tok, t1); int minor = s2n(t2, t3); @@ -224,7 +218,7 @@ const char *t4; vers.push_back(ver); continue; } -#line 228 "c/submatch/01_stags_fill.c" +#line 222 "c/submatch/01_stags_fill.c" yy9: ++in.cur; yyFillLabel5: @@ -271,11 +265,11 @@ const char *t4; goto yy5; } yy11: -#line 84 "c/submatch/01_stags_fill.re" +#line 85 "c/submatch/01_stags_fill.re" { return true; } -#line 277 "c/submatch/01_stags_fill.c" +#line 271 "c/submatch/01_stags_fill.c" } -#line 86 "c/submatch/01_stags_fill.re" +#line 87 "c/submatch/01_stags_fill.re" } } @@ -297,11 +291,11 @@ int main() { in.file = f; in.cur = in.mar = in.tok = in.lim = in.buf + BUFSIZE; -#line 301 "c/submatch/01_stags_fill.c" +#line 295 "c/submatch/01_stags_fill.c" in.yyt1 = in.lim; in.yyt2 = in.lim; in.yyt3 = in.lim; -#line 106 "c/submatch/01_stags_fill.re" +#line 107 "c/submatch/01_stags_fill.re" in.eof = false; // Sentinel (at YYLIMIT pointer) is set to zero, which triggers YYFILL. diff --git a/examples/c/submatch/01_stags_fill.re b/examples/c/submatch/01_stags_fill.re index 86c2379b9..1f5dec7de 100644 --- a/examples/c/submatch/01_stags_fill.re +++ b/examples/c/submatch/01_stags_fill.re @@ -10,7 +10,7 @@ struct Input { FILE *file; char buf[BUFSIZE + 1], *lim, *cur, *mar, *tok; - // Intermediate tag variables must be part of the lexer state passed to YYFILL. + // Tag variables must be part of the lexer state passed to YYFILL. // They don't correspond to tags and should be autogenerated by re2c. /*!stags:re2c format = 'const char *@@;'; */ bool eof; @@ -56,19 +56,20 @@ static int fill(Input &in) { } static bool lex(Input &in, std::vector &vers) { - // Final tag variables available in semantic action. - /*!svars:re2c format = 'const char *@@;\n'; */ - + // User-defined local variables that store final tag values. + // They are different from tag variables autogenerated with `stags:re2c`, + // as they are set at the end of match and used only in semantic actions. + const char *t1, *t2, *t3, *t4; for (;;) { in.tok = in.cur; /*!re2c re2c:eof = 0; re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYCURSOR = in.cur; - re2c:YYMARKER = in.mar; - re2c:YYLIMIT = in.lim; - re2c:YYFILL = "fill(in) == 0"; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in.cur; + re2c:define:YYMARKER = in.mar; + re2c:define:YYLIMIT = in.lim; + re2c:define:YYFILL = "fill(in) == 0"; re2c:tags:expression = "in.@@"; num = [0-9]+; diff --git a/examples/c/submatch/02_mtags.c b/examples/c/submatch/02_mtags.c index de42ba040..02fad93f0 100644 --- a/examples/c/submatch/02_mtags.c +++ b/examples/c/submatch/02_mtags.c @@ -57,32 +57,24 @@ static bool parse(const char *str, Ver &ver) { const char *YYCURSOR = str, *YYMARKER; MtagTrie mt; - // Final tag variables available in semantic action. - -#line 63 "c/submatch/02_mtags.c" -const char *t1;const char *t2; -#line 59 "c/submatch/02_mtags.re" - - -#line 68 "c/submatch/02_mtags.c" -int t3;int t4; -#line 60 "c/submatch/02_mtags.re" - + // User-defined tag variables that are available in semantic action. + const char *t1, *t2; + int t3, t4; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. -#line 75 "c/submatch/02_mtags.c" +#line 67 "c/submatch/02_mtags.c" const char *yyt1 = NULL;const char *yyt2 = NULL; #line 63 "c/submatch/02_mtags.re" -#line 80 "c/submatch/02_mtags.c" +#line 72 "c/submatch/02_mtags.c" int yytm3 = MTAG_ROOT;int yytm4 = MTAG_ROOT; #line 64 "c/submatch/02_mtags.re" -#line 86 "c/submatch/02_mtags.c" +#line 78 "c/submatch/02_mtags.c" { char yych; yych = *YYCURSOR; @@ -106,7 +98,7 @@ int yytm3 = MTAG_ROOT;int yytm4 = MTAG_ROOT; yy2: #line 84 "c/submatch/02_mtags.re" { return false; } -#line 110 "c/submatch/02_mtags.c" +#line 102 "c/submatch/02_mtags.c" yy3: yych = *(YYMARKER = ++YYCURSOR); switch (yych) { @@ -143,7 +135,7 @@ int yytm3 = MTAG_ROOT;int yytm4 = MTAG_ROOT; unfold(mt, t3, t4, ver); return true; } -#line 147 "c/submatch/02_mtags.c" +#line 139 "c/submatch/02_mtags.c" yy5: yych = *++YYCURSOR; switch (yych) { diff --git a/examples/c/submatch/02_mtags.re b/examples/c/submatch/02_mtags.re index 533341034..f65328a18 100644 --- a/examples/c/submatch/02_mtags.re +++ b/examples/c/submatch/02_mtags.re @@ -55,21 +55,21 @@ static bool parse(const char *str, Ver &ver) { const char *YYCURSOR = str, *YYMARKER; MtagTrie mt; - // Final tag variables available in semantic action. - /*!svars:re2c format = 'const char *@@;'; */ - /*!mvars:re2c format = 'int @@;'; */ + // User-defined tag variables that are available in semantic action. + const char *t1, *t2; + int t3, t4; - // Intermediate tag variables used by the lexer (must be autogenerated). + // Autogenerated tag variables used by the lexer to track tag values. /*!stags:re2c format = 'const char *@@ = NULL;'; */ /*!mtags:re2c format = 'int @@ = MTAG_ROOT;'; */ /*!re2c re2c:api:style = free-form; - re2c:YYCTYPE = char; - re2c:YYSTAGP = "@@ = YYCURSOR;"; - re2c:YYSTAGN = "@@ = NULL;"; - re2c:YYMTAGP = "add_mtag(mt, @@, YYCURSOR);"; - re2c:YYMTAGN = "add_mtag(mt, @@, NULL);"; + re2c:define:YYCTYPE = char; + re2c:define:YYSTAGP = "@@ = YYCURSOR;"; + re2c:define:YYSTAGN = "@@ = NULL;"; + re2c:define:YYMTAGP = "add_mtag(mt, @@, YYCURSOR);"; + re2c:define:YYMTAGN = "add_mtag(mt, @@, NULL);"; re2c:yyfill:enable = 0; re2c:tags = 1; diff --git a/examples/c/submatch/03_captures.re b/examples/c/submatch/03_captures.re index 57b55dc24..e114a79c4 100644 --- a/examples/c/submatch/03_captures.re +++ b/examples/c/submatch/03_captures.re @@ -21,7 +21,7 @@ static bool lex(const char *str, SemVer &ver) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:captvars = 1; num = [0-9]+; diff --git a/examples/c/submatch/04_posix_captures.re b/examples/c/submatch/04_posix_captures.re index 3219df35f..a3311e83d 100644 --- a/examples/c/submatch/04_posix_captures.re +++ b/examples/c/submatch/04_posix_captures.re @@ -25,7 +25,7 @@ static bool lex(const char *str, SemVer &ver) { /*!re2c re2c:yyfill:enable = 0; - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:posix-captures = 1; num = [0-9]+; diff --git a/examples/c/submatch/http_rfc7230.c b/examples/c/submatch/http_rfc7230.c index fdcc6b783..4da7ce470 100644 --- a/examples/c/submatch/http_rfc7230.c +++ b/examples/c/submatch/http_rfc7230.c @@ -259,51 +259,20 @@ static void print_headers(const char *tok, static int lex(input_t *in, long *count) { - const char *at = NULL; -const char *au = NULL; -const char *hs1 = NULL; -const char *hs2 = NULL; -const char *hs3 = NULL; -const char *hs4 = NULL; -const char *m1 = NULL; -const char *m2 = NULL; -const char *of = NULL; -const char *p1 = NULL; -const char *p2 = NULL; -const char *p3 = NULL; -const char *p4 = NULL; -const char *p5 = NULL; -const char *p6 = NULL; -const char *q1 = NULL; -const char *q2 = NULL; -const char *q3 = NULL; -const char *q4 = NULL; -const char *r1 = NULL; -const char *r2 = NULL; -const char *r3 = NULL; -const char *r4 = NULL; -const char *rp1 = NULL; -const char *rp2 = NULL; -const char *s1 = NULL; -const char *s2 = NULL; -const char *st1 = NULL; -const char *st2 = NULL; -const char *u1 = NULL; -const char *u2 = NULL; -const char *u3 = NULL; -const char *u4 = NULL; -const char *v1 = NULL; -const char *v2 = NULL; -const char *v3 = NULL; -const char *v4 = NULL; + const char *of, *au, *at, + *hs1, *hs3, *m1, *p1, *p3, *p5, *q1, *q3, + *hs2, *hs4, *m2, *p2, *p4, *p6, *q2, *q4, + *r1, *r3, *rp1, *s1, *st1, *u1, *u3, *v1, *v3, + *r2, *r4, *rp2, *s2, *st2, *u2, *u4, *v2, *v4; + mtag_t *h1, *h2, *h3, *h4, *h5; + long c; - mtag_t *h1; -mtag_t *h2; -mtag_t *h3; -mtag_t *h4; -mtag_t *h5; - - long c = 0; + c = 0;; + of = au = at + = hs1 = hs3 = m1 = p1 = p3 = p5 = q1 = q3 + = hs2 = hs4 = m2 = p2 = p4 = p6 = q2 = q4 + = r1 = r3 = rp1 = s1 = st1 = u1 = u3 = v1 = v3 + = r2 = r4 = rp2 = s2 = st2 = u2 = u4 = v2 = v4 = NULL; loop: in->tok = in->cur; @@ -14076,21 +14045,21 @@ int main(int argc, char **argv) free_input(&in); return 0; } -c/submatch/http_rfc7230.re:236:17: warning: tag `m1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `at` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `u3` has 3rd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `u4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `hs3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `hs4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `r3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `s1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `s2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `u1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `u2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `hs1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `hs2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `r1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `p3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `h3` has 3rd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `h4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/http_rfc7230.re:236:17: warning: tag `h5` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `m1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `at` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `u3` has 3rd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `u4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `hs3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `hs4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `r3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `s1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `s2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `u1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `u2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `hs1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `hs2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `r1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `p3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `h3` has 3rd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `h4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/http_rfc7230.re:247:17: warning: tag `h5` has 2nd degree of nondeterminism [-Wnondeterministic-tags] diff --git a/examples/c/submatch/http_rfc7230.re b/examples/c/submatch/http_rfc7230.re index 2319b1426..3d0a64691 100644 --- a/examples/c/submatch/http_rfc7230.re +++ b/examples/c/submatch/http_rfc7230.re @@ -146,9 +146,20 @@ static void print_headers(const char *tok, static int lex(input_t *in, long *count) { - /*!svars:re2c format = 'const char *@@ = NULL;\n'; */ - /*!mvars:re2c format = 'mtag_t *@@;\n'; */ - long c = 0; + const char *of, *au, *at, + *hs1, *hs3, *m1, *p1, *p3, *p5, *q1, *q3, + *hs2, *hs4, *m2, *p2, *p4, *p6, *q2, *q4, + *r1, *r3, *rp1, *s1, *st1, *u1, *u3, *v1, *v3, + *r2, *r4, *rp2, *s2, *st2, *u2, *u4, *v2, *v4; + mtag_t *h1, *h2, *h3, *h4, *h5; + long c; + + c = 0;; + of = au = at + = hs1 = hs3 = m1 = p1 = p3 = p5 = q1 = q3 + = hs2 = hs4 = m2 = p2 = p4 = p6 = q2 = q4 + = r1 = r3 = rp1 = s1 = st1 = u1 = u3 = v1 = v3 + = r2 = r4 = rp2 = s2 = st2 = u2 = u4 = v2 = v4 = NULL; loop: in->tok = in->cur; /*!re2c diff --git a/examples/c/submatch/parse_etc_passwd.c b/examples/c/submatch/parse_etc_passwd.c index f622448f9..e07bb6276 100644 --- a/examples/c/submatch/parse_etc_passwd.c +++ b/examples/c/submatch/parse_etc_passwd.c @@ -8,8 +8,7 @@ static int lex(const char *YYCURSOR) { - const char *YYMARKER; - const char *c;const char *f;const char *g;const char *h;const char *n;const char *p;const char *u; + const char *YYMARKER, *n, *p, *u, *g, *f, *h, *c; const char *yyt1;const char *yyt2;const char *yyt3;const char *yyt4;const char *yyt5;const char *yyt6;const char *yyt7; for (;;) { diff --git a/examples/c/submatch/parse_etc_passwd.re b/examples/c/submatch/parse_etc_passwd.re index 3847202e9..8c325865b 100644 --- a/examples/c/submatch/parse_etc_passwd.re +++ b/examples/c/submatch/parse_etc_passwd.re @@ -6,13 +6,12 @@ /*!max:re2c*/ static int lex(const char *YYCURSOR) { - const char *YYMARKER; - /*!svars:re2c format = 'const char *@@;'; */ + const char *YYMARKER, *n, *p, *u, *g, *f, *h, *c; /*!stags:re2c format = 'const char *@@;'; */ for (;;) { /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; re2c:tags = 1; diff --git a/examples/c/submatch/parse_options.re b/examples/c/submatch/parse_options.re index 0aec276a8..1107d1446 100644 --- a/examples/c/submatch/parse_options.re +++ b/examples/c/submatch/parse_options.re @@ -42,9 +42,9 @@ static int lex(const char *s) { for (;;) { /*!re2c - re2c:YYCTYPE = char; - re2c:YYCURSOR = s; - re2c:YYMARKER = m; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = s; + re2c:define:YYMARKER = m; re2c:yyfill:enable = 0; re2c:tags = 1; diff --git a/examples/c/submatch/parse_records.re b/examples/c/submatch/parse_records.re index 4fc112dbf..9547b09fc 100644 --- a/examples/c/submatch/parse_records.re +++ b/examples/c/submatch/parse_records.re @@ -39,7 +39,7 @@ static int lex(const char *YYCURSOR) { tp.clear(); /*!mtags:re2c format = "@@ = -1;"; */ /*!re2c - re2c:YYCTYPE = char; + re2c:define:YYCTYPE = char; re2c:yyfill:enable = 0; re2c:tags = 1; diff --git a/examples/c/submatch/uri_rfc3986.c b/examples/c/submatch/uri_rfc3986.c index 9a4794bcc..0c92ea208 100644 --- a/examples/c/submatch/uri_rfc3986.c +++ b/examples/c/submatch/uri_rfc3986.c @@ -124,28 +124,12 @@ if (in->yyt9) in->yyt9 -= free; static int lex(input_t *in, long *count) { - const char *f1; -const char *f2; -const char *h1; -const char *h2; -const char *h3; -const char *h4; -const char *h5; -const char *h6; -const char *p1; -const char *p2; -const char *p3; -const char *p4; -const char *q1; -const char *q2; -const char *r1; -const char *r2; -const char *s1; -const char *s2; -const char *u1; -const char *u2; + const char + *s1, *u1, *h1, *h3, *h5, *r1, *p1, *p3, *q1, *f1, + *s2, *u2, *h2, *h4, *h6, *r2, *p2, *p4, *q2, *f2; + long c; - long c = 0; + c = 0; loop: in->tok = in->cur; @@ -8929,13 +8913,13 @@ int main(int argc, char **argv) free_input(&in); return 0; } -c/submatch/uri_rfc3986.re:134:8: warning: tag `u1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `u2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h5` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `h6` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `r1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] -c/submatch/uri_rfc3986.re:134:8: warning: tag `p3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `u1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `u2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h2` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h4` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h5` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `h6` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `r1` has 2nd degree of nondeterminism [-Wnondeterministic-tags] +c/submatch/uri_rfc3986.re:138:8: warning: tag `p3` has 2nd degree of nondeterminism [-Wnondeterministic-tags] diff --git a/examples/c/submatch/uri_rfc3986.re b/examples/c/submatch/uri_rfc3986.re index 6d4422f80..aea02a757 100644 --- a/examples/c/submatch/uri_rfc3986.re +++ b/examples/c/submatch/uri_rfc3986.re @@ -62,18 +62,22 @@ static int fill(input_t *in, size_t need) static int lex(input_t *in, long *count) { - /*!svars:re2c format = "const char *@@;\n"; */ - long c = 0; + const char + *s1, *u1, *h1, *h3, *h5, *r1, *p1, *p3, *q1, *f1, + *s2, *u2, *h2, *h4, *h6, *r2, *p2, *p4, *q2, *f2; + long c; + + c = 0; loop: in->tok = in->cur; /*!re2c - re2c:YYCTYPE = char; - re2c:YYCURSOR = in->cur; - re2c:YYMARKER = in->mar; - re2c:YYLIMIT = in->lim; - re2c:YYFILL = "if (fill(in, @@) != 0) return 2;"; - re2c:YYFILL:naked = 1; + re2c:define:YYCTYPE = char; + re2c:define:YYCURSOR = in->cur; + re2c:define:YYMARKER = in->mar; + re2c:define:YYLIMIT = in->lim; + re2c:define:YYFILL = "if (fill(in, @@) != 0) return 2;"; + re2c:define:YYFILL:naked = 1; re2c:tags:expression = "in->@@"; end = "\x00";