Add tests for alternative precedence in left-recursive transformation
This commit is contained in:
parent
d0fb48c2b8
commit
b1b2579621
|
@ -59,6 +59,8 @@ TestTemplates ::= [
|
|||
"MultipleAlternativesWithCommonLabel_2": [],
|
||||
"MultipleAlternativesWithCommonLabel_3": [],
|
||||
"MultipleAlternativesWithCommonLabel_4": [],
|
||||
"PrefixAndOtherAlt_1": [],
|
||||
"PrefixAndOtherAlt_2": [],
|
||||
"PrefixOpWithActionAndLabel_1": [],
|
||||
"PrefixOpWithActionAndLabel_2": [],
|
||||
"PrefixOpWithActionAndLabel_3": [],
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : expr EOF ;
|
||||
expr : literal
|
||||
| op expr
|
||||
| expr op expr
|
||||
;
|
||||
literal : '-'? Integer ;
|
||||
op : '+' | '-' ;
|
||||
Integer : [0-9]+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,9 @@
|
|||
import "PrefixAndOtherAlt.stg"
|
||||
|
||||
Input() ::= "-1"
|
||||
|
||||
Output() ::= <<
|
||||
(s (expr (literal - 1)) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "PrefixAndOtherAlt.stg"
|
||||
|
||||
Input() ::= "-1 + -1"
|
||||
|
||||
Output() ::= <<
|
||||
(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1801,6 +1801,50 @@ public class TestLeftRecursion extends BaseTest {
|
|||
assertEquals("(prog (statement (letterA a)) (statement (letterA a)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {Console.WriteLine($ctx.ToStringTree(this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="-1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals("(s (expr (literal - 1)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {Console.WriteLine($ctx.ToStringTree(this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="-1 + -1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals("(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
|
|
|
@ -2007,6 +2007,58 @@ public class TestLeftRecursion extends BaseTest {
|
|||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {System.out.println($ctx.toStringTree(this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals("(s (expr (literal - 1)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {System.out.println($ctx.toStringTree(this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1 + -1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals("(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixOpWithActionAndLabel_1() throws Exception {
|
||||
|
|
|
@ -1905,6 +1905,54 @@ public class TestLeftRecursion extends BaseTest {
|
|||
assertEquals("(prog (statement (letterA a)) (statement (letterA a)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {console.log($ctx.toStringTree(null, this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="-1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals("(s (expr (literal - 1)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {console.log($ctx.toStringTree(null, this));} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="-1 + -1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals("(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
|
|
|
@ -2058,6 +2058,60 @@ public class TestLeftRecursion extends BasePython2Test {
|
|||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {print($ctx.toStringTree(recog=self))} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals("(s (expr (literal - 1)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {print($ctx.toStringTree(recog=self))} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1 + -1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals("(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixOpWithActionAndLabel_1() throws Exception {
|
||||
|
|
|
@ -2058,6 +2058,60 @@ public class TestLeftRecursion extends BasePython3Test {
|
|||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {print($ctx.toStringTree(recog=self))} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals("(s (expr (literal - 1)) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixAndOtherAlt_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {print($ctx.toStringTree(recog=self))} : expr EOF ; \n");
|
||||
grammarBuilder.append("expr : literal\n");
|
||||
grammarBuilder.append(" | op expr\n");
|
||||
grammarBuilder.append(" | expr op expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("literal : '-'? Integer ;\n");
|
||||
grammarBuilder.append("op : '+' | '-' ;\n");
|
||||
grammarBuilder.append("Integer : [0-9]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="-1 + -1";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals("(s (expr (expr (literal - 1)) (op +) (expr (literal - 1))) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testPrefixOpWithActionAndLabel_1() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue