From 0c1e034856231e0c38b1ffa7cf43a035a789bbd1 Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Sat, 4 Mar 2017 11:58:55 +0000 Subject: [PATCH] Added test for '--posix-captures': implicit grouping is forbidden. RE2C has named definitions, which allow to override operator precedence without grouping parenthesis. However, in POSIX all parenthesis are capturing: allowing some of them to be non-capturing would affect disambiguation and might result in a different parse. For now RE2C uses a crude criterion to determine if the given named definition needs to be explicitely wrapped in parenthesis: if the topmost constructor of the subexpression is either alternative, or catenation, or another reference to another named definition, then wrapping is required. This is an overapproximation, because it doesn't take the surrounding context into account (e.g. catenation inside of an alternative doesn't need wrapping, but catenation inside of an iteration does). --- .../implicit_grouping1.i--posix-captures.c | 1 + .../implicit_grouping1.i--posix-captures.re | 4 ++ .../implicit_grouping2.i--posix-captures.c | 51 +++++++++++++++++++ .../implicit_grouping2.i--posix-captures.re | 4 ++ .../implicit_grouping3.i--posix-captures.c | 51 +++++++++++++++++++ .../implicit_grouping3.i--posix-captures.re | 4 ++ 6 files changed, 115 insertions(+) create mode 100644 re2c/test/posix_captures/implicit_grouping1.i--posix-captures.c create mode 100644 re2c/test/posix_captures/implicit_grouping1.i--posix-captures.re create mode 100644 re2c/test/posix_captures/implicit_grouping2.i--posix-captures.c create mode 100644 re2c/test/posix_captures/implicit_grouping2.i--posix-captures.re create mode 100644 re2c/test/posix_captures/implicit_grouping3.i--posix-captures.c create mode 100644 re2c/test/posix_captures/implicit_grouping3.i--posix-captures.re diff --git a/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.c b/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.c new file mode 100644 index 00000000..e136f1dd --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.c @@ -0,0 +1 @@ +re2c: error: implicit grouping is forbidden with '--posix-captures' option, please wrap 'x' in capturing parenthesis diff --git a/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.re b/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.re new file mode 100644 index 00000000..8b9ff1df --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping1.i--posix-captures.re @@ -0,0 +1,4 @@ +/*!re2c + x = "a" | "aa"; + x* {} +*/ diff --git a/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.c b/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.c new file mode 100644 index 00000000..65b749a4 --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.c @@ -0,0 +1,51 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt1 = yyt3 = YYCURSOR; + goto yy3; + default: + yyt2 = yyt3 = NULL; + yyt1 = YYCURSOR; + goto yy2; + } +yy2: + { + const size_t yynmatch = 2; + const YYCTYPE *yypmatch[yynmatch * 2]; + yypmatch[0] = yyt1; + yypmatch[3] = yyt2; + yypmatch[1] = YYCURSOR; + yypmatch[2] = yyt3; + {} + } +yy3: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: + yyt2 = YYCURSOR; + goto yy2; + } +yy4: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy3; + default: + yyt2 = YYCURSOR; + goto yy2; + } +} + +re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string] +re2c: warning: line 3: trailing context is non-deterministic and induces 2 parallel instances [-Wnondeterministic-tags] diff --git a/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.re b/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.re new file mode 100644 index 00000000..0be75ab1 --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping2.i--posix-captures.re @@ -0,0 +1,4 @@ +/*!re2c + x = "a" | "aa"; + (x)* {} +*/ diff --git a/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.c b/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.c new file mode 100644 index 00000000..65b749a4 --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.c @@ -0,0 +1,51 @@ +/* Generated by re2c */ + +{ + YYCTYPE yych; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt1 = yyt3 = YYCURSOR; + goto yy3; + default: + yyt2 = yyt3 = NULL; + yyt1 = YYCURSOR; + goto yy2; + } +yy2: + { + const size_t yynmatch = 2; + const YYCTYPE *yypmatch[yynmatch * 2]; + yypmatch[0] = yyt1; + yypmatch[3] = yyt2; + yypmatch[1] = YYCURSOR; + yypmatch[2] = yyt3; + {} + } +yy3: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': goto yy4; + default: + yyt2 = YYCURSOR; + goto yy2; + } +yy4: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; + switch (yych) { + case 'a': + yyt3 = YYCURSOR; + goto yy3; + default: + yyt2 = YYCURSOR; + goto yy2; + } +} + +re2c: warning: line 3: rule matches empty string [-Wmatch-empty-string] +re2c: warning: line 3: trailing context is non-deterministic and induces 2 parallel instances [-Wnondeterministic-tags] diff --git a/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.re b/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.re new file mode 100644 index 00000000..b62a6bc4 --- /dev/null +++ b/re2c/test/posix_captures/implicit_grouping3.i--posix-captures.re @@ -0,0 +1,4 @@ +/*!re2c + x = ("a" | "aa"); + x* {} +*/ -- 2.40.0