Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes #9

Merged
merged 8 commits into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ GetExpectedTokenNames() ::= "p.GetExpectedTokens().StringVerbose(p.GetTokenNames

RuleInvocationStack() ::= "p.GetRuleInvocationStack(nil)"

LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);>>
LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);>>

ParserPropertyMember() ::= <<
@members {
Expand All @@ -241,12 +241,12 @@ PositionAdjustingLexer() ::= <<
package antlrtest

type PositionAdjustingLexer struct {
antlr4.*BaseLexer
antlr.*BaseLexer
}

func NewPositionAdjustingLexer(input antlr4.CharStream) *PositionAdjustingLexer {
func NewPositionAdjustingLexer(input antlr.CharStream) *PositionAdjustingLexer {
l := new(PositionAdjustingLexer)
l.BaseLexer = antlr4.NewBaseLexer( input )
l.BaseLexer = antlr.NewBaseLexer( input )
return l
}

Expand Down Expand Up @@ -308,14 +308,14 @@ func isIdentifierChar(c rune) bool {
}

type PositionAdjustingLexerATNSimulator struct {
*antlr4.LexerATNSimulator
*antlr.LexerATNSimulator
}

func NewPositionAdjustingLexerATNSimulator(recog antlr4.Lexer, atn *antlr4.ATN, decisionToDFA []*antlr4.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {
func NewPositionAdjustingLexerATNSimulator(recog antlr.Lexer, atn *antlr.ATN, decisionToDFA []*antlr.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {

l := new(PositionAdjustingLexerATNSimulator)

l.LexerATNSimulator = antlr4.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)
l.LexerATNSimulator = antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)

return l
}
Expand All @@ -340,13 +340,13 @@ func NewLeafListener() *LeafListener {
return l
}

func (this *LeafListener) VisitTerminal( node antlr4.TerminalNode ) {
func (this *LeafListener) VisitTerminal( node antlr.TerminalNode ) {
fmt.Println(node.GetSymbol().GetText())
}
>>

WalkListener(s) ::= <<
walker := antlr4.NewParseTreeWalker();
walker := antlr.NewParseTreeWalker();
walker.Walk(NewLeafListener(), <s>);
>>

Expand Down
30 changes: 17 additions & 13 deletions runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,12 @@ public String execModule(String fileName) {
try {
ProcessBuilder builder = new ProcessBuilder(goPath, "run", modulePath,
inputPath);
builder.environment().put("GOPATH",
runtimePath + File.pathSeparator + tmpdir);
String gopath = builder.environment().get("GOPATH");
String path = runtimePath + File.pathSeparator + tmpdir;
if (gopath != null && gopath.length() > 0) {
path = gopath + File.pathSeparator + path;
}
builder.environment().put("GOPATH", path);
builder.directory(new File(tmpdir));
Process process = builder.start();
StreamVacuum stdoutVacuum = new StreamVacuum(
Expand Down Expand Up @@ -766,7 +770,7 @@ protected void writeParserTestFile(String parserName, String lexerName,
ST outputFileST = new ST(
"package main\n" +
"import (\n"
+" \"antlr4\"\n"
+" \"github.com/pboyer/antlr4/runtime/Go/antlr\"\n"
+" \"./parser\"\n"
+" \"os\"\n"
+")\n"
Expand All @@ -779,32 +783,32 @@ protected void writeParserTestFile(String parserName, String lexerName,
+ " return new(TreeShapeListener)\n"
+ "}\n"
+ "\n"
+ "func (this *TreeShapeListener) EnterEveryRule(ctx antlr4.ParserRuleContext) {\n"
+ "func (this *TreeShapeListener) EnterEveryRule(ctx antlr.ParserRuleContext) {\n"
+ " for i := 0; i\\<ctx.GetChildCount(); i++ {\n"
+ " child := ctx.GetChild(i)\n"
+ " parentR,ok := child.GetParent().(antlr4.RuleNode)\n"
+ " parentR,ok := child.GetParent().(antlr.RuleNode)\n"
+ " if !ok || parentR.GetBaseRuleContext() != ctx.GetBaseRuleContext() {\n"
+ " panic(\"Invalid parse tree shape detected.\")\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "\n"
+ "func main() {\n"
+ " input := antlr4.NewFileStream(os.Args[1])\n"
+ " input := antlr.NewFileStream(os.Args[1])\n"
+ " lexer := parser.New<lexerName>(input)\n"
+ " stream := antlr4.NewCommonTokenStream(lexer,0)\n"
+ " stream := antlr.NewCommonTokenStream(lexer,0)\n"
+ "<createParser>"
+ " p.BuildParseTrees = true\n"
+ " tree := p.<parserStartRuleName>()\n"
+ " antlr4.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)\n"
+ " antlr.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)\n"
+ "}\n");

ST createParserST = new ST(
" p := parser.New<parserName>(stream)\n");
if (debug) {
createParserST = new ST(
" p := parser.New<parserName>(stream)\n"
+ " p.AddErrorListener(antlr4.NewDiagnosticErrorListener(true))\n");
+ " p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))\n");
}
outputFileST.add("createParser", createParserST);
outputFileST.add("parserName", parserName);
Expand All @@ -821,21 +825,21 @@ protected void writeLexerTestFile(String lexerName, boolean showDFA) {
ST outputFileST = new ST(
"package main\n" +
"import (\n"
+ " \"antlr4\"\n"
+ " \"github.com/pboyer/antlr4/runtime/Go/antlr\"\n"
+ " \"./parser\"\n"
+ " \"os\"\n"
+ " \"fmt\"\n"
+ ")\n"
+ "\n"
+ "func main() {\n"
+ " input := antlr4.NewFileStream(os.Args[1])\n"
+ " input := antlr.NewFileStream(os.Args[1])\n"
+ " lexer := parser.New<lexerName>(input)\n"
+ " stream := antlr4.NewCommonTokenStream(lexer,0)\n"
+ " stream := antlr.NewCommonTokenStream(lexer,0)\n"
+ " stream.Fill()\n"
+ " for _, t := range stream.GetAllTokens() {\n"
+ " fmt.Println(t)\n"
+ " }\n"
+ (showDFA ? "fmt.Print(lexer.GetInterpreter().DecisionToDFA[antlr4.LexerDefaultMode].ToLexerString())\n"
+ (showDFA ? "fmt.Print(lexer.GetInterpreter().DecisionToDFA[antlr.LexerDefaultMode].ToLexerString())\n"
: "")
+ "}\n"
+ "\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testAmbiguityNoLoop() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(218);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("prog\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(" : expr expr {fmt.Println(\"alt 1\")}\n");
grammarBuilder.append(" | expr\n");
grammarBuilder.append(" ;\n");
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testExprAmbiguity_1() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(293);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
grammarBuilder.append(" expr[int _p]\n");
grammarBuilder.append(" : ID \n");
Expand Down Expand Up @@ -187,7 +187,7 @@ public void testExprAmbiguity_2() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(293);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
grammarBuilder.append(" expr[int _p]\n");
grammarBuilder.append(" : ID \n");
Expand Down Expand Up @@ -219,7 +219,7 @@ public void testFullContextIF_THEN_ELSEParse_1() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand All @@ -245,7 +245,7 @@ public void testFullContextIF_THEN_ELSEParse_2() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand Down Expand Up @@ -274,7 +274,7 @@ public void testFullContextIF_THEN_ELSEParse_3() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand Down Expand Up @@ -304,7 +304,7 @@ public void testFullContextIF_THEN_ELSEParse_4() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand Down Expand Up @@ -335,7 +335,7 @@ public void testFullContextIF_THEN_ELSEParse_5() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand Down Expand Up @@ -369,7 +369,7 @@ public void testFullContextIF_THEN_ELSEParse_6() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
Expand Down Expand Up @@ -403,7 +403,7 @@ public void testLoopsSimulateTailRecursion() throws Exception {
StringBuilder grammarBuilder = new StringBuilder(317);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("prog\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(" : expr_or_assign*;\n");
grammarBuilder.append("expr_or_assign\n");
grammarBuilder.append(" : expr '++' {fmt.Println(\"fail.\")}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4632,12 +4632,12 @@ public void testPositionAdjustingLexer() throws Exception {
grammarBuilder.append("package antlrtest\n");
grammarBuilder.append("\n");
grammarBuilder.append("type PositionAdjustingLexer struct {\n");
grammarBuilder.append(" antlr4.*BaseLexer\n");
grammarBuilder.append(" antlr.*BaseLexer\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewPositionAdjustingLexer(input antlr4.CharStream) *PositionAdjustingLexer {\n");
grammarBuilder.append("func NewPositionAdjustingLexer(input antlr.CharStream) *PositionAdjustingLexer {\n");
grammarBuilder.append(" l := new(PositionAdjustingLexer)\n");
grammarBuilder.append(" l.BaseLexer = antlr4.NewBaseLexer( input )\n");
grammarBuilder.append(" l.BaseLexer = antlr.NewBaseLexer( input )\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
Expand Down Expand Up @@ -4699,14 +4699,14 @@ public void testPositionAdjustingLexer() throws Exception {
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("type PositionAdjustingLexerATNSimulator struct {\n");
grammarBuilder.append(" *antlr4.LexerATNSimulator\n");
grammarBuilder.append(" *antlr.LexerATNSimulator\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewPositionAdjustingLexerATNSimulator(recog antlr4.Lexer, atn *antlr4.ATN, decisionToDFA []*antlr4.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {\n");
grammarBuilder.append("func NewPositionAdjustingLexerATNSimulator(recog antlr.Lexer, atn *antlr.ATN, decisionToDFA []*antlr.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {\n");
grammarBuilder.append("\n");
grammarBuilder.append(" l := new(PositionAdjustingLexerATNSimulator)\n");
grammarBuilder.append("\n");
grammarBuilder.append(" l.LexerATNSimulator = antlr4.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)\n");
grammarBuilder.append(" l.LexerATNSimulator = antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public void testBasic() throws Exception {
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) VisitTerminal( node antlr4.TerminalNode ) {\n");
grammarBuilder.append("func (this *LeafListener) VisitTerminal( node antlr.TerminalNode ) {\n");
grammarBuilder.append(" fmt.Println(node.GetSymbol().GetText())\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testLR() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=e ;\n");
Expand Down Expand Up @@ -152,7 +152,7 @@ public void testLRWithLabels() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=e ;\n");
Expand Down Expand Up @@ -211,7 +211,7 @@ public void testRuleGetters_1() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
Expand Down Expand Up @@ -267,7 +267,7 @@ public void testRuleGetters_2() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
Expand Down Expand Up @@ -323,7 +323,7 @@ public void testTokenGetters_1() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
Expand Down Expand Up @@ -378,7 +378,7 @@ public void testTokenGetters_2() throws Exception {
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker := antlr.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public void testParserProperty() throws Exception {
grammarBuilder.append(" return true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("a : {$parser.Property()}? ID {fmt.Println(\"valid\")}\n");
grammarBuilder.append("a : {Property()}? ID {fmt.Println(\"valid\")}\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
Expand All @@ -611,7 +611,7 @@ public void testPredicatedIfIfElse() throws Exception {
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : stmt EOF ;\n");
grammarBuilder.append("stmt : ifStmt | ID;\n");
grammarBuilder.append("ifStmt : 'if' ID stmt ('else' stmt | { p.GetTokenStream().LA(1)!=TParser.ELSE }?);\n");
grammarBuilder.append("ifStmt : 'if' ID stmt ('else' stmt | { p.GetTokenStream().LA(1)!=TParserELSE }?);\n");
grammarBuilder.append("ELSE : 'else';\n");
grammarBuilder.append("ID : [a-zA-Z]+;\n");
grammarBuilder.append("WS : [ \\n\\t]+ -> skip;");
Expand Down
Loading