From 10eb1a197073550a74981d771dc591fb804f71ab Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:27:21 -0700 Subject: [PATCH 1/8] Rename Lexer.mode to setMode Also minor formatting. --- runtime/Go/antlr/lexer.go | 8 ++++++-- runtime/Go/antlr/lexer_action.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/runtime/Go/antlr/lexer.go b/runtime/Go/antlr/lexer.go index 8e171d0f8..7d5aca7f3 100644 --- a/runtime/Go/antlr/lexer.go +++ b/runtime/Go/antlr/lexer.go @@ -19,7 +19,7 @@ type Lexer interface { pushMode(int) popMode() int setType(int) - mode(int) + setMode(int) } type BaseLexer struct { @@ -37,7 +37,7 @@ type BaseLexer struct { token Token hitEOF bool channel int - thetype int + thetype int modeStack IntStack mode int text string @@ -249,6 +249,10 @@ func (b *BaseLexer) More() { b.thetype = LexerMore } +func (b *BaseLexer) setMode(m int) { + b.mode = m +} + func (b *BaseLexer) pushMode(m int) { if LexerATNSimulatorDebug { fmt.Println("pushMode " + strconv.Itoa(m)) diff --git a/runtime/Go/antlr/lexer_action.go b/runtime/Go/antlr/lexer_action.go index d5f7ca509..48970b061 100644 --- a/runtime/Go/antlr/lexer_action.go +++ b/runtime/Go/antlr/lexer_action.go @@ -232,7 +232,7 @@ func NewLexerModeAction(mode int) *LexerModeAction { //

This action is implemented by calling {@link Lexer//mode} with the // value provided by {@link //getMode}.

func (l *LexerModeAction) execute(lexer Lexer) { - lexer.mode(l.mode) + lexer.setMode(l.mode) } func (l *LexerModeAction) Hash() string { From 92793a9dc84e9a0780377bb206513e2c1fa7e847 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:28:27 -0700 Subject: [PATCH 2/8] Rename "this" receiver to "t" --- runtime/Go/antlr/trace_listener.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/Go/antlr/trace_listener.go b/runtime/Go/antlr/trace_listener.go index a4f3eea1f..ed6d4fecd 100644 --- a/runtime/Go/antlr/trace_listener.go +++ b/runtime/Go/antlr/trace_listener.go @@ -12,17 +12,17 @@ func NewTraceListener(parser *BaseParser) *TraceListener { return tl } -func (this *TraceListener) VisitErrorNode(_ ErrorNode) { +func (t *TraceListener) VisitErrorNode(_ ErrorNode) { } -func (this *TraceListener) EnterEveryRule(ctx ParserRuleContext) { - fmt.Println("enter " + this.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + this.parser._input.LT(1).GetText()) +func (t *TraceListener) EnterEveryRule(ctx ParserRuleContext) { + fmt.Println("enter " + t.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + t.parser.input.LT(1).GetText()) } -func (this *TraceListener) VisitTerminal(node TerminalNode) { - fmt.Println("consume " + fmt.Sprint(node.GetSymbol()) + " rule " + this.parser.GetRuleNames()[this.parser._ctx.GetRuleIndex()]) +func (t *TraceListener) VisitTerminal(node TerminalNode) { + fmt.Println("consume " + fmt.Sprint(node.GetSymbol()) + " rule " + t.parser.GetRuleNames()[t.parser.ctx.GetRuleIndex()]) } -func (this *TraceListener) ExitEveryRule(ctx ParserRuleContext) { - fmt.Println("exit " + this.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + this.parser._input.LT(1).GetText()) +func (t *TraceListener) ExitEveryRule(ctx ParserRuleContext) { + fmt.Println("exit " + t.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + t.parser.input.LT(1).GetText()) } From 34877767c128aa2f54d76a9926cced7e75021587 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:31:19 -0700 Subject: [PATCH 3/8] Change package alias antlr4 to antlr --- .../org/antlr/v4/test/runtime/go/Go.test.stg | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg index 3b9ec4f66..171405c69 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg @@ -227,7 +227,7 @@ GetExpectedTokenNames() ::= "p.GetExpectedTokens().StringVerbose(p.GetTokenNames RuleInvocationStack() ::= "p.GetRuleInvocationStack(nil)" -LL_EXACT_AMBIG_DETECTION() ::= <> +LL_EXACT_AMBIG_DETECTION() ::= <> ParserPropertyMember() ::= << @members { @@ -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 } @@ -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 } @@ -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(), ); >> From 3434e802be38f6e5e4473ab68b20677d9b758d50 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:34:29 -0700 Subject: [PATCH 4/8] Fix test GOPATH env var to include current GOPATH Also: - Change "antlr4" imports to "github.com/antlr/antlr4/runtime/Go/antlr" - Remove parser prefix from Property and pred calls - Change TParser.X tokens to TParserX --- .../antlr/v4/test/runtime/go/BaseTest.java | 24 +++++++++---------- .../runtime/go/TestFullContextParsing.java | 20 ++++++++-------- .../v4/test/runtime/go/TestLexerExec.java | 12 +++++----- .../v4/test/runtime/go/TestListeners.java | 16 ++++++------- .../v4/test/runtime/go/TestParserExec.java | 4 ++-- .../runtime/go/TestSemPredEvalParser.java | 20 ++++++++-------- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java index d371b068e..9670ba79d 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java @@ -391,7 +391,7 @@ public abstract class BaseTest { ProcessBuilder builder = new ProcessBuilder(goPath, "run", modulePath, inputPath); builder.environment().put("GOPATH", - runtimePath + File.pathSeparator + tmpdir); + builder.environment().get("GOPATH") + ":" + runtimePath + File.pathSeparator + tmpdir); builder.directory(new File(tmpdir)); Process process = builder.start(); StreamVacuum stdoutVacuum = new StreamVacuum( @@ -766,7 +766,7 @@ public abstract class BaseTest { ST outputFileST = new ST( "package main\n" + "import (\n" - +" \"antlr4\"\n" + +" \"github.com/willfaught/antlr4/runtime/Go/antlr\"\n" +" \"./parser\"\n" +" \"os\"\n" +")\n" @@ -779,10 +779,10 @@ public abstract class BaseTest { + " 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\\(input)\n" - + " stream := antlr4.NewCommonTokenStream(lexer,0)\n" + + " stream := antlr.NewCommonTokenStream(lexer,0)\n" + "" + " p.BuildParseTrees = true\n" + " tree := p.()\n" - + " antlr4.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)\n" + + " antlr.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)\n" + "}\n"); ST createParserST = new ST( @@ -804,7 +804,7 @@ public abstract class BaseTest { if (debug) { createParserST = new ST( " p := parser.New(stream)\n" - + " p.AddErrorListener(antlr4.NewDiagnosticErrorListener(true))\n"); + + " p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))\n"); } outputFileST.add("createParser", createParserST); outputFileST.add("parserName", parserName); @@ -821,21 +821,21 @@ public abstract class BaseTest { ST outputFileST = new ST( "package main\n" + "import (\n" - + " \"antlr4\"\n" + + " \"github.com/willfaught/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(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"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestFullContextParsing.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestFullContextParsing.java index 710972ec3..26b9a0523 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestFullContextParsing.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestFullContextParsing.java @@ -37,7 +37,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -157,7 +157,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -187,7 +187,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -219,7 +219,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -245,7 +245,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -274,7 +274,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -304,7 +304,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -335,7 +335,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -369,7 +369,7 @@ public class TestFullContextParsing extends BaseTest { 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"); @@ -403,7 +403,7 @@ public class TestFullContextParsing extends BaseTest { 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"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLexerExec.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLexerExec.java index 5201a24fa..127a03e43 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLexerExec.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLexerExec.java @@ -4632,12 +4632,12 @@ public class TestLexerExec extends BaseTest { 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"); @@ -4699,14 +4699,14 @@ public class TestLexerExec extends BaseTest { 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"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java index a774f5e94..64a417f56 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java @@ -28,7 +28,7 @@ public class TestListeners extends BaseTest { 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"); @@ -36,7 +36,7 @@ public class TestListeners extends BaseTest { 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"); @@ -92,7 +92,7 @@ public class TestListeners extends BaseTest { 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"); @@ -152,7 +152,7 @@ public class TestListeners extends BaseTest { 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"); @@ -211,7 +211,7 @@ public class TestListeners extends BaseTest { 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"); @@ -267,7 +267,7 @@ public class TestListeners extends BaseTest { 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"); @@ -323,7 +323,7 @@ public class TestListeners extends BaseTest { 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"); @@ -378,7 +378,7 @@ public class TestListeners extends BaseTest { 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"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java index 887cd0d25..7c6a4558d 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java @@ -590,7 +590,7 @@ public class TestParserExec extends BaseTest { 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 ;"); @@ -611,7 +611,7 @@ public class TestParserExec extends BaseTest { 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;"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java index 4d11d3aa9..0ebe872c7 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java @@ -14,7 +14,7 @@ public class TestSemPredEvalParser extends BaseTest { mkdir(parserpkgdir); StringBuilder grammarBuilder = new StringBuilder(300); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);} a ';' a; // do 2x: once in ATN, next in DFA\n"); + grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);} a ';' a; // do 2x: once in ATN, next in DFA\n"); grammarBuilder.append("a : ID {fmt.Println(\"alt 1\")}\n"); grammarBuilder.append(" | ID {fmt.Println(\"alt 2\")}\n"); grammarBuilder.append(" | {false}? ID {fmt.Println(\"alt 3\")}\n"); @@ -44,7 +44,7 @@ public class TestSemPredEvalParser extends BaseTest { mkdir(parserpkgdir); StringBuilder grammarBuilder = new StringBuilder(351); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);} a ';' a ';' a;\n"); + grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);} a ';' a ';' a;\n"); grammarBuilder.append("a : INT {fmt.Println(\"alt 1\")}\n"); grammarBuilder.append(" | ID {fmt.Println(\"alt 2\")} // must pick this one for ID since pred is false\n"); grammarBuilder.append(" | ID {fmt.Println(\"alt 3\")}\n"); @@ -108,8 +108,8 @@ public class TestSemPredEvalParser extends BaseTest { grammarBuilder.append(" return v\n"); grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); - grammarBuilder.append("s : e {} {p.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n"); - grammarBuilder.append("t : e {} {p.pred(false)}? ID ;\n"); + grammarBuilder.append("s : e {} {pred(true)}? {fmt.Println(\"parse\")} '!' ;\n"); + grammarBuilder.append("t : e {} {pred(false)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -157,8 +157,8 @@ public class TestSemPredEvalParser extends BaseTest { grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); grammarBuilder.append("s : a[99] ;\n"); - grammarBuilder.append("a[int i] : e {p.pred($i==99)}? {fmt.Println(\"parse\")} '!' ;\n"); - grammarBuilder.append("b[int i] : e {p.pred($i==99)}? ID ;\n"); + grammarBuilder.append("a[int i] : e {pred($i==99)}? {fmt.Println(\"parse\")} '!' ;\n"); + grammarBuilder.append("b[int i] : e {pred($i==99)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); @@ -300,7 +300,7 @@ public class TestSemPredEvalParser extends BaseTest { grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil,p))}\n"); grammarBuilder.append(" : para para EOF ;\n"); grammarBuilder.append("para: paraContent NL NL ;\n"); - grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParser.NL}? NL)+ ;\n"); + grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParserNL}? NL)+ ;\n"); grammarBuilder.append("NL : '\\n' ;\n"); grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("X : 'x' ;"); @@ -330,7 +330,7 @@ public class TestSemPredEvalParser extends BaseTest { grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil,p))}\n"); grammarBuilder.append(" : para para EOF ;\n"); grammarBuilder.append("para: paraContent NL NL ;\n"); - grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParser.NL}? NL)+ ;\n"); + grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParserNL}? NL)+ ;\n"); grammarBuilder.append("NL : '\\n' ;\n"); grammarBuilder.append("s : 's' ;\n"); grammarBuilder.append("X : 'x' ;"); @@ -455,8 +455,8 @@ public class TestSemPredEvalParser extends BaseTest { grammarBuilder.append(" return v\n"); grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); - grammarBuilder.append("s : e {p.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n"); - grammarBuilder.append("t : e {p.pred(false)}? ID ;\n"); + grammarBuilder.append("s : e {pred(true)}? {fmt.Println(\"parse\")} '!' ;\n"); + grammarBuilder.append("t : e {pred(false)}? ID ;\n"); grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n"); grammarBuilder.append("ID : 'a'..'z'+ ;\n"); grammarBuilder.append("INT : '0'..'9'+;\n"); From 8d863ea19c615f32210a7fd7d22a71cec10a4a64 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:38:51 -0700 Subject: [PATCH 5/8] Change antlr/antlr4 to willfaught/antlr4 --- .../org/antlr/v4/tool/templates/codegen/Go/Go.stg | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index 4d562ed99..be506986b 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -11,7 +11,7 @@ import ( "fmt" "strconv" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/willfaught/antlr4/runtime/Go/antlr" ) // Stopgap to suppress unused import error. We aren't certain @@ -31,7 +31,7 @@ ListenerFile(file, header) ::= << package parser // -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/willfaught/antlr4/runtime/Go/antlr" // A complete listener for a parse tree produced by @@ -50,7 +50,7 @@ BaseListenerFile(file, header) ::= << package parser // -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/willfaught/antlr4/runtime/Go/antlr" // A complete base listener for a parse tree produced by @@ -78,7 +78,7 @@ VisitorFile(file, header) ::= << package parser // -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/willfaught/antlr4/runtime/Go/antlr"
@@ -98,7 +98,7 @@ BaseVisitorFile(file, header) ::= << package parser // -import "github.com/antlr/antlr4/runtime/Go/antlr" +import "github.com/willfaught/antlr4/runtime/Go/antlr" type BaseVisitor struct { *antlr.BaseParseTreeVisitor @@ -897,7 +897,7 @@ package parser import ( "fmt" - "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/willfaught/antlr4/runtime/Go/antlr" ) // suppress unused import error, many tests From 9562d87d499fe2bb2c47294e6794e3dbd04548a5 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Thu, 26 May 2016 23:43:43 -0700 Subject: [PATCH 6/8] Change willfaught/antlr4 to pboyer/antlr4 --- .../test/org/antlr/v4/test/runtime/go/BaseTest.java | 4 ++-- .../org/antlr/v4/tool/templates/codegen/Go/Go.stg | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java index 9670ba79d..239611986 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java @@ -766,7 +766,7 @@ public abstract class BaseTest { ST outputFileST = new ST( "package main\n" + "import (\n" - +" \"github.com/willfaught/antlr4/runtime/Go/antlr\"\n" + +" \"github.com/pboyer/antlr4/runtime/Go/antlr\"\n" +" \"./parser\"\n" +" \"os\"\n" +")\n" @@ -821,7 +821,7 @@ public abstract class BaseTest { ST outputFileST = new ST( "package main\n" + "import (\n" - + " \"github.com/willfaught/antlr4/runtime/Go/antlr\"\n" + + " \"github.com/pboyer/antlr4/runtime/Go/antlr\"\n" + " \"./parser\"\n" + " \"os\"\n" + " \"fmt\"\n" diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index be506986b..ee2789c5e 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -11,7 +11,7 @@ import ( "fmt" "strconv" - "github.com/willfaught/antlr4/runtime/Go/antlr" + "github.com/pboyer/antlr4/runtime/Go/antlr" ) // Stopgap to suppress unused import error. We aren't certain @@ -31,7 +31,7 @@ ListenerFile(file, header) ::= << package parser // -import "github.com/willfaught/antlr4/runtime/Go/antlr" +import "github.com/pboyer/antlr4/runtime/Go/antlr" // A complete listener for a parse tree produced by @@ -50,7 +50,7 @@ BaseListenerFile(file, header) ::= << package parser // -import "github.com/willfaught/antlr4/runtime/Go/antlr" +import "github.com/pboyer/antlr4/runtime/Go/antlr" // A complete base listener for a parse tree produced by @@ -78,7 +78,7 @@ VisitorFile(file, header) ::= << package parser // -import "github.com/willfaught/antlr4/runtime/Go/antlr" +import "github.com/pboyer/antlr4/runtime/Go/antlr"
@@ -98,7 +98,7 @@ BaseVisitorFile(file, header) ::= << package parser // -import "github.com/willfaught/antlr4/runtime/Go/antlr" +import "github.com/pboyer/antlr4/runtime/Go/antlr" type BaseVisitor struct { *antlr.BaseParseTreeVisitor @@ -897,7 +897,7 @@ package parser import ( "fmt" - "github.com/willfaught/antlr4/runtime/Go/antlr" + "github.com/pboyer/antlr4/runtime/Go/antlr" ) // suppress unused import error, many tests From 7e8fb7a7f3ecc8ed3a54a670b5992e0ec0af9411 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Fri, 27 May 2016 11:05:16 -0700 Subject: [PATCH 7/8] Handle empty current GOPATH when setting GOPATH --- .../test/org/antlr/v4/test/runtime/go/BaseTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java index 239611986..d4e67664c 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java @@ -390,8 +390,12 @@ public abstract class BaseTest { try { ProcessBuilder builder = new ProcessBuilder(goPath, "run", modulePath, inputPath); - builder.environment().put("GOPATH", - builder.environment().get("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.separator + path; + } + builder.environment().put("GOPATH", path); builder.directory(new File(tmpdir)); Process process = builder.start(); StreamVacuum stdoutVacuum = new StreamVacuum( From a0314a89468722a3a0a00f958683824f9c244d45 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Fri, 27 May 2016 11:26:38 -0700 Subject: [PATCH 8/8] Change File.separator to File.pathSeparator --- .../test/org/antlr/v4/test/runtime/go/BaseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java index d4e67664c..178634b2a 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseTest.java @@ -393,7 +393,7 @@ public abstract class BaseTest { String gopath = builder.environment().get("GOPATH"); String path = runtimePath + File.pathSeparator + tmpdir; if (gopath != null && gopath.length() > 0) { - path = gopath + File.separator + path; + path = gopath + File.pathSeparator + path; } builder.environment().put("GOPATH", path); builder.directory(new File(tmpdir));