Skip to content

Commit 99b65bd

Browse files
committed
Merge remote-tracking branch 'antlr/master' into optimized
2 parents c2e3dec + b57843d commit 99b65bd

File tree

11 files changed

+74
-12
lines changed

11 files changed

+74
-12
lines changed

runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParserErrors/InvalidEmptyInput.stg

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Rule() ::= "start"
2020
Output() ::= ""
2121

2222
Errors() ::= <<
23-
line 1:0 missing ID at '\<EOF>'<\n>
23+
line 1:0 mismatched input '\<EOF>' expecting ID<\n>
2424
>>
2525

2626
grammar(grammarName) ::= <<

runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParserErrors/SingleTokenDeletionBeforeLoop.stg

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ line 1:3 token recognition error at: 'c'<\n>
2222

2323
grammar(grammarName) ::= <<
2424
grammar <grammarName>;
25-
a : 'a' 'b'* ;
25+
a : 'a' 'b'* EOF ;
2626
>>

runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParserErrors/SingleTokenDeletionBeforeLoop2.stg

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ line 1:3 token recognition error at: 'c'<\n>
2222

2323
grammar(grammarName) ::= <<
2424
grammar <grammarName>;
25-
a : 'a' ('b'|'z'{<Pass()>})*;
25+
a : 'a' ('b'|'z'{<Pass()>})* EOF ;
2626
>>

runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParserExec/Index.stg

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ TestTemplates ::= [
3131
"MultipleEOFHandling": [],
3232
"EOFInClosure": [],
3333
"ReferenceToATN_1": [],
34-
"ReferenceToATN_2": []
34+
"ReferenceToATN_2": [],
3535
//"AlternateQuotes": []
36+
"OpenDeviceStatement_1": [],
37+
"OpenDeviceStatement_2": [],
38+
"OpenDeviceStatement_3": []
3639
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This is a regression test for antlr/antlr4#1545.
3+
*/
4+
5+
TestType() ::= "Parser"
6+
7+
Options ::= [
8+
"Debug": false
9+
]
10+
11+
Rule() ::= "statement"
12+
13+
Output() ::= "OPEN DEVICE DEVICE<\n>"
14+
15+
Errors() ::= ""
16+
17+
grammar(grammarName, opt1) ::= <<
18+
grammar <grammarName>;
19+
program : statement+ '.' ;
20+
21+
statement : 'OPEN' ( 'DEVICE' ( <opt1> | OPT2 | OPT3 )? )+ {<writeln("$text")>} ;
22+
23+
OPT1 : 'OPT-1';
24+
OPT2 : 'OPT-2';
25+
OPT3 : 'OPT-3';
26+
27+
WS : (' '|'\n')+ -> channel(HIDDEN);
28+
>>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* This is a regression test for antlr/antlr4#1545, case 1.
3+
*/
4+
5+
import "OpenDeviceStatement.stg"
6+
7+
Grammar ::= [
8+
"OpenDeviceStatement": {<grammar("OpenDeviceStatement", "OPT1")>}
9+
]
10+
11+
Input() ::= "OPEN DEVICE DEVICE"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* This is a regression test for antlr/antlr4#1545, case 2.
3+
*/
4+
5+
import "OpenDeviceStatement.stg"
6+
7+
Grammar ::= [
8+
"OpenDeviceStatement": {<grammar("OpenDeviceStatement", "(OPT1)")>}
9+
]
10+
11+
Input() ::= "OPEN DEVICE DEVICE"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* This is a regression test for antlr/antlr4#1545, case 3.
3+
*/
4+
5+
import "OpenDeviceStatement.stg"
6+
7+
Grammar ::= [
8+
"OpenDeviceStatement": {<grammar("OpenDeviceStatement", "(OPT1)")>}
9+
]
10+
11+
Input() ::= "OPEN DEVICE DEVICE ."

runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,8 @@ public void sync(Parser recognizer) throws RecognitionException {
231231
int la = tokens.LA(1);
232232

233233
// try cheaper subset first; might get lucky. seems to shave a wee bit off
234-
if ( recognizer.getATN().nextTokens(s).contains(la) || la==Token.EOF ) return;
235-
236-
// Return but don't end recovery. only do that upon valid token match
237-
if (recognizer.isExpectedToken(la)) {
234+
IntervalSet nextTokens = recognizer.getATN().nextTokens(s);
235+
if (nextTokens.contains(Token.EPSILON) || nextTokens.contains(la)) {
238236
return;
239237
}
240238

tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ switch (_input.LA(1)) {
529529
<alt>
530530
break;}; separator="\n">
531531
default:
532-
<error>
532+
break;
533533
}
534534
>>
535535

tool/test/org/antlr/v4/test/tool/TestParseErrors.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public class TestParseErrors extends BaseTest {
125125
@Test public void testSingleTokenDeletionBeforeLoop() throws Exception {
126126
String grammar =
127127
"grammar T;\n" +
128-
"a : 'a' 'b'*;";
128+
"a : 'a' 'b'* EOF ;";
129129
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
130130
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b'}\n" +
131131
"line 1:3 token recognition error at: 'c'\n";
@@ -172,7 +172,7 @@ public class TestParseErrors extends BaseTest {
172172
@Test public void testSingleTokenDeletionBeforeLoop2() throws Exception {
173173
String grammar =
174174
"grammar T;\n" +
175-
"a : 'a' ('b'|'z'{;})*;";
175+
"a : 'a' ('b'|'z'{;})* EOF ;";
176176
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
177177
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" +
178178
"line 1:3 token recognition error at: 'c'\n";
@@ -249,7 +249,7 @@ public void testInvalidEmptyInput() throws Exception {
249249
String result = execParser("T.g4", grammar, "TParser", "TLexer", "start", "", true);
250250
String expecting = "";
251251
assertEquals(expecting, result);
252-
assertEquals("line 1:0 missing ID at '<EOF>'\n", this.stderrDuringParse);
252+
assertEquals("line 1:0 mismatched input '<EOF>' expecting ID\n", this.stderrDuringParse);
253253
}
254254

255255
/**

0 commit comments

Comments
 (0)