From d726003e3bf6364cea53a486385b01cd290a7ddc Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Wed, 11 May 2016 13:27:07 +0100 Subject: [PATCH] Added tests for tags (nondeterminism, unsuccessfull minimization). --- re2c/test/tags/minimization.i.c | 66 ++++++++ re2c/test/tags/minimization.i.re | 14 ++ re2c/test/tags/nondet_alt1.--tags.c | 1 + re2c/test/tags/nondet_alt1.--tags.re | 4 + re2c/test/tags/nondet_alt2.--tags.c | 1 + re2c/test/tags/nondet_alt2.--tags.re | 4 + re2c/test/tags/nondet_cat1.--tags.c | 1 + re2c/test/tags/nondet_cat1.--tags.re | 4 + re2c/test/tags/nondet_cat2.c | 2 + re2c/test/tags/nondet_cat2.re | 15 ++ re2c/test/tags/nondet_cat3.i.c | 147 ++++++++++++++++++ re2c/test/tags/nondet_cat3.i.re | 33 ++++ re2c/test/tags/nondet_cat4.--tags.c | 1 + re2c/test/tags/nondet_cat4.--tags.re | 6 + re2c/test/tags/nondeterministic1.i--tags.c | 1 - re2c/test/tags/nondeterministic1.i--tags.re | 28 ---- .../tags/nondeterministic1_trail.i--tags.c | 1 - .../tags/nondeterministic1_trail.i--tags.re | 28 ---- re2c/test/tags/nondeterministic1_trail.i.c | 57 ------- re2c/test/tags/nondeterministic1_trail.i.re | 28 ---- 20 files changed, 299 insertions(+), 143 deletions(-) create mode 100644 re2c/test/tags/minimization.i.c create mode 100644 re2c/test/tags/minimization.i.re create mode 100644 re2c/test/tags/nondet_alt1.--tags.c create mode 100644 re2c/test/tags/nondet_alt1.--tags.re create mode 100644 re2c/test/tags/nondet_alt2.--tags.c create mode 100644 re2c/test/tags/nondet_alt2.--tags.re create mode 100644 re2c/test/tags/nondet_cat1.--tags.c create mode 100644 re2c/test/tags/nondet_cat1.--tags.re create mode 100644 re2c/test/tags/nondet_cat2.c create mode 100644 re2c/test/tags/nondet_cat2.re create mode 100644 re2c/test/tags/nondet_cat3.i.c create mode 100644 re2c/test/tags/nondet_cat3.i.re create mode 100644 re2c/test/tags/nondet_cat4.--tags.c create mode 100644 re2c/test/tags/nondet_cat4.--tags.re delete mode 100644 re2c/test/tags/nondeterministic1.i--tags.c delete mode 100644 re2c/test/tags/nondeterministic1.i--tags.re delete mode 100644 re2c/test/tags/nondeterministic1_trail.i--tags.c delete mode 100644 re2c/test/tags/nondeterministic1_trail.i--tags.re delete mode 100644 re2c/test/tags/nondeterministic1_trail.i.c delete mode 100644 re2c/test/tags/nondeterministic1_trail.i.re diff --git a/re2c/test/tags/minimization.i.c b/re2c/test/tags/minimization.i.c new file mode 100644 index 00000000..83044b25 --- /dev/null +++ b/re2c/test/tags/minimization.i.c @@ -0,0 +1,66 @@ +/* Generated by re2c */ +// Rules are the same except for the tag in the 2nd case. +// In the 1st case common tail "a" is deduplicated after DFA minimization. +// In the 2nd case tag prevents minimization. + + +{ + YYCTYPE yych; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch (yych) { + case 'b': + case 'c': goto yy4; + default: goto yy2; + } +yy2: + ++YYCURSOR; +yy3: + {} +yy4: + yych = *++YYCURSOR; + switch (yych) { + case 'a': goto yy5; + default: goto yy3; + } +yy5: + ++YYCURSOR; + {} +} + + + +{ + YYCTYPE yych; + long yytag0p; + YYCTXMARKER = YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch (yych) { + case 'b': goto yy11; + case 'c': goto yy12; + default: goto yy9; + } +yy9: + ++YYCURSOR; +yy10: + {} +yy11: + yych = *++YYCURSOR; + switch (yych) { + case 'a': + yytag0p = (YYCURSOR - YYCTXMARKER); + goto yy13; + default: goto yy10; + } +yy12: + yych = *++YYCURSOR; + switch (yych) { + case 'a': goto yy13; + default: goto yy10; + } +yy13: + ++YYCURSOR; + { (YYCTXMARKER + yytag0p) } +} + diff --git a/re2c/test/tags/minimization.i.re b/re2c/test/tags/minimization.i.re new file mode 100644 index 00000000..949b0c4b --- /dev/null +++ b/re2c/test/tags/minimization.i.re @@ -0,0 +1,14 @@ +// Rules are the same except for the tag in the 2nd case. +// In the 1st case common tail "a" is deduplicated after DFA minimization. +// In the 2nd case tag prevents minimization. + +/*!re2c + "ba" | "ca" {} + * {} +*/ + +/*!re2c + re2c:flags:tags = 1; + "b" @p "a" | "ca" { @p } + * {} +*/ diff --git a/re2c/test/tags/nondet_alt1.--tags.c b/re2c/test/tags/nondet_alt1.--tags.c new file mode 100644 index 00000000..47a58ddd --- /dev/null +++ b/re2c/test/tags/nondet_alt1.--tags.c @@ -0,0 +1 @@ +re2c: error: line 2: tag 'p' is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondet_alt1.--tags.re b/re2c/test/tags/nondet_alt1.--tags.re new file mode 100644 index 00000000..b461e58c --- /dev/null +++ b/re2c/test/tags/nondet_alt1.--tags.re @@ -0,0 +1,4 @@ +/*!re2c + "a" @p | "a" { @p } + * {} +*/ diff --git a/re2c/test/tags/nondet_alt2.--tags.c b/re2c/test/tags/nondet_alt2.--tags.c new file mode 100644 index 00000000..47a58ddd --- /dev/null +++ b/re2c/test/tags/nondet_alt2.--tags.c @@ -0,0 +1 @@ +re2c: error: line 2: tag 'p' is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondet_alt2.--tags.re b/re2c/test/tags/nondet_alt2.--tags.re new file mode 100644 index 00000000..1d8d78a5 --- /dev/null +++ b/re2c/test/tags/nondet_alt2.--tags.re @@ -0,0 +1,4 @@ +/*!re2c + @p "a" | "a" { @p } + * {} +*/ diff --git a/re2c/test/tags/nondet_cat1.--tags.c b/re2c/test/tags/nondet_cat1.--tags.c new file mode 100644 index 00000000..47a58ddd --- /dev/null +++ b/re2c/test/tags/nondet_cat1.--tags.c @@ -0,0 +1 @@ +re2c: error: line 2: tag 'p' is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondet_cat1.--tags.re b/re2c/test/tags/nondet_cat1.--tags.re new file mode 100644 index 00000000..1caed3a5 --- /dev/null +++ b/re2c/test/tags/nondet_cat1.--tags.re @@ -0,0 +1,4 @@ +/*!re2c + "a"+ @p "a"+ { @p } + * {} +*/ diff --git a/re2c/test/tags/nondet_cat2.c b/re2c/test/tags/nondet_cat2.c new file mode 100644 index 00000000..d9137ba0 --- /dev/null +++ b/re2c/test/tags/nondet_cat2.c @@ -0,0 +1,2 @@ +re2c: error: line 7: trailing context is nondeterministic [-Werror-nondeterministic-tags] +re2c: warning: line 13: trailing context is nondeterministic [-Wnondeterministic-tags] diff --git a/re2c/test/tags/nondet_cat2.re b/re2c/test/tags/nondet_cat2.re new file mode 100644 index 00000000..8707367e --- /dev/null +++ b/re2c/test/tags/nondet_cat2.re @@ -0,0 +1,15 @@ +// The same rules, nondeterministic trailing context, with different configurations: +// 1. tags: error +// 2. no tags: warning + +/*!re2c + re2c:flags:tags = 1; + "a"+ / "a"+ {} + * {} +*/ + +/*!re2c + re2c:flags:tags = 0; + "a"+ / "a"+ {} + * {} +*/ diff --git a/re2c/test/tags/nondet_cat3.i.c b/re2c/test/tags/nondet_cat3.i.c new file mode 100644 index 00000000..712f5afd --- /dev/null +++ b/re2c/test/tags/nondet_cat3.i.c @@ -0,0 +1,147 @@ +/* Generated by re2c */ +// The same rules, fixed length trailing context, with different configurations: +// 1. default input API, no tags: no warning (no variable, static offset) +// 2. default input API, tags: no warning (no variable, static offset) +// 3. generic input API, no tags: warning (need variable: lack API to to make use of fixed length) +// 4. generic input API, tags: no warning (no variable, static offset) + + +{ + YYCTYPE yych; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: goto yy2; + } +yy2: + ++YYCURSOR; +yy3: + {} +yy4: + yych = *++YYCURSOR; + switch (yych) { + case 'a': goto yy5; + default: goto yy3; + } +yy5: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy5; + default: goto yy7; + } +yy7: + YYCURSOR -= 1; + {} +} + + + +{ + YYCTYPE yych; + YYCTXMARKER = YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy12; + default: goto yy10; + } +yy10: + ++YYCURSOR; +yy11: + {} +yy12: + yych = *++YYCURSOR; + switch (yych) { + case 'a': goto yy13; + default: goto yy11; + } +yy13: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy13; + default: goto yy15; + } +yy15: + YYCURSOR -= 1; + {} +} + + + +{ + YYCTYPE yych; + if (YYLESSTHAN (2)) YYFILL(2); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy20; + default: goto yy18; + } +yy18: + YYSKIP (); +yy19: + {} +yy20: + YYSKIP (); + yych = YYPEEK (); + switch (yych) { + case 'a': + YYBACKUPCTX (); + goto yy21; + default: goto yy19; + } +yy21: + YYSKIP (); + if (YYLESSTHAN (1)) YYFILL(1); + yych = YYPEEK (); + switch (yych) { + case 'a': + YYBACKUPCTX (); + goto yy21; + default: goto yy23; + } +yy23: + YYRESTORECTX (); + {} +} + + + +{ + YYCTYPE yych; + YYBACKUPCTX (); + if (YYLESSTHAN (2)) YYFILL(2); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy28; + default: goto yy26; + } +yy26: + YYSKIP (); +yy27: + {} +yy28: + YYSKIP (); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy29; + default: goto yy27; + } +yy29: + YYSKIP (); + if (YYLESSTHAN (1)) YYFILL(1); + yych = YYPEEK (); + switch (yych) { + case 'a': goto yy29; + default: goto yy31; + } +yy31: + YYRESTORECTX (YYDIST() - 1); + {} +} + +re2c: warning: line 24: trailing context is nondeterministic [-Wnondeterministic-tags] diff --git a/re2c/test/tags/nondet_cat3.i.re b/re2c/test/tags/nondet_cat3.i.re new file mode 100644 index 00000000..784164a9 --- /dev/null +++ b/re2c/test/tags/nondet_cat3.i.re @@ -0,0 +1,33 @@ +// The same rules, fixed length trailing context, with different configurations: +// 1. default input API, no tags: no warning (no variable, static offset) +// 2. default input API, tags: no warning (no variable, static offset) +// 3. generic input API, no tags: warning (need variable: lack API to to make use of fixed length) +// 4. generic input API, tags: no warning (no variable, static offset) + +/*!re2c + re2c:flags:input = default; + re2c:flags:tags = 0; + "a"+ / "a" {} + * {} +*/ + +/*!re2c + re2c:flags:input = default; + re2c:flags:tags = 1; + "a"+ / "a" {} + * {} +*/ + +/*!re2c + re2c:flags:input = custom; + re2c:flags:tags = 0; + "a"+ / "a" {} + * {} +*/ + +/*!re2c + re2c:flags:input = custom; + re2c:flags:tags = 1; + "a"+ / "a" {} + * {} +*/ diff --git a/re2c/test/tags/nondet_cat4.--tags.c b/re2c/test/tags/nondet_cat4.--tags.c new file mode 100644 index 00000000..3da022eb --- /dev/null +++ b/re2c/test/tags/nondet_cat4.--tags.c @@ -0,0 +1 @@ +re2c: error: line 4: tag 'p' is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondet_cat4.--tags.re b/re2c/test/tags/nondet_cat4.--tags.re new file mode 100644 index 00000000..a5fe9816 --- /dev/null +++ b/re2c/test/tags/nondet_cat4.--tags.re @@ -0,0 +1,6 @@ +// Tag is nondeterministic: fixed length helps only in top-level + +/*!re2c + "a"+ @p "a" | "b" { @p } + * {} +*/ diff --git a/re2c/test/tags/nondeterministic1.i--tags.c b/re2c/test/tags/nondeterministic1.i--tags.c deleted file mode 100644 index 6647a34e..00000000 --- a/re2c/test/tags/nondeterministic1.i--tags.c +++ /dev/null @@ -1 +0,0 @@ -re2c: error: line 13: tag 'p1' is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondeterministic1.i--tags.re b/re2c/test/tags/nondeterministic1.i--tags.re deleted file mode 100644 index a88a744e..00000000 --- a/re2c/test/tags/nondeterministic1.i--tags.re +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -static void lex(const char *YYCURSOR) -{ - const char *YYMARKER; - const char *YYCTXMARKER; - /*!re2c - re2c:define:YYCTYPE = char; - re2c:yyfill:enable = 0; - - * { printf("error\n"); return; } - "a"+ @p1 "a"+ { - printf("'%.*s', '%.*s'\n", - @p1 - YYCTXMARKER, YYCTXMARKER, - YYCURSOR - @p1, @p1); - return; - } - */ -} - -int main(int argc, char **argv) -{ - for (int i = 1; i < argc; ++i) { - lex(argv[i]); - } - return 0; -} diff --git a/re2c/test/tags/nondeterministic1_trail.i--tags.c b/re2c/test/tags/nondeterministic1_trail.i--tags.c deleted file mode 100644 index 4844e830..00000000 --- a/re2c/test/tags/nondeterministic1_trail.i--tags.c +++ /dev/null @@ -1 +0,0 @@ -re2c: error: line 13: trailing context is nondeterministic [-Werror-nondeterministic-tags] diff --git a/re2c/test/tags/nondeterministic1_trail.i--tags.re b/re2c/test/tags/nondeterministic1_trail.i--tags.re deleted file mode 100644 index 5f1b9623..00000000 --- a/re2c/test/tags/nondeterministic1_trail.i--tags.re +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -static void lex(const char *YYCURSOR) -{ - const char *YYMARKER; - const char *YYCTXMARKER; - /*!re2c - re2c:define:YYCTYPE = char; - re2c:yyfill:enable = 0; - - * { printf("error\n"); return; } - "" @p0 "a"+ / "a"+ { - printf("'%.*s', '%s'\n", - YYCURSOR - @p0, @p0, - YYCURSOR); - return; - } - */ -} - -int main(int argc, char **argv) -{ - for (int i = 1; i < argc; ++i) { - lex(argv[i]); - } - return 0; -} diff --git a/re2c/test/tags/nondeterministic1_trail.i.c b/re2c/test/tags/nondeterministic1_trail.i.c deleted file mode 100644 index 7dbebbc4..00000000 --- a/re2c/test/tags/nondeterministic1_trail.i.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Generated by re2c */ -#include -#include - -static void lex(const char *YYCURSOR) -{ - const char *YYCTXMARKER; - const char *token = YYCURSOR; - -{ - char yych; - yych = *YYCURSOR; - switch (yych) { - case 'a': goto yy4; - default: goto yy2; - } -yy2: - ++YYCURSOR; -yy3: - { printf("error\n"); return; } -yy4: - yych = *++YYCURSOR; - switch (yych) { - case 'a': - YYCTXMARKER = YYCURSOR; - goto yy5; - default: goto yy3; - } -yy5: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case 'a': - YYCTXMARKER = YYCURSOR; - goto yy5; - default: goto yy7; - } -yy7: - YYCURSOR = YYCTXMARKER; - { - printf("'%.*s', '%s'\n", - YYCURSOR - token, token, - YYCURSOR); - return; - } -} - -} - -int main(int argc, char **argv) -{ - for (int i = 1; i < argc; ++i) { - lex(argv[i]); - } - return 0; -} -re2c: warning: line 13: trailing context is nondeterministic [-Wnondeterministic-tags] diff --git a/re2c/test/tags/nondeterministic1_trail.i.re b/re2c/test/tags/nondeterministic1_trail.i.re deleted file mode 100644 index 32db9cbd..00000000 --- a/re2c/test/tags/nondeterministic1_trail.i.re +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -static void lex(const char *YYCURSOR) -{ - const char *YYCTXMARKER; - const char *token = YYCURSOR; - /*!re2c - re2c:define:YYCTYPE = char; - re2c:yyfill:enable = 0; - - * { printf("error\n"); return; } - "a"+ / "a"+ { - printf("'%.*s', '%s'\n", - YYCURSOR - token, token, - YYCURSOR); - return; - } - */ -} - -int main(int argc, char **argv) -{ - for (int i = 1; i < argc; ++i) { - lex(argv[i]); - } - return 0; -} -- 2.40.0