forked from jasder/antlr
TestParserExec for Java is working
This commit is contained in:
parent
c9c32c2c4f
commit
4fa9ed5a6b
|
@ -5,6 +5,7 @@ TestFolders ::= [
|
|||
"LexerExec": [],
|
||||
"Listeners": [],
|
||||
"ParserErrors": [],
|
||||
"ParserExec": [],
|
||||
"ParseTrees": [],
|
||||
"SemPredEvalLexer": [],
|
||||
"SemPredEvalParser": []
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a b c"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
abc<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : ID+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,20 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : ID* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "AStar.stg"
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Output() ::= "<\n>"
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "AStar.stg"
|
||||
|
||||
Input() ::= "a b c"
|
||||
|
||||
Output() ::= <<
|
||||
abc<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,42 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Options ::= [
|
||||
"SlaveIsLexer": true,
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"ModeTagsParser": {<grammar("ModeTagsParser", "ModeTagsLexer")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"ModeTagsLexer": {<slaveGrammar("ModeTagsLexer")>}
|
||||
]
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Rule() ::= "file_"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName, slaveGrammarName) ::= <<
|
||||
parser grammar <grammarName>;
|
||||
options { tokenVocab=<slaveGrammarName>; } // use tokens from <slaveGrammarName>.g4
|
||||
file_: (tag | TEXT)* ;
|
||||
tag : '«' ID '»'
|
||||
| '«' '/' ID '»'
|
||||
;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
// Default mode rules (the SEA)
|
||||
OPEN : '«' -> mode(ISLAND) ; // switch to ISLAND mode
|
||||
TEXT : ~'«'+ ; // clump all text together
|
||||
mode ISLAND;
|
||||
CLOSE : '»' -> mode(DEFAULT_MODE) ; // back to SEA mode
|
||||
SLASH : '/' ;
|
||||
ID : [a-zA-Z]+ ; // match/send ID in tag to parser
|
||||
>>
|
|
@ -0,0 +1,28 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a b c"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
abc<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|ID)+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,26 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|ID)* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "AorAStar.stg"
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Output() ::= "<\n>"
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "AorAStar.stg"
|
||||
|
||||
Input() ::= "a b c"
|
||||
|
||||
Output() ::= <<
|
||||
abc<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "34"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
alt 2<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : ID {
|
||||
<writeln("\"alt 1\"")>
|
||||
} | INT {
|
||||
<writeln("\"alt 2\"")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,30 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a 34 c"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
a34c<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|INT{
|
||||
})+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,22 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|INT{
|
||||
})* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "AorBStar.stg"
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Output() ::= "<\n>"
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "AorBStar.stg"
|
||||
|
||||
Input() ::= "a 34 c"
|
||||
|
||||
Output() ::= <<
|
||||
a34c<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,29 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc 34"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
abc34<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : ID INT {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* This test ensures that {@link ParserATNSimulator} does not produce a
|
||||
* {@link StackOverflowError} when it encounters an {@code EOF} transition
|
||||
* inside a closure.
|
||||
*/
|
||||
|
||||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "x"
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
prog : stat EOF;
|
||||
stat : 'x' ('y' | EOF)*?;
|
||||
>>
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "if y if y x else x"
|
||||
|
||||
Rule() ::= "start"
|
||||
|
||||
Output() ::= <<
|
||||
if y x else x
|
||||
if y if y x else x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement)? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
||||
>>
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "if y if y x else x"
|
||||
|
||||
Rule() ::= "start"
|
||||
|
||||
Output() ::= <<
|
||||
if y x else x
|
||||
if y if y x else x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement|) {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
||||
>>
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "if y if y x else x"
|
||||
|
||||
Rule() ::= "start"
|
||||
|
||||
Output() ::= <<
|
||||
if y x
|
||||
if y if y x else x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement)?? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
||||
>>
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "if y if y x else x"
|
||||
|
||||
Rule() ::= "start"
|
||||
|
||||
Output() ::= <<
|
||||
if y x
|
||||
if y if y x else x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement (|'else' statement) {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
||||
>>
|
|
@ -0,0 +1,38 @@
|
|||
//TestFolders ::= [
|
||||
//]
|
||||
|
||||
TestTemplates ::= [
|
||||
"Labels": [],
|
||||
"ListLabelsOnSet": [],
|
||||
"AorB": [],
|
||||
"Basic": [],
|
||||
"APlus": [],
|
||||
"AorAPlus": [],
|
||||
"IfIfElseGreedyBinding1": [],
|
||||
"IfIfElseGreedyBinding2": [],
|
||||
"IfIfElseNonGreedyBinding1": [],
|
||||
"IfIfElseNonGreedyBinding2": [],
|
||||
"AStar_1": [],
|
||||
"AStar_2": [],
|
||||
"LL1OptionalBlock_1": [],
|
||||
"LL1OptionalBlock_2": [],
|
||||
"AorAStar_1": [],
|
||||
"AorAStar_2": [],
|
||||
"AorBPlus": [],
|
||||
"AorBStar_1": [],
|
||||
"AorBStar_2": [],
|
||||
"Optional_1": [],
|
||||
"Optional_2": [],
|
||||
"Optional_3": [],
|
||||
"Optional_4": [],
|
||||
"PredicatedIfIfElse": [],
|
||||
//"StartRuleWithoutEOF": [],
|
||||
"LabelAliasingAcrossLabeledAlternatives": [],
|
||||
"PredictionIssue334": [],
|
||||
"ListLabelForClosureContext": [],
|
||||
"MultipleEOFHandling": [],
|
||||
"EOFInClosure": [],
|
||||
"ReferenceToATN_1": [],
|
||||
"ReferenceToATN_2": []
|
||||
//"AlternateQuotes": []
|
||||
]
|
|
@ -0,0 +1,27 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|{}INT)? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "LL1OptionalBlock.stg"
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Output() ::= "<\n>"
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "LL1OptionalBlock.stg"
|
||||
|
||||
Input() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "xy"
|
||||
|
||||
Rule() ::= "start"
|
||||
|
||||
Output() ::= <<
|
||||
x
|
||||
y<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
start : a* EOF;
|
||||
a
|
||||
: label=subrule {<writeln("$label.text")>} #One
|
||||
| label='y' {<writeln("$label.text")>} #Two
|
||||
;
|
||||
subrule : 'x';
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,26 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc 34;"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : b1=b b2+=b* b3+=';' ;
|
||||
b : id_=ID val+=INT*;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -1,3 +1,22 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a"
|
||||
|
||||
Rule() ::= "expression"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
ifStatement
|
||||
@after {
|
||||
|
@ -18,3 +37,4 @@ elseIfStatement
|
|||
expression : 'a' ;
|
||||
executableStatement : 'a' ;
|
||||
elseStatement : 'a' ;
|
||||
>>
|
|
@ -0,0 +1,27 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc 34;"
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : b b* ';' ;
|
||||
b : ID val+=(INT | FLOAT)*;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
FLOAT : [0-9]+ '.' [0-9]+;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* This test ensures that {@link ParserATNSimulator} produces a correct
|
||||
* result when the grammar contains multiple explicit references to
|
||||
* {@code EOF} inside of parser rules.
|
||||
*/
|
||||
|
||||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "x"
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
prog : ('x' | 'x' 'y') EOF EOF;
|
||||
>>
|
|
@ -0,0 +1,18 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "stat"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
stat : ifstat | 'x';
|
||||
ifstat : 'if' stat ('else' stat)?;
|
||||
WS : [ \n\t]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "Optional.stg"
|
||||
|
||||
Input() ::= "x"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,7 @@
|
|||
import "Optional.stg"
|
||||
|
||||
Input() ::= "if x"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,7 @@
|
|||
import "Optional.stg"
|
||||
|
||||
Input() ::= "if x else x"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,7 @@
|
|||
import "Optional.stg"
|
||||
|
||||
Input() ::= "if if x else x"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,27 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "if x if x a else b"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s : stmt EOF ;
|
||||
stmt : ifStmt | ID;
|
||||
ifStmt : 'if' ID stmt ('else' stmt | { <LANotEquals("1", "ELSE")> }?);
|
||||
ELSE : 'else';
|
||||
ID : [a-zA-Z]+;
|
||||
WS : [ \\n\\t]+ -> skip;
|
||||
>>
|
|
@ -1,3 +1,24 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a"
|
||||
|
||||
Rule() ::= "file_"
|
||||
|
||||
Output() ::= <<
|
||||
(file_ (item a) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
file_ @init{
|
||||
<BailErrorStrategy()>
|
||||
|
@ -11,4 +32,4 @@ SEMICOLON: ';';
|
|||
A : 'a'|'A';
|
||||
B : 'b'|'B';
|
||||
WS : [ \r\t\n]+ -> skip;
|
||||
|
||||
>>
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* This is a regression test for antlr/antlr4#561 "Issue with parser
|
||||
* generation in 4.2.2"
|
||||
* https://github.com/antlr/antlr4/issues/561
|
||||
*/
|
||||
|
||||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
a : (ID|ATN_)* ATN_? {<writeln("$text")>} ;
|
||||
ID : 'a'..'z'+ ;
|
||||
ATN_ : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -0,0 +1,7 @@
|
|||
import "ReferenceToATN.stg"
|
||||
|
||||
Input() ::= ""
|
||||
|
||||
Output() ::= "<\n>"
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,9 @@
|
|||
import "ReferenceToATN.stg"
|
||||
|
||||
Input() ::= "a 34 c"
|
||||
|
||||
Output() ::= <<
|
||||
a34c<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,31 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc 34"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 0:
|
||||
s0-ID->s1
|
||||
s1-INT->s2
|
||||
s2-EOF->:s3=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after { <DumpDFA()> }
|
||||
: ID | ID INT ID ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\t'|'\n') -> skip;
|
||||
>>
|
|
@ -152,7 +152,6 @@ public class Generator {
|
|||
List<JUnitTestFile> list = new ArrayList<JUnitTestFile>();
|
||||
list.add(buildCompositeParsers());
|
||||
list.add(buildFullContextParsing());
|
||||
list.add(buildParserExec());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -307,71 +306,4 @@ public class Generator {
|
|||
return file;
|
||||
}
|
||||
|
||||
private JUnitTestFile buildParserExec() throws Exception {
|
||||
JUnitTestFile file = new JUnitTestFile("ParserExec");
|
||||
file.addParserTest(input, "Labels", "T", "a", "abc 34;", "", null);
|
||||
file.addParserTest(input, "ListLabelsOnSet", "T", "a", "abc 34;", "", null);
|
||||
file.addParserTest(input, "AorB", "T", "a", "34", "alt 2\n", null);
|
||||
file.addParserTest(input, "Basic", "T", "a", "abc 34", "abc34\n", null);
|
||||
file.addParserTest(input, "APlus", "T", "a", "a b c", "abc\n", null);
|
||||
file.addParserTest(input, "AorAPlus", "T", "a", "a b c", "abc\n", null);
|
||||
file.addParserTest(input, "IfIfElseGreedyBinding1", "T", "start",
|
||||
"if y if y x else x", "if y x else x\nif y if y x else x\n", null);
|
||||
file.addParserTest(input, "IfIfElseGreedyBinding2", "T", "start",
|
||||
"if y if y x else x", "if y x else x\nif y if y x else x\n", null);
|
||||
file.addParserTest(input, "IfIfElseNonGreedyBinding1", "T", "start",
|
||||
"if y if y x else x", "if y x\nif y if y x else x\n", null);
|
||||
file.addParserTest(input, "IfIfElseNonGreedyBinding2", "T", "start",
|
||||
"if y if y x else x", "if y x\nif y if y x else x\n", null);
|
||||
file.addParserTests(input, "AStar", "T", "a",
|
||||
"", "\n",
|
||||
"a b c", "abc\n");
|
||||
file.addParserTests(input, "LL1OptionalBlock", "T", "a",
|
||||
"", "\n",
|
||||
"a", "a\n");
|
||||
file.addParserTests(input, "AorAStar", "T", "a",
|
||||
"", "\n",
|
||||
"a b c", "abc\n");
|
||||
file.addParserTest(input, "AorBPlus", "T", "a", "a 34 c", "a34c\n", null);
|
||||
file.addParserTests(input, "AorBStar", "T", "a",
|
||||
"", "\n",
|
||||
"a 34 c", "a34c\n");
|
||||
file.addParserTests(input, "Optional", "T", "stat",
|
||||
"x", "",
|
||||
"if x", "",
|
||||
"if x else x", "",
|
||||
"if if x else x", "");
|
||||
file.addParserTest(input, "PredicatedIfIfElse", "T", "s", "if x if x a else b", "", null);
|
||||
/* file.addTest(input, "StartRuleWithoutEOF", "T", "s", "abc 34",
|
||||
"Decision 0:\n" + "s0-ID->s1\n" + "s1-INT->s2\n" + "s2-EOF->:s3=>1\n", null); */
|
||||
file.addParserTest(input, "LabelAliasingAcrossLabeledAlternatives", "T", "start", "xy", "x\ny\n", null);
|
||||
file.addParserTest(input, "PredictionIssue334", "T", "file_", "a", "(file_ (item a) <EOF>)\n", null);
|
||||
file.addParserTest(input, "ListLabelForClosureContext", "T", "expression", "a", "", null);
|
||||
/**
|
||||
* This test ensures that {@link ParserATNSimulator} produces a correct
|
||||
* result when the grammar contains multiple explicit references to
|
||||
* {@code EOF} inside of parser rules.
|
||||
*/
|
||||
file.addParserTest(input, "MultipleEOFHandling", "T", "prog", "x", "", null);
|
||||
/**
|
||||
* This test ensures that {@link ParserATNSimulator} does not produce a
|
||||
* {@link StackOverflowError} when it encounters an {@code EOF} transition
|
||||
* inside a closure.
|
||||
*/
|
||||
file.addParserTest(input, "EOFInClosure", "T", "prog", "x", "", null);
|
||||
/**
|
||||
* This is a regression test for antlr/antlr4#561 "Issue with parser
|
||||
* generation in 4.2.2"
|
||||
* https://github.com/antlr/antlr4/issues/561
|
||||
*/
|
||||
file.addParserTests(input, "ReferenceToATN", "T", "a",
|
||||
"", "\n",
|
||||
"a 34 c", "a34c\n");
|
||||
/*CompositeParserTestMethod tm = file.addCompositeParserTest(input, "AlternateQuotes", "ModeTagsParser", "file_", "", "", null, "ModeTagsLexer");
|
||||
tm.slaveIsLexer = true;*/
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : ID+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : ID* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,6 +0,0 @@
|
|||
parser grammar ModeTagsParser;
|
||||
options { tokenVocab=ModeTagsLexer; } // use tokens from ModeTagsLexer.g4
|
||||
file_: (tag | TEXT)* ;
|
||||
tag : '«' ID '»'
|
||||
| '«' '/' ID '»'
|
||||
;
|
|
@ -1,8 +0,0 @@
|
|||
lexer grammar ModeTagsLexer;
|
||||
// Default mode rules (the SEA)
|
||||
OPEN : '«' -> mode(ISLAND) ; // switch to ISLAND mode
|
||||
TEXT : ~'«'+ ; // clump all text together
|
||||
mode ISLAND;
|
||||
CLOSE : '»' -> mode(DEFAULT_MODE) ; // back to SEA mode
|
||||
SLASH : '/' ;
|
||||
ID : [a-zA-Z]+ ; // match/send ID in tag to parser
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|ID)+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|ID)* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,9 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : ID {
|
||||
<writeln("\"alt 1\"")>
|
||||
} | INT {
|
||||
<writeln("\"alt 2\"")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|INT{
|
||||
})+ {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|INT{
|
||||
})* {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\\n') -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : ID INT {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,3 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog : stat EOF;
|
||||
stat : 'x' ('y' | EOF)*?;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement)? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement|) {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement ('else' statement)?? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : statement+ ;
|
||||
statement : 'x' | ifStatement;
|
||||
ifStatement : 'if' 'y' statement (|'else' statement) {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\n') -> channel(HIDDEN);
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|{}INT)? {
|
||||
<writeln("$text")>
|
||||
};
|
||||
ID : 'a'..'z'+;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip;
|
|
@ -1,8 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
start : a* EOF;
|
||||
a
|
||||
: label=subrule {<writeln("$label.text")>} #One
|
||||
| label='y' {<writeln("$label.text")>} #Two
|
||||
;
|
||||
subrule : 'x';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : b1=b b2+=b* b3+=';' ;
|
||||
b : id_=ID val+=INT*;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : b b* ';' ;
|
||||
b : ID val+=(INT | FLOAT)*;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
FLOAT : [0-9]+ '.' [0-9]+;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,2 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
prog : ('x' | 'x' 'y') EOF EOF;
|
|
@ -1,4 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
stat : ifstat | 'x';
|
||||
ifstat : 'if' stat ('else' stat)?;
|
||||
WS : [ \n\t]+ -> skip ;
|
|
@ -1,7 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s : stmt EOF ;
|
||||
stmt : ifStmt | ID;
|
||||
ifStmt : 'if' ID stmt ('else' stmt | { <LANotEquals("1", "ELSE")> }?);
|
||||
ELSE : 'else';
|
||||
ID : [a-zA-Z]+;
|
||||
WS : [ \\n\\t]+ -> skip;
|
|
@ -1,5 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
a : (ID|ATN_)* ATN_? {<writeln("$text")>} ;
|
||||
ID : 'a'..'z'+ ;
|
||||
ATN_ : '0'..'9'+;
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -1,6 +0,0 @@
|
|||
grammar <grammarName>;
|
||||
s @after { <DumpDFA()> }
|
||||
: ID | ID INT ID ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+;
|
||||
WS : (' '|'\t'|'\n') -> skip;
|
|
@ -1,457 +0,0 @@
|
|||
package org.antlr.v4.test.rt.java;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestParserExec extends BaseTest {
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testLabels() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : b1=b b2+=b* b3+=';' ;\n" +
|
||||
"b : id_=ID val+=INT*;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abc 34;", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testListLabelsOnSet() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : b b* ';' ;\n" +
|
||||
"b : ID val+=(INT | FLOAT)*;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"FLOAT : [0-9]+ '.' [0-9]+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abc 34;", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorB() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : ID {\n" +
|
||||
"System.out.println(\"alt 1\");\n" +
|
||||
"} | INT {\n" +
|
||||
"System.out.println(\"alt 2\");\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "34", false);
|
||||
assertEquals("alt 2\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : ID INT {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abc 34", false);
|
||||
assertEquals("abc34\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAPlus() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : ID+ {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorAPlus() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|ID)+ {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testIfIfElseGreedyBinding1() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"start : statement+ ;\n" +
|
||||
"statement : 'x' | ifStatement;\n" +
|
||||
"ifStatement : 'if' 'y' statement ('else' statement)? {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> channel(HIDDEN);";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", "if y if y x else x", false);
|
||||
assertEquals("if y x else x\nif y if y x else x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testIfIfElseGreedyBinding2() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"start : statement+ ;\n" +
|
||||
"statement : 'x' | ifStatement;\n" +
|
||||
"ifStatement : 'if' 'y' statement ('else' statement|) {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> channel(HIDDEN);";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", "if y if y x else x", false);
|
||||
assertEquals("if y x else x\nif y if y x else x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testIfIfElseNonGreedyBinding1() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"start : statement+ ;\n" +
|
||||
"statement : 'x' | ifStatement;\n" +
|
||||
"ifStatement : 'if' 'y' statement ('else' statement)?? {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> channel(HIDDEN);";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", "if y if y x else x", false);
|
||||
assertEquals("if y x\nif y if y x else x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testIfIfElseNonGreedyBinding2() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"start : statement+ ;\n" +
|
||||
"statement : 'x' | ifStatement;\n" +
|
||||
"ifStatement : 'if' 'y' statement (|'else' statement) {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> channel(HIDDEN);";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", "if y if y x else x", false);
|
||||
assertEquals("if y x\nif y if y x else x\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testAStar(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : ID* {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAStar_1() throws Exception {
|
||||
String found = testAStar("");
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAStar_2() throws Exception {
|
||||
String found = testAStar("a b c");
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testLL1OptionalBlock(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|{}INT)? {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+;\n" +
|
||||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testLL1OptionalBlock_1() throws Exception {
|
||||
String found = testLL1OptionalBlock("");
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testLL1OptionalBlock_2() throws Exception {
|
||||
String found = testLL1OptionalBlock("a");
|
||||
assertEquals("a\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testAorAStar(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|ID)* {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorAStar_1() throws Exception {
|
||||
String found = testAorAStar("");
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorAStar_2() throws Exception {
|
||||
String found = testAorAStar("a b c");
|
||||
assertEquals("abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorBPlus() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|INT{\n" +
|
||||
"})+ {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "a 34 c", false);
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testAorBStar(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|INT{\n" +
|
||||
"})* {\n" +
|
||||
"System.out.println($text);\n" +
|
||||
"};\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorBStar_1() throws Exception {
|
||||
String found = testAorBStar("");
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testAorBStar_2() throws Exception {
|
||||
String found = testAorBStar("a 34 c");
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testOptional(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"stat : ifstat | 'x';\n" +
|
||||
"ifstat : 'if' stat ('else' stat)?;\n" +
|
||||
"WS : [ \\n\\t]+ -> skip ;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "stat", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testOptional_1() throws Exception {
|
||||
String found = testOptional("x");
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testOptional_2() throws Exception {
|
||||
String found = testOptional("if x");
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testOptional_3() throws Exception {
|
||||
String found = testOptional("if x else x");
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testOptional_4() throws Exception {
|
||||
String found = testOptional("if if x else x");
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testPredicatedIfIfElse() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"s : stmt EOF ;\n" +
|
||||
"stmt : ifStmt | ID;\n" +
|
||||
"ifStmt : 'if' ID stmt ('else' stmt | { this._input.LA(1)!=ELSE }?);\n" +
|
||||
"ELSE : 'else';\n" +
|
||||
"ID : [a-zA-Z]+;\n" +
|
||||
"WS : [ \\n\\t]+ -> skip;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "if x if x a else b", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testLabelAliasingAcrossLabeledAlternatives() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"start : a* EOF;\n" +
|
||||
"a\n" +
|
||||
" : label=subrule {System.out.println($label.text);} #One\n" +
|
||||
" | label='y' {System.out.println($label.text);} #Two\n" +
|
||||
" ;\n" +
|
||||
"subrule : 'x';\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "start", "xy", false);
|
||||
assertEquals("x\ny\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testPredictionIssue334() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"file_ @init{\n" +
|
||||
"setErrorHandler(new BailErrorStrategy());\n" +
|
||||
"} \n" +
|
||||
"@after {\n" +
|
||||
"System.out.println($ctx.toStringTree(this));\n" +
|
||||
"}\n" +
|
||||
" : item (SEMICOLON item)* SEMICOLON? EOF ;\n" +
|
||||
"item : A B?;\n" +
|
||||
"SEMICOLON: ';';\n" +
|
||||
"A : 'a'|'A';\n" +
|
||||
"B : 'b'|'B';\n" +
|
||||
"WS : [ \\r\\t\\n]+ -> skip;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "file_", "a", false);
|
||||
assertEquals("(file_ (item a) <EOF>)\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testListLabelForClosureContext() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"ifStatement\n" +
|
||||
"@after {\n" +
|
||||
"Object items = $ctx.elseIfStatement(); \n" +
|
||||
"}\n" +
|
||||
" : 'if' expression\n" +
|
||||
" ( ( 'then'\n" +
|
||||
" executableStatement*\n" +
|
||||
" elseIfStatement* // <--- problem is here\n" +
|
||||
" elseStatement?\n" +
|
||||
" 'end' 'if'\n" +
|
||||
" ) | executableStatement )\n" +
|
||||
" ;\n" +
|
||||
"\n" +
|
||||
"elseIfStatement\n" +
|
||||
" : 'else' 'if' expression 'then' executableStatement*\n" +
|
||||
" ;\n" +
|
||||
"expression : 'a' ;\n" +
|
||||
"executableStatement : 'a' ;\n" +
|
||||
"elseStatement : 'a' ;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "expression", "a", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testMultipleEOFHandling() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"prog : ('x' | 'x' 'y') EOF EOF;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "prog", "x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testEOFInClosure() throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"prog : stat EOF;\n" +
|
||||
"stat : 'x' ('y' | EOF)*?;";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "prog", "x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String testReferenceToATN(String input) throws Exception {
|
||||
String grammar = "grammar T;\n" +
|
||||
"a : (ID|ATN_)* ATN_? {System.out.println($text);} ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"ATN_ : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
return execParser("T.g4", grammar, "TParser", "TLexer", "a", input, false);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testReferenceToATN_1() throws Exception {
|
||||
String found = testReferenceToATN("");
|
||||
assertEquals("\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void testReferenceToATN_2() throws Exception {
|
||||
String found = testReferenceToATN("a 34 c");
|
||||
assertEquals("a34c\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue