Pull in parrt's branch 'model-updates-for-new-targets' which appears to have freshened some non Go stuff as well. Simplify Go filename construction.
This commit is contained in:
commit
6d022379bc
|
@ -0,0 +1,7 @@
|
|||
root = true
|
||||
|
||||
[*.{java,stg}]
|
||||
charset = utf-8
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
|
@ -0,0 +1,2 @@
|
|||
# This rule applies to all files which don't match another line below
|
||||
* text=auto
|
|
@ -96,3 +96,5 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2016/08/08, wjkohnen, Wolfgang Johannes Kohnen, wjkohnen-go-antlr@ko-sys.com
|
||||
2016/08/11, BurtHarris, Ralph "Burt" Harris, Burt_Harris_antlr4@azxs.33mail.com
|
||||
2016/08/19, andjo403, Andreas Jonson, andjo403@hotmail.com
|
||||
2016/10/13, cgudrian, Christian Gudrian, christian.gudrian@gmx.de
|
||||
2016/10/13, nielsbasjes, Niels Basjes, niels@basjes.nl
|
|
@ -1,4 +1,11 @@
|
|||
IgnoredTests ::= [
|
||||
"Visitors.Basic": true,
|
||||
"Visitors.LR": true,
|
||||
"Visitors.LRWithLabels": true,
|
||||
"Visitors.RuleGetters_1": true,
|
||||
"Visitors.RuleGetters_2": true,
|
||||
"Visitors.TokenGetters_1": true,
|
||||
"Visitors.TokenGetters_2": true,
|
||||
default: false
|
||||
]
|
||||
|
||||
|
|
|
@ -428,6 +428,13 @@ Declare_pred() ::= <<boolean pred(boolean v) {
|
|||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
|
||||
IgnoredTests ::= [
|
||||
"Visitors.Basic": true,
|
||||
"Visitors.LR": true,
|
||||
"Visitors.LRWithLabels": true,
|
||||
"Visitors.RuleGetters_1": true,
|
||||
"Visitors.RuleGetters_2": true,
|
||||
"Visitors.TokenGetters_1": true,
|
||||
"Visitors.TokenGetters_2": true,
|
||||
default: false
|
||||
]
|
||||
|
||||
|
|
|
@ -227,6 +227,8 @@ TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
|||
|
||||
ImportListener(X) ::= <<var <X>Listener = require('./<X>Listener').<X>Listener;>>
|
||||
|
||||
ImportVisitor(X) ::= <<var <X>Visitor = require('./<X>Visitor').<X>Visitor;>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
@ -328,6 +330,24 @@ var walker = new antlr4.tree.ParseTreeWalker();
|
|||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
BasicVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
return node.symbol.text;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
WalkVisitor(s) ::= <<
|
||||
var visitor = new this.LeafVisitor();
|
||||
console.log(<s>.accept(visitor));
|
||||
>>
|
||||
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
|
||||
@parser::header {
|
||||
|
@ -364,6 +384,24 @@ this.LeafListener.prototype.constructor = this.LeafListener;
|
|||
|
||||
>>
|
||||
|
||||
TokenGetterVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
|
@ -382,6 +420,24 @@ this.LeafListener.prototype.constructor = this.LeafListener;
|
|||
|
||||
>>
|
||||
|
||||
RuleGetterVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
|
@ -401,6 +457,24 @@ this.LeafListener.prototype.constructor = this.LeafListener;
|
|||
|
||||
>>
|
||||
|
||||
LRVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
|
@ -418,6 +492,23 @@ this.LeafListener.prototype.constructor = this.LeafListener;
|
|||
|
||||
>>
|
||||
|
||||
LRWithLabelsVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
this.visitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
IgnoredTests ::= [
|
||||
"Visitors.Basic": true,
|
||||
"Visitors.LR": true,
|
||||
"Visitors.LRWithLabels": true,
|
||||
"Visitors.RuleGetters_1": true,
|
||||
"Visitors.RuleGetters_2": true,
|
||||
"Visitors.TokenGetters_1": true,
|
||||
"Visitors.TokenGetters_2": true,
|
||||
default: false
|
||||
]
|
||||
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
IgnoredTests ::= [
|
||||
"Visitors.Basic": true,
|
||||
"Visitors.LR": true,
|
||||
"Visitors.LRWithLabels": true,
|
||||
"Visitors.RuleGetters_1": true,
|
||||
"Visitors.RuleGetters_2": true,
|
||||
"Visitors.TokenGetters_1": true,
|
||||
"Visitors.TokenGetters_2": true,
|
||||
default: false
|
||||
]
|
||||
|
||||
|
|
|
@ -12,5 +12,6 @@ TestFolders ::= [
|
|||
"Performance": [],
|
||||
"SemPredEvalLexer": [],
|
||||
"SemPredEvalParser": [],
|
||||
"Sets": []
|
||||
"Sets": [],
|
||||
"Visitors": []
|
||||
]
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "1 2"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
(a 1 2)
|
||||
[ '1', '2' ]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
@parser::header {
|
||||
<ImportVisitor(grammarName)>
|
||||
}
|
||||
|
||||
@parser::members {
|
||||
<BasicVisitor(grammarName)>
|
||||
}
|
||||
|
||||
s
|
||||
@after {
|
||||
<ToStringTree("$ctx.r"):writeln()>
|
||||
<WalkVisitor("$ctx.r")>
|
||||
}
|
||||
: r=a ;
|
||||
a : INT INT
|
||||
| ID
|
||||
;
|
||||
MULT: '*' ;
|
||||
ADD : '+' ;
|
||||
INT : [0-9]+ ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,9 @@
|
|||
TestTemplates ::= [
|
||||
"Basic": [],
|
||||
"TokenGetters_1": [],
|
||||
"TokenGetters_2": [],
|
||||
"RuleGetters_1": [],
|
||||
"RuleGetters_2": [],
|
||||
"LR": [],
|
||||
"LRWithLabels": []
|
||||
]
|
|
@ -0,0 +1,47 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "1+2*3"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
(e (e 1) + (e (e 2) * (e 3)))
|
||||
1,,2,,32 3 21 2 1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
@parser::header {
|
||||
<ImportVisitor(grammarName)>
|
||||
}
|
||||
|
||||
@parser::members {
|
||||
<LRVisitor(grammarName)>
|
||||
}
|
||||
|
||||
s
|
||||
@after {
|
||||
<ToStringTree("$ctx.r"):writeln()>
|
||||
<WalkVisitor("$ctx.r")>
|
||||
}
|
||||
: r=e ;
|
||||
e : e op='*' e
|
||||
| e op='+' e
|
||||
| INT
|
||||
;
|
||||
MULT: '*' ;
|
||||
ADD : '+' ;
|
||||
INT : [0-9]+ ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,47 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "1(2,3)"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
(e (e 1) ( (eList (e 2) , (e 3)) ))
|
||||
1,,2,,3,1 [13 6]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
@parser::header {
|
||||
<ImportVisitor(grammarName)>
|
||||
}
|
||||
|
||||
@parser::members {
|
||||
<LRWithLabelsVisitor(grammarName)>
|
||||
}
|
||||
|
||||
s
|
||||
@after {
|
||||
<ToStringTree("$ctx.r"):writeln()>
|
||||
<WalkVisitor("$ctx.r")>
|
||||
}
|
||||
: r=e ;
|
||||
e : e '(' eList ')' # Call
|
||||
| INT # Int
|
||||
;
|
||||
eList : e (',' e)* ;
|
||||
MULT: '*' ;
|
||||
ADD : '+' ;
|
||||
INT : [0-9]+ ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,38 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
@parser::header {
|
||||
<ImportVisitor(grammarName)>
|
||||
}
|
||||
|
||||
@parser::members {
|
||||
<RuleGetterVisitor(grammarName)>
|
||||
}
|
||||
|
||||
s
|
||||
@after {
|
||||
<ToStringTree("$ctx.r"):writeln()>
|
||||
<WalkVisitor("$ctx.r")>
|
||||
}
|
||||
: r=a ;
|
||||
a : b b // forces list
|
||||
| b // a list still
|
||||
;
|
||||
b : ID | INT;
|
||||
MULT: '*' ;
|
||||
ADD : '+' ;
|
||||
INT : [0-9]+ ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,10 @@
|
|||
import "RuleGetters.stg"
|
||||
|
||||
Input() ::= "1 2"
|
||||
|
||||
Output() ::= <<
|
||||
(a (b 1) (b 2))
|
||||
,1 2 1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,10 @@
|
|||
import "RuleGetters.stg"
|
||||
|
||||
Input() ::= "abc"
|
||||
|
||||
Output() ::= <<
|
||||
(a (b abc))
|
||||
abc<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,37 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
@parser::header {
|
||||
<ImportVisitor(grammarName)>
|
||||
}
|
||||
|
||||
@parser::members {
|
||||
<TokenGetterVisitor(grammarName)>
|
||||
}
|
||||
|
||||
s
|
||||
@after {
|
||||
<ToStringTree("$ctx.r"):writeln()>
|
||||
<WalkVisitor("$ctx.r")>
|
||||
}
|
||||
: r=a ;
|
||||
a : INT INT
|
||||
| ID
|
||||
;
|
||||
MULT: '*' ;
|
||||
ADD : '+' ;
|
||||
INT : [0-9]+ ;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \t\n]+ -> skip ;
|
||||
>>
|
|
@ -0,0 +1,10 @@
|
|||
import "TokenGetters.stg"
|
||||
|
||||
Input() ::= "1 2"
|
||||
|
||||
Output() ::= <<
|
||||
(a 1 2)
|
||||
,1 2 [1, 2]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,10 @@
|
|||
import "TokenGetters.stg"
|
||||
|
||||
Input() ::= "abc"
|
||||
|
||||
Output() ::= <<
|
||||
(a abc)
|
||||
[@0,0:2='abc',\<4>,1:0]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -0,0 +1,260 @@
|
|||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.csharp;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestVisitors extends BaseTest {
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"[ '1', '2' ]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLR() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(238);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
grammarBuilder.append(" | e op='+' e\n");
|
||||
grammarBuilder.append(" | INT\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1,,2,,32 3 21 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(278);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
grammarBuilder.append(" | INT # Int\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("eList : e (',' e)* ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1,,2,,3,1 [13 6]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(265);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
",1 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(265);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
",1 2 [1, 2]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("Console.WriteLine($ctx.r.ToStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.java;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestVisitors extends BaseTest {
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"[ '1', '2' ]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLR() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(239);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
grammarBuilder.append(" | e op='+' e\n");
|
||||
grammarBuilder.append(" | INT\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1,,2,,32 3 21 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(279);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
grammarBuilder.append(" | INT # Int\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("eList : e (',' e)* ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1,,2,,3,1 [13 6]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(266);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
",1 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(266);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
",1 2 [1, 2]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("System.out.println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false);
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,388 @@
|
|||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.javascript.node;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestVisitors extends BaseTest {
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(603);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitTerminal = function(node) {\n");
|
||||
grammarBuilder.append(" return node.symbol.text;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"[ '1', '2' ]\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 testLR() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(843);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitE = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str;\n");
|
||||
grammarBuilder.append(" if(ctx.getChildCount()===3) {\n");
|
||||
grammarBuilder.append(" str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" str = ctx.INT().symbol.text;\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
grammarBuilder.append(" | e op='+' e\n");
|
||||
grammarBuilder.append(" | INT\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1,,2,,32 3 21 2 1\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 testLRWithLabels() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(854);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitCall = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str = ctx.e().start.text + ' ' + ctx.eList();\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" this.visitInt = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str = ctx.INT().symbol.text;\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
grammarBuilder.append(" | INT # Int\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("eList : e (',' e)* ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1,,2,,3,1 [13 6]\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 testRuleGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(868);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitA = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str;\n");
|
||||
grammarBuilder.append(" if(ctx.getChildCount()===2) {\n");
|
||||
grammarBuilder.append(" str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" str = ctx.b(0).start.text;\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
",1 2 1\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 testRuleGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(868);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitA = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str;\n");
|
||||
grammarBuilder.append(" if(ctx.getChildCount()===2) {\n");
|
||||
grammarBuilder.append(" str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" str = ctx.b(0).start.text;\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\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 testTokenGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(855);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitA = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str;\n");
|
||||
grammarBuilder.append(" if(ctx.getChildCount()===2) {\n");
|
||||
grammarBuilder.append(" str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" str = ctx.ID().symbol.toString();\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
",1 2 [1, 2]\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 testTokenGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(855);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("var TVisitor = require('./TVisitor').TVisitor;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("this.LeafVisitor = function() {\n");
|
||||
grammarBuilder.append(" this.visitA = function(ctx) {\n");
|
||||
grammarBuilder.append(" var str;\n");
|
||||
grammarBuilder.append(" if(ctx.getChildCount()===2) {\n");
|
||||
grammarBuilder.append(" str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());\n");
|
||||
grammarBuilder.append(" } else {\n");
|
||||
grammarBuilder.append(" str = ctx.ID().symbol.toString();\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append(" return this.visitChildren(ctx) + str;\n");
|
||||
grammarBuilder.append(" };\n");
|
||||
grammarBuilder.append(" return this;\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype = Object.create(TVisitor.prototype);\n");
|
||||
grammarBuilder.append("this.LeafVisitor.prototype.constructor = this.LeafVisitor;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("console.log($ctx.r.toStringTree(null, this));\n");
|
||||
grammarBuilder.append("var visitor = new this.LeafVisitor();\n");
|
||||
grammarBuilder.append("console.log($ctx.r.accept(visitor));\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"TListener", "TVisitor",
|
||||
"s", input, false);
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.python2;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestVisitors extends BasePython2Test {
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"[ '1', '2' ]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLR() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(231);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
grammarBuilder.append(" | e op='+' e\n");
|
||||
grammarBuilder.append(" | INT\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1,,2,,32 3 21 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(271);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
grammarBuilder.append(" | INT # Int\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("eList : e (',' e)* ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1,,2,,3,1 [13 6]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(258);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
",1 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(258);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
",1 2 [1, 2]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.python3;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TestVisitors extends BasePython3Test {
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
"[ '1', '2' ]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLR() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(231);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
grammarBuilder.append(" | e op='+' e\n");
|
||||
grammarBuilder.append(" | INT\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1+2*3";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1,,2,,32 3 21 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(271);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
grammarBuilder.append(" | INT # Int\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("eList : e (',' e)* ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1(2,3)";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1,,2,,3,1 [13 6]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(258);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a (b 1) (b 2))\n" +
|
||||
",1 2 1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(258);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
grammarBuilder.append(" | b // a list still\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("b : ID | INT;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a (b abc))\n" +
|
||||
"abc\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="1 2";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a 1 2)\n" +
|
||||
",1 2 [1, 2]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(216);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("print($ctx.r.toStringTree(recog=self))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
grammarBuilder.append(" | ID\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("MULT: '*' ;\n");
|
||||
grammarBuilder.append("ADD : '+' ;\n");
|
||||
grammarBuilder.append("INT : [0-9]+ ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
||||
|
||||
String input ="abc";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false);
|
||||
|
||||
assertEquals(
|
||||
"(a abc)\n" +
|
||||
"[@0,0:2='abc',<4>,1:0]\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -96,10 +96,16 @@ ATNConfig.prototype.checkContext = function(params, config) {
|
|||
}
|
||||
};
|
||||
|
||||
ATNConfig.prototype.hashString = function() {
|
||||
return "" + this.state.stateNumber + "/" + this.alt + "/" +
|
||||
(this.context===null ? "" : this.context.hashString()) +
|
||||
"/" + this.semanticContext.hashString();
|
||||
};
|
||||
|
||||
// An ATN configuration is equal to another if both have
|
||||
// the same state, they predict the same alternative, and
|
||||
// syntactic/semantic contexts are the same.
|
||||
///
|
||||
|
||||
ATNConfig.prototype.equals = function(other) {
|
||||
if (this === other) {
|
||||
return true;
|
||||
|
@ -114,16 +120,23 @@ ATNConfig.prototype.equals = function(other) {
|
|||
}
|
||||
};
|
||||
|
||||
ATNConfig.prototype.shortHashString = function() {
|
||||
ATNConfig.prototype.hashStringForConfigSet = function() {
|
||||
return "" + this.state.stateNumber + "/" + this.alt + "/" + this.semanticContext;
|
||||
};
|
||||
|
||||
ATNConfig.prototype.hashString = function() {
|
||||
return "" + this.state.stateNumber + "/" + this.alt + "/" +
|
||||
(this.context===null ? "" : this.context.hashString()) +
|
||||
"/" + this.semanticContext.hashString();
|
||||
ATNConfig.prototype.equalsForConfigSet = function(other) {
|
||||
if (this === other) {
|
||||
return true;
|
||||
} else if (! (other instanceof ATNConfig)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.state.stateNumber===other.state.stateNumber &&
|
||||
this.alt===other.alt &&
|
||||
this.semanticContext.equals(other.semanticContext);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ATNConfig.prototype.toString = function() {
|
||||
return "(" + this.state + "," + this.alt +
|
||||
(this.context!==null ? ",[" + this.context.toString() + "]" : "") +
|
||||
|
@ -171,6 +184,11 @@ LexerATNConfig.prototype.equals = function(other) {
|
|||
}
|
||||
};
|
||||
|
||||
LexerATNConfig.prototype.hashStringForConfigSet = LexerATNConfig.prototype.hashString;
|
||||
|
||||
LexerATNConfig.prototype.equalsForConfigSet = LexerATNConfig.prototype.eqials;
|
||||
|
||||
|
||||
LexerATNConfig.prototype.checkNonGreedyDecision = function(source, target) {
|
||||
return source.passedThroughNonGreedyDecision ||
|
||||
(target instanceof DecisionState) && target.nonGreedy;
|
||||
|
|
|
@ -41,19 +41,17 @@ var SemanticContext = require('./SemanticContext').SemanticContext;
|
|||
var merge = require('./../PredictionContext').merge;
|
||||
|
||||
function hashATNConfig(c) {
|
||||
return c.shortHashString();
|
||||
return c.hashStringForConfigSet();
|
||||
}
|
||||
|
||||
function equalATNConfigs(a, b) {
|
||||
if ( a===b ) {
|
||||
return true;
|
||||
}
|
||||
if ( a===null || b===null ) {
|
||||
} else if ( a===null || b===null ) {
|
||||
return false;
|
||||
}
|
||||
return a.state.stateNumber===b.state.stateNumber &&
|
||||
a.alt===b.alt && a.semanticContext.equals(b.semanticContext);
|
||||
}
|
||||
} else
|
||||
return a.equalsForConfigSet(b);
|
||||
}
|
||||
|
||||
|
||||
function ATNConfigSet(fullCtx) {
|
||||
|
|
|
@ -95,6 +95,10 @@ ParseTreeVisitor.prototype.visit = function(ctx) {
|
|||
}
|
||||
};
|
||||
|
||||
ParseTreeVisitor.prototype.visitChildren = function(ctx) {
|
||||
return this.visit(ctx.children);
|
||||
}
|
||||
|
||||
ParseTreeVisitor.prototype.visitTerminal = function(node) {
|
||||
};
|
||||
|
||||
|
@ -103,14 +107,7 @@ ParseTreeVisitor.prototype.visitErrorNode = function(node) {
|
|||
|
||||
|
||||
var visitAtom = function(visitor, ctx) {
|
||||
if (ctx.parser === undefined) { //is terminal
|
||||
return;
|
||||
}
|
||||
|
||||
var name = ctx.parser.ruleNames[ctx.ruleIndex];
|
||||
var funcName = "visit" + Utils.titleCase(name);
|
||||
|
||||
return visitor[funcName](ctx);
|
||||
return ctx.accept(visitor);
|
||||
};
|
||||
|
||||
function ParseTreeListener() {
|
||||
|
@ -253,4 +250,4 @@ exports.TerminalNodeImpl = TerminalNodeImpl;
|
|||
exports.ParseTreeListener = ParseTreeListener;
|
||||
exports.ParseTreeVisitor = ParseTreeVisitor;
|
||||
exports.ParseTreeWalker = ParseTreeWalker;
|
||||
exports.INVALID_INTERVAL = INVALID_INTERVAL;
|
||||
exports.INVALID_INTERVAL = INVALID_INTERVAL;
|
||||
|
|
|
@ -91,7 +91,6 @@ exports.<file.grammarName>Listener = <file.grammarName>Listener;
|
|||
VisitorFile(file, header) ::= <<
|
||||
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
|
||||
var antlr4 = require('antlr4/index');
|
||||
<header>
|
||||
|
||||
// This class defines a complete generic visitor for a parse tree produced by <file.parserName>.
|
||||
|
||||
|
@ -106,6 +105,7 @@ function <file.grammarName>Visitor() {
|
|||
<file.visitorNames:{lname |
|
||||
// Visit a parse tree produced by <file.parserName>#<lname>.
|
||||
<file.grammarName>Visitor.prototype.visit<lname; format="cap"> = function(ctx) {
|
||||
return this.visitChildren(ctx);
|
||||
\};
|
||||
|
||||
}; separator="\n">
|
||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.codegen;
|
|||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.codegen.model.OutputModelObject;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
|
@ -237,94 +236,17 @@ public class CodeGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
/** Generate TParser.java and TLexer.java from T.g4 if combined, else
|
||||
* just use T.java as output regardless of type.
|
||||
*/
|
||||
public String getRecognizerFileName() {
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
ST fullST = getTemplates().getInstanceOf("RecognizerFileName");
|
||||
if (fullST != null) {
|
||||
switch (g.getType()) {
|
||||
case ANTLRParser.PARSER:
|
||||
fullST.add("name", g.name.endsWith("Parser") ? g.name.substring(0, g.name.length() - 6) : g.name); // trim off "parser"
|
||||
fullST.add("type", "parser");
|
||||
break;
|
||||
case ANTLRParser.LEXER:
|
||||
fullST.add("name", g.name.endsWith("Lexer") ?g.name.substring(0, g.name.length() - 5) : g.name); // trim off "lexer"
|
||||
fullST.add("type", "lexer");
|
||||
break;
|
||||
case ANTLRParser.COMBINED:
|
||||
fullST.add("name", g.name);
|
||||
fullST.add("type", "parser");
|
||||
break;
|
||||
}
|
||||
return fullST.render() + extST.render();
|
||||
}
|
||||
String recognizerName = g.getRecognizerName();
|
||||
return recognizerName+extST.render();
|
||||
}
|
||||
public String getRecognizerFileName() { return getRecognizerFileName(false); }
|
||||
public String getListenerFileName() { return getListenerFileName(false); }
|
||||
public String getVisitorFileName() { return getVisitorFileName(false); }
|
||||
public String getBaseListenerFileName() { return getBaseListenerFileName(false); }
|
||||
public String getBaseVisitorFileName() { return getBaseVisitorFileName(false); }
|
||||
|
||||
/** A given grammar T, return the listener name such as
|
||||
* TListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getListenerFileName() {
|
||||
assert g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
ST fullST = getTemplates().getInstanceOf("ListenerFileName");
|
||||
if (fullST != null) {
|
||||
fullST.add("name", g.name);
|
||||
return fullST.render() + extST.render();
|
||||
}
|
||||
String listenerName = g.name + "Listener";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return the visitor name such as
|
||||
* TVisitor.java, if we're using the Java target.
|
||||
*/
|
||||
public String getVisitorFileName() {
|
||||
assert g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
ST fullST = getTemplates().getInstanceOf("VisitorFileName");
|
||||
if (fullST != null) {
|
||||
fullST.add("name", g.name);
|
||||
return fullST.render() + extST.render();
|
||||
}
|
||||
String listenerName = g.name + "Visitor";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return a blank listener implementation
|
||||
* such as TBaseListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getBaseListenerFileName() {
|
||||
assert g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
ST fullST = getTemplates().getInstanceOf("BaseListenerFileName");
|
||||
if (fullST != null) {
|
||||
fullST.add("name", g.name);
|
||||
return fullST.render() + extST.render();
|
||||
}
|
||||
String listenerName = g.name + "BaseListener";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return a blank listener implementation
|
||||
* such as TBaseListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getBaseVisitorFileName() {
|
||||
assert g.name != null;
|
||||
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
ST fullST = getTemplates().getInstanceOf("BaseVisitorFileName");
|
||||
if (fullST != null) {
|
||||
fullST.add("name", g.name);
|
||||
return fullST.render() + extST.render();
|
||||
}
|
||||
|
||||
String listenerName = g.name + "BaseVisitor";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
public String getRecognizerFileName(boolean header) { return getTarget().getRecognizerFileName(header); }
|
||||
public String getListenerFileName(boolean header) { return getTarget().getListenerFileName(header); }
|
||||
public String getVisitorFileName(boolean header) { return getTarget().getVisitorFileName(header); }
|
||||
public String getBaseListenerFileName(boolean header) { return getTarget().getBaseListenerFileName(header); }
|
||||
public String getBaseVisitorFileName(boolean header) { return getTarget().getBaseVisitorFileName(header); }
|
||||
|
||||
/** What is the name of the vocab file generated for this grammar?
|
||||
* Returns null if no .tokens file should be generated.
|
||||
|
|
|
@ -392,6 +392,55 @@ public abstract class Target {
|
|||
return getTokenTypeAsTargetLabel(getCodeGenerator().g, ttype);
|
||||
}
|
||||
|
||||
/** Generate TParser.java and TLexer.java from T.g4 if combined, else
|
||||
* just use T.java as output regardless of type.
|
||||
*/
|
||||
public String getRecognizerFileName(boolean header) {
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
String recognizerName = gen.g.getRecognizerName();
|
||||
return recognizerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return the listener name such as
|
||||
* TListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getListenerFileName(boolean header) {
|
||||
assert gen.g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
String listenerName = gen.g.name + "Listener";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return the visitor name such as
|
||||
* TVisitor.java, if we're using the Java target.
|
||||
*/
|
||||
public String getVisitorFileName(boolean header) {
|
||||
assert gen.g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
String listenerName = gen.g.name + "Visitor";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return a blank listener implementation
|
||||
* such as TBaseListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getBaseListenerFileName(boolean header) {
|
||||
assert gen.g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
String listenerName = gen.g.name + "BaseListener";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/** A given grammar T, return a blank listener implementation
|
||||
* such as TBaseListener.java, if we're using the Java target.
|
||||
*/
|
||||
public String getBaseVisitorFileName(boolean header) {
|
||||
assert gen.g.name != null;
|
||||
ST extST = getTemplates().getInstanceOf("codeFileExtension");
|
||||
String listenerName = gen.g.name + "BaseVisitor";
|
||||
return listenerName+extST.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum number of 16-bit unsigned integers that can be encoded
|
||||
* in a single segment of the serialized ATN.
|
||||
|
|
Loading…
Reference in New Issue