Skip to content

Commit

Permalink
Merge pull request #991 from michaelpj/sync-before-predict
Browse files Browse the repository at this point in the history
Reinstitute `sync` calls before `adaptivePredict`
  • Loading branch information
parrt committed Nov 19, 2015
2 parents 3fa8cfe + 42cb08f commit 05b5032
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ TestTemplates ::= [
"LL2": [],
"LL3": [],
"LLStar": [],
"SingleTokenDeletionBeforeAlt": [],
"SingleTokenDeletionBeforePredict": [],
"SingleTokenDeletionBeforeLoop": [],
"MultiTokenDeletionBeforeLoop": [],
"SingleTokenDeletionDuringLoop": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TestType() ::= "Parser"

Options ::= [
"Debug": false
]

Grammar ::= [
"T": {<grammar("T")>}
]

Input() ::= "ac"

Rule() ::= "a"

Output() ::= <<
>>

Errors() ::= <<
line 1:0 extraneous input 'a' expecting {'b', 'c'}<\n>
>>

grammar(grammarName) ::= <<
grammar <grammarName>;
a : ('b' | 'c')
;
q : 'a'
;
>>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
TestType() ::= "Parser"

Options ::= [
"Debug": false
]

Grammar ::= [
"T": {<grammar("T")>}
]

Input() ::= "caaab"

Rule() ::= "a"

Output() ::= <<
>>

Errors() ::= <<
line 1:0 extraneous input 'c' expecting 'a'<\n>
>>

grammar(grammarName) ::= <<
grammar <grammarName>;
a : 'a'+ 'b'
| 'a'+ 'c'
;
q : 'e' ;
>>
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,24 @@ public void testSingleTokenDeletion() throws Exception {

assertEquals("line 1:1 extraneous input 'a' expecting 'b'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeAlt() throws Exception {
mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(38);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('b' | 'c')\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'a'\n");
grammarBuilder.append(";");
String grammar = grammarBuilder.toString();
String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
Expand Down Expand Up @@ -404,6 +422,24 @@ public void testSingleTokenDeletionBeforeLoop2() throws Exception {
"line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" +
"line 1:3 token recognition error at: 'c'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforePredict() throws Exception {
mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(48);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : 'a'+ 'b'\n");
grammarBuilder.append(" | 'a'+ 'c'\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'e' ;");
String grammar = grammarBuilder.toString();
String input ="caaab";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,28 @@ public void testSingleTokenDeletion() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeAlt() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(38);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('b' | 'c')\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'a'\n");
grammarBuilder.append(";");
String grammar = grammarBuilder.toString();


String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeLoop() throws Exception {
Expand Down Expand Up @@ -498,6 +520,28 @@ public void testSingleTokenDeletionBeforeLoop2() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforePredict() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(48);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : 'a'+ 'b'\n");
grammarBuilder.append(" | 'a'+ 'c'\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'e' ;");
String grammar = grammarBuilder.toString();


String input ="caaab";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionConsumption() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,26 @@ public void testSingleTokenDeletion() throws Exception {

assertEquals("line 1:1 extraneous input 'a' expecting 'b'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeAlt() throws Exception {
mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(38);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('b' | 'c')\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'a'\n");
grammarBuilder.append(";");
String grammar = grammarBuilder.toString();
String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
"TListener", "TVisitor",
"a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
Expand Down Expand Up @@ -452,6 +472,26 @@ public void testSingleTokenDeletionBeforeLoop2() throws Exception {
"line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" +
"line 1:3 token recognition error at: 'c'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforePredict() throws Exception {
mkdir(tmpdir);
StringBuilder grammarBuilder = new StringBuilder(48);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : 'a'+ 'b'\n");
grammarBuilder.append(" | 'a'+ 'c'\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'e' ;");
String grammar = grammarBuilder.toString();
String input ="caaab";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
"TListener", "TVisitor",
"a", input, false);
assertEquals("", found);

assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);

}
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,29 @@ public void testSingleTokenDeletion() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeAlt() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(38);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('b' | 'c')\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'a'\n");
grammarBuilder.append(";");
String grammar = grammarBuilder.toString();


String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false);

assertEquals("", found);

assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeLoop() throws Exception {
Expand Down Expand Up @@ -520,6 +543,29 @@ public void testSingleTokenDeletionBeforeLoop2() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforePredict() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(48);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : 'a'+ 'b'\n");
grammarBuilder.append(" | 'a'+ 'c'\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'e' ;");
String grammar = grammarBuilder.toString();


String input ="caaab";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false);

assertEquals("", found);

assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionConsumption() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,29 @@ public void testSingleTokenDeletion() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeAlt() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(38);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('b' | 'c')\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'a'\n");
grammarBuilder.append(";");
String grammar = grammarBuilder.toString();


String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false);

assertEquals("", found);

assertEquals("line 1:0 extraneous input 'a' expecting {'b', 'c'}\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforeLoop() throws Exception {
Expand Down Expand Up @@ -520,6 +543,29 @@ public void testSingleTokenDeletionBeforeLoop2() throws Exception {

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionBeforePredict() throws Exception {
mkdir(tmpdir);

StringBuilder grammarBuilder = new StringBuilder(48);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : 'a'+ 'b'\n");
grammarBuilder.append(" | 'a'+ 'c'\n");
grammarBuilder.append(";\n");
grammarBuilder.append("q : 'e' ;");
String grammar = grammarBuilder.toString();


String input ="caaab";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", input, false);

assertEquals("", found);

assertEquals("line 1:0 extraneous input 'c' expecting 'a'\n", this.stderrDuringParse);

}

/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void testSingleTokenDeletionConsumption() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= <<

LL1AltBlock(choice, preamble, alts, error) ::= <<
State = <choice.stateNumber>;
<!ErrorHandler.sync(this);!>
<if(choice.label)><labelref(choice.label)> = TokenStream.Lt(1);<endif>
<preamble; separator="\n">
switch (TokenStream.La(1)) {
Expand All @@ -551,7 +550,6 @@ default:

LL1OptionalBlock(choice, alts, error) ::= <<
State = <choice.stateNumber>;
<!ErrorHandler.sync(this);!>
switch (TokenStream.La(1)) {
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
<alt>
Expand All @@ -563,7 +561,6 @@ default:

LL1OptionalBlockSingleAlt(choice, expr, alts, preamble, error, followExpr) ::= <<
State = <choice.stateNumber>;
<!ErrorHandler.sync(this);!>
<preamble; separator="\n">
if (<expr>) {
<alts; separator="\n">
Expand Down Expand Up @@ -599,7 +596,7 @@ do {

AltBlock(choice, preamble, alts, error) ::= <<
State = <choice.stateNumber>;
<!ErrorHandler.sync(this);!>
ErrorHandler.Sync(this);
<if(choice.label)><labelref(choice.label)> = TokenStream.Lt(1);<endif>
<preamble; separator="\n">
switch ( Interpreter.AdaptivePredict(TokenStream,<choice.decision>,Context) ) {
Expand All @@ -612,7 +609,7 @@ case <i>:

OptionalBlock(choice, alts, error) ::= <<
State = <choice.stateNumber>;
<!ErrorHandler.sync(this);!>
ErrorHandler.Sync(this);
switch ( Interpreter.AdaptivePredict(TokenStream,<choice.decision>,Context) ) {
<alts:{alt |
case <i><if(!choice.ast.greedy)>+1<endif>:
Expand Down
Loading

0 comments on commit 05b5032

Please sign in to comment.