Merge pull request #9 from willfaught/master

Test fixes
This commit is contained in:
Peter Boyer 2016-05-27 15:33:29 -04:00
commit 6ddc7c9d4f
11 changed files with 82 additions and 74 deletions

View File

@ -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 {
@ -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(), <s>);
>>

View File

@ -390,8 +390,12 @@ public abstract class BaseTest {
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(
@ -766,7 +770,7 @@ public abstract class BaseTest {
ST outputFileST = new ST(
"package main\n" +
"import (\n"
+" \"antlr4\"\n"
+" \"github.com/pboyer/antlr4/runtime/Go/antlr\"\n"
+" \"./parser\"\n"
+" \"os\"\n"
+")\n"
@ -779,10 +783,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\\<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"
@ -790,13 +794,13 @@ public abstract class BaseTest {
+ "}\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(
@ -804,7 +808,7 @@ public abstract class BaseTest {
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);
@ -821,21 +825,21 @@ public abstract class BaseTest {
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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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;");

View File

@ -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");

View File

@ -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))

View File

@ -232,7 +232,7 @@ func NewLexerModeAction(mode int) *LexerModeAction {
// <p>This action is implemented by calling {@link Lexer//mode} with the
// value provided by {@link //getMode}.</p>
func (l *LexerModeAction) execute(lexer Lexer) {
lexer.mode(l.mode)
lexer.setMode(l.mode)
}
func (l *LexerModeAction) Hash() string {

View File

@ -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())
}

View File

@ -11,7 +11,7 @@ import (
"fmt"
"strconv"
"github.com/antlr/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) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
package parser // <file.grammarName>
import "github.com/antlr/antlr4/runtime/Go/antlr"
import "github.com/pboyer/antlr4/runtime/Go/antlr"
// A complete listener for a parse tree produced by <file.parserName>
@ -50,7 +50,7 @@ BaseListenerFile(file, header) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
package parser // <file.grammarName>
import "github.com/antlr/antlr4/runtime/Go/antlr"
import "github.com/pboyer/antlr4/runtime/Go/antlr"
// A complete base listener for a parse tree produced by <file.parserName>
@ -78,7 +78,7 @@ VisitorFile(file, header) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
package parser // <file.grammarName>
import "github.com/antlr/antlr4/runtime/Go/antlr"
import "github.com/pboyer/antlr4/runtime/Go/antlr"
<header>
@ -98,7 +98,7 @@ BaseVisitorFile(file, header) ::= <<
<fileHeader(file.grammarFileName, file.ANTLRVersion)>
package parser // <file.grammarName>
import "github.com/antlr/antlr4/runtime/Go/antlr"
import "github.com/pboyer/antlr4/runtime/Go/antlr"
type Base<file.grammarName>Visitor struct {
*antlr.BaseParseTreeVisitor
@ -897,7 +897,7 @@ package parser
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/pboyer/antlr4/runtime/Go/antlr"
)
// suppress unused import error, many tests