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
This commit is contained in:
parent
34877767c1
commit
3434e802be
|
@ -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\\<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 +790,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 +804,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 +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<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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;");
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue