Fix lexer test failures

This commit is contained in:
Peter Boyer 2016-01-16 17:11:00 -05:00
parent 8f70a6f553
commit 86d65cf719
6 changed files with 33 additions and 36 deletions

View File

@ -341,14 +341,6 @@ public abstract class BaseTest {
boolean defaultListener, String... extraOptions) {
ErrorQueue equeue = antlr(grammarFileName, grammarFileName, grammarStr,
defaultListener, extraOptions);
if (!equeue.errors.isEmpty()) {
System.err.println("PRINTING ERROR QUEUE");
System.err.println("++++++++++++++++++++++++++++++++++++++++++++++");
System.err.println(equeue.toString());
System.err.println("++++++++++++++++++++++++++++++++++++++++++++++");
return false;
}
// List<String> files = new ArrayList<String>();
// if (lexerName != null) {

View File

@ -1769,16 +1769,16 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleAlternativesWithCommonLabel_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(720);
StringBuilder grammarBuilder = new StringBuilder(576);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)};\n");
grammarBuilder.append("e returns [int v]\n");
grammarBuilder.append(" : e '*' e {$v = ((BinaryContext)$ctx).e(0).v * ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ((BinaryContext)$ctx).e(0).v + ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n");
grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n");
grammarBuilder.append(" | left=e INC {assert(((UnaryContext)$ctx).INC() != null)$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {assert(((UnaryContext)$ctx).DEC() != null)$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | ID {$v = 3;} # anID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -1799,16 +1799,16 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleAlternativesWithCommonLabel_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(720);
StringBuilder grammarBuilder = new StringBuilder(576);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)};\n");
grammarBuilder.append("e returns [int v]\n");
grammarBuilder.append(" : e '*' e {$v = ((BinaryContext)$ctx).e(0).v * ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ((BinaryContext)$ctx).e(0).v + ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n");
grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n");
grammarBuilder.append(" | left=e INC {assert(((UnaryContext)$ctx).INC() != null)$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {assert(((UnaryContext)$ctx).DEC() != null)$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | ID {$v = 3;} # anID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -1829,16 +1829,16 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleAlternativesWithCommonLabel_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(720);
StringBuilder grammarBuilder = new StringBuilder(576);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)};\n");
grammarBuilder.append("e returns [int v]\n");
grammarBuilder.append(" : e '*' e {$v = ((BinaryContext)$ctx).e(0).v * ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ((BinaryContext)$ctx).e(0).v + ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n");
grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n");
grammarBuilder.append(" | left=e INC {assert(((UnaryContext)$ctx).INC() != null)$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {assert(((UnaryContext)$ctx).DEC() != null)$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | ID {$v = 3;} # anID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -1859,16 +1859,16 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleAlternativesWithCommonLabel_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(720);
StringBuilder grammarBuilder = new StringBuilder(576);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)};\n");
grammarBuilder.append("e returns [int v]\n");
grammarBuilder.append(" : e '*' e {$v = ((BinaryContext)$ctx).e(0).v * ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ((BinaryContext)$ctx).e(0).v + ((BinaryContext)$ctx).e(1).v;} # binary\n");
grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n");
grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n");
grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n");
grammarBuilder.append(" | left=e INC {assert(((UnaryContext)$ctx).INC() != null)$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {assert(((UnaryContext)$ctx).DEC() != null)$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n");
grammarBuilder.append(" | left=e DEC {$v = $left.v - 1;} # unary\n");
grammarBuilder.append(" | ID {$v = 3;} # anID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");

View File

@ -200,7 +200,7 @@ public class TestParseTrees extends BaseTest {
@Test
public void testTokenAndRuleContextString() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(163);
StringBuilder grammarBuilder = new StringBuilder(166);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
@ -211,7 +211,7 @@ public class TestParseTrees extends BaseTest {
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' { \n");
grammarBuilder.append("fmt.Println(p.GetRuleInvocationStack())\n");
grammarBuilder.append("fmt.Println(p.GetRuleInvocationStack(nil))\n");
grammarBuilder.append("} ;");
String grammar = grammarBuilder.toString();
String input ="x";

View File

@ -441,11 +441,10 @@ public class TestParserExec extends BaseTest {
@Test
public void testListLabelForClosureContext() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(462);
StringBuilder grammarBuilder = new StringBuilder(420);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("ifStatement\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("List<?> __ttt__ = $ctx.elseIfStatement();\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : 'if' expression\n");
grammarBuilder.append(" ( ( 'then'\n");

View File

@ -9,7 +9,7 @@ type Parser interface {
Recognizer
GetInterpreter() *ParserATNSimulator
GetErrorHandler() ErrorStrategy
GetTokenStream() TokenStream
GetTokenFactory() TokenFactory
GetParserRuleContext() ParserRuleContext
@ -17,6 +17,8 @@ type Parser interface {
Consume() Token
GetParseListeners() []ParseTreeListener
GetErrorHandler() ErrorStrategy
SetErrorHandler(ErrorStrategy)
GetInputStream() IntStream
GetCurrentToken() Token
GetExpectedTokens() *IntervalSet
@ -108,6 +110,10 @@ func (p *BaseParser) GetErrorHandler() ErrorStrategy {
return p._errHandler
}
func (p *BaseParser) SetErrorHandler(e ErrorStrategy) {
p._errHandler = e
}
// Match current input symbol against {@code ttype}. If the symbol type
// Matches, {@link ANTLRErrorStrategy//ReportMatch} and {@link //consume} are
// called to complete the Match process.

View File

@ -187,9 +187,9 @@ func (this *CommonToken) SetText(text string) {
func (this *CommonToken) String() string {
var txt = this.GetText()
if txt != "" {
txt = strings.Replace(txt, "\n", "", -1)
txt = strings.Replace(txt, "\r", "", -1)
txt = strings.Replace(txt, "\t", "", -1)
txt = strings.Replace(txt, "\n", "\\n", -1)
txt = strings.Replace(txt, "\r", "\\r", -1)
txt = strings.Replace(txt, "\t", "\\t", -1)
} else {
txt = "<no text>"
}