Fix a bunch of compiler errors in Go runtime-testsuite

This commit is contained in:
Peter Boyer 2016-01-06 19:12:37 -05:00
parent 81b47eedd7
commit 21999adb6e
44 changed files with 1436 additions and 672 deletions

35
pb/src/Test.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"antlr4"
"./parser"
"os"
)
type TreeShapeListener struct {
*parser.BaseExprListener
}
func NewTreeShapeListener() *TreeShapeListener {
return new(TreeShapeListener)
}
func (this *TreeShapeListener) EnterEveryRule(ctx antlr4.ParserRuleContext) {
for i := 0; i<ctx.GetChildCount(); i++ {
child := ctx.GetChild(i)
parentR,ok := child.GetParent().(antlr4.RuleNode)
if !ok || parentR.GetBaseRuleContext() != ctx.GetBaseRuleContext() {
panic("Invalid parse tree shape detected.")
}
}
}
func main() {
input := antlr4.NewFileStream(os.Args[1])
lexer := parser.NewExprLexer(input)
stream := antlr4.NewCommonTokenStream(lexer,0)
p := parser.NewExprParser(stream)
p.AddErrorListener(antlr4.NewDiagnosticErrorListener(true))
p.BuildParseTrees = true
tree := p.Prog()
antlr4.ParseTreeWalkerDefault.Walk(NewTreeShapeListener(), tree)
}

1
pb/src/input Normal file
View File

@ -0,0 +1 @@
b = 6

View File

@ -1,7 +1,4 @@
grammar Expr;
options { language = Go; }
prog: stat ;
stat: expr NEWLINE # printExpr
| ID '=' expr NEWLINE # assign
@ -21,4 +18,4 @@ SUB : '-' ;
ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace
WS : [ \t]+ -> skip ; // toss out whitespace

View File

@ -1,5 +1,5 @@
grammar M;
options { language = JavaScript; }
options { language = Go; }
import S;
s : a;
B : 'b';

15
pb/src/parser/T.g4 Normal file
View File

@ -0,0 +1,15 @@
grammar T;
prog
@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}
: expr_or_assign*;
expr_or_assign
: expr '++' {fmt.Println("fail.")}
| expr {fmt.Println("pass: "+$expr.text)}
;
expr: expr_primary ('<-' ID)?;
expr_primary
: '(' ID ')'
| ID '(' ID ')'
| ID
;
ID : [a-z]+ ;

View File

@ -0,0 +1,86 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link TListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class TBaseListener implements TListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterProg(TParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitProg(TParser.ProgContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr_or_assign(TParser.Expr_or_assignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr_or_assign(TParser.Expr_or_assignContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr(TParser.ExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr(TParser.ExprContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterExpr_primary(TParser.Expr_primaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitExpr_primary(TParser.Expr_primaryContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

105
pb/src/parser/TLexer.java Normal file
View File

@ -0,0 +1,105 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, ID=5;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"T__0", "T__1", "T__2", "T__3", "ID"
};
private static final String[] _LITERAL_NAMES = {
null, "'++'", "'<-'", "'('", "')'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, "ID"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public TLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "T.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\7\34\b\1\4\2\t\2"+
"\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\3\2\3\2\3\2\3\3\3\3\3\3\3\4\3\4\3\5\3"+
"\5\3\6\6\6\31\n\6\r\6\16\6\32\2\2\7\3\3\5\4\7\5\t\6\13\7\3\2\3\3\2c|\34"+
"\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\3\r\3\2"+
"\2\2\5\20\3\2\2\2\7\23\3\2\2\2\t\25\3\2\2\2\13\30\3\2\2\2\r\16\7-\2\2"+
"\16\17\7-\2\2\17\4\3\2\2\2\20\21\7>\2\2\21\22\7/\2\2\22\6\3\2\2\2\23\24"+
"\7*\2\2\24\b\3\2\2\2\25\26\7+\2\2\26\n\3\2\2\2\27\31\t\2\2\2\30\27\3\2"+
"\2\2\31\32\3\2\2\2\32\30\3\2\2\2\32\33\3\2\2\2\33\f\3\2\2\2\4\2\32\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,49 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link TParser}.
*/
public interface TListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link TParser#prog}.
* @param ctx the parse tree
*/
void enterProg(TParser.ProgContext ctx);
/**
* Exit a parse tree produced by {@link TParser#prog}.
* @param ctx the parse tree
*/
void exitProg(TParser.ProgContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr_or_assign}.
* @param ctx the parse tree
*/
void enterExpr_or_assign(TParser.Expr_or_assignContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr_or_assign}.
* @param ctx the parse tree
*/
void exitExpr_or_assign(TParser.Expr_or_assignContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr}.
* @param ctx the parse tree
*/
void enterExpr(TParser.ExprContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr}.
* @param ctx the parse tree
*/
void exitExpr(TParser.ExprContext ctx);
/**
* Enter a parse tree produced by {@link TParser#expr_primary}.
* @param ctx the parse tree
*/
void enterExpr_primary(TParser.Expr_primaryContext ctx);
/**
* Exit a parse tree produced by {@link TParser#expr_primary}.
* @param ctx the parse tree
*/
void exitExpr_primary(TParser.Expr_primaryContext ctx);
}

336
pb/src/parser/TParser.java Normal file
View File

@ -0,0 +1,336 @@
// Generated from T.g4 by ANTLR 4.5.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TParser extends Parser {
static { RuntimeMetaData.checkVersion("4.5.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, ID=5;
public static final int
RULE_prog = 0, RULE_expr_or_assign = 1, RULE_expr = 2, RULE_expr_primary = 3;
public static final String[] ruleNames = {
"prog", "expr_or_assign", "expr", "expr_primary"
};
private static final String[] _LITERAL_NAMES = {
null, "'++'", "'<-'", "'('", "')'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, "ID"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "T.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public TParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class ProgContext extends ParserRuleContext {
public List<Expr_or_assignContext> expr_or_assign() {
return getRuleContexts(Expr_or_assignContext.class);
}
public Expr_or_assignContext expr_or_assign(int i) {
return getRuleContext(Expr_or_assignContext.class,i);
}
public ProgContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_prog; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterProg(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitProg(this);
}
}
public final ProgContext prog() throws RecognitionException {
ProgContext _localctx = new ProgContext(_ctx, getState());
enterRule(_localctx, 0, RULE_prog);
_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(11);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==T__2 || _la==ID) {
{
{
setState(8);
expr_or_assign();
}
}
setState(13);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class Expr_or_assignContext extends ParserRuleContext {
public ExprContext expr;
public ExprContext expr() {
return getRuleContext(ExprContext.class,0);
}
public Expr_or_assignContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr_or_assign; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr_or_assign(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr_or_assign(this);
}
}
public final Expr_or_assignContext expr_or_assign() throws RecognitionException {
Expr_or_assignContext _localctx = new Expr_or_assignContext(_ctx, getState());
enterRule(_localctx, 2, RULE_expr_or_assign);
try {
setState(21);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(14);
expr();
setState(15);
match(T__0);
fmt.Println("fail.")
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(18);
((Expr_or_assignContext)_localctx).expr = expr();
fmt.Println("pass: "+(((Expr_or_assignContext)_localctx).expr!=null?_input.getText(((Expr_or_assignContext)_localctx).expr.start,((Expr_or_assignContext)_localctx).expr.stop):null))
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ExprContext extends ParserRuleContext {
public Expr_primaryContext expr_primary() {
return getRuleContext(Expr_primaryContext.class,0);
}
public TerminalNode ID() { return getToken(TParser.ID, 0); }
public ExprContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr(this);
}
}
public final ExprContext expr() throws RecognitionException {
ExprContext _localctx = new ExprContext(_ctx, getState());
enterRule(_localctx, 4, RULE_expr);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(23);
expr_primary();
setState(26);
_la = _input.LA(1);
if (_la==T__1) {
{
setState(24);
match(T__1);
setState(25);
match(ID);
}
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class Expr_primaryContext extends ParserRuleContext {
public List<TerminalNode> ID() { return getTokens(TParser.ID); }
public TerminalNode ID(int i) {
return getToken(TParser.ID, i);
}
public Expr_primaryContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_expr_primary; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).enterExpr_primary(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof TListener ) ((TListener)listener).exitExpr_primary(this);
}
}
public final Expr_primaryContext expr_primary() throws RecognitionException {
Expr_primaryContext _localctx = new Expr_primaryContext(_ctx, getState());
enterRule(_localctx, 6, RULE_expr_primary);
try {
setState(36);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(28);
match(T__2);
setState(29);
match(ID);
setState(30);
match(T__3);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(31);
match(ID);
setState(32);
match(T__2);
setState(33);
match(ID);
setState(34);
match(T__3);
}
break;
case 3:
enterOuterAlt(_localctx, 3);
{
setState(35);
match(ID);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\7)\4\2\t\2\4\3\t"+
"\3\4\4\t\4\4\5\t\5\3\2\7\2\f\n\2\f\2\16\2\17\13\2\3\3\3\3\3\3\3\3\3\3"+
"\3\3\3\3\5\3\30\n\3\3\4\3\4\3\4\5\4\35\n\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5"+
"\3\5\5\5\'\n\5\3\5\2\2\6\2\4\6\b\2\2)\2\r\3\2\2\2\4\27\3\2\2\2\6\31\3"+
"\2\2\2\b&\3\2\2\2\n\f\5\4\3\2\13\n\3\2\2\2\f\17\3\2\2\2\r\13\3\2\2\2\r"+
"\16\3\2\2\2\16\3\3\2\2\2\17\r\3\2\2\2\20\21\5\6\4\2\21\22\7\3\2\2\22\23"+
"\b\3\1\2\23\30\3\2\2\2\24\25\5\6\4\2\25\26\b\3\1\2\26\30\3\2\2\2\27\20"+
"\3\2\2\2\27\24\3\2\2\2\30\5\3\2\2\2\31\34\5\b\5\2\32\33\7\4\2\2\33\35"+
"\7\7\2\2\34\32\3\2\2\2\34\35\3\2\2\2\35\7\3\2\2\2\36\37\7\5\2\2\37 \7"+
"\7\2\2 \'\7\6\2\2!\"\7\7\2\2\"#\7\5\2\2#$\7\7\2\2$\'\7\6\2\2%\'\7\7\2"+
"\2&\36\3\2\2\2&!\3\2\2\2&%\3\2\2\2\'\t\3\2\2\2\6\r\27\34&";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -27,11 +27,11 @@ func main() {
a := antlr4.NewFileStream("foo.txt")
l := parser.NewMLexer(a)
l := parser.NewTLexer(a)
s := antlr4.NewCommonTokenStream(l, 0)
p := parser.NewMParser(s)
p := parser.NewTParser(s)
p.BuildParseTrees = true

View File

@ -173,9 +173,9 @@ AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use type system
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%int <n> = <v>;%>
InitIntMember(n,v) ::= <%var <n> int = <v>;%>
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%>
InitBooleanMember(n,v) ::= <%var <n> bool= <v>;%>
GetMember(n) ::= <%this.<n>%>
@ -195,39 +195,39 @@ DumpDFA() ::= "p.DumpDFA()"
Pass() ::= ""
StringList() ::= "List\<String>"
StringList() ::= "[]string"
BuildParseTrees() ::= "this.BuildParseTrees = true"
BailErrorStrategy() ::= <%SetErrorHandler(NewBailErrorStrategy());%>
BailErrorStrategy() ::= <%SetErrorHandler(NewBailErrorStrategy())%>
ToStringTree(s) ::= <%<s>.toStringTree(this)%>
ToStringTree(s) ::= <%<s>.ToStringTree(nil,p)%>
Column() ::= "this.GetCharPositionInLine()"
Column() ::= "l.GetCharPositionInLine()"
Text() ::= "this.GetText()"
Text() ::= "l.GetText()"
ValEquals(a,b) ::= <%<a>==<b>%>
TextEquals(a) ::= <%this.GetText().equals("<a>")%>
TextEquals(a) ::= <%l.GetText() == "<a>"%>
PlusText(a) ::= <%"<a>" + this.GetText()%>
PlusText(a) ::= <%"<a>" + l.GetText()%>
InputText() ::= "this._input.GetText()"
InputText() ::= "p.GetInput().GetText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).GetText().equals(<v>)%>
LTEquals(i, v) ::= <%p.GetTokenStream().LT(<i>).GetText() == <v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
LANotEquals(i, v) ::= <%p.GetTokenStream().LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartCharPositionInLine==<i>%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "this.GetExpectedTokens().toString(this.tokenNames)"
GetExpectedTokenNames() ::= "p.GetExpectedTokens().StringVerbose(p.GetTokenNames(), nil, false)"
RuleInvocationStack() ::= "GetRuleInvocationStack()"
RuleInvocationStack() ::= "p.GetRuleInvocationStack()"
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);>>
LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);>>
ParserPropertyMember() ::= <<
@members {
@ -240,138 +240,193 @@ bool Property() {
PositionAdjustingLexer() ::= <<
package antlrtest
//@Override
func (this *PositionAdjustingLexer) NextToken() *Token {
if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {
_interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
return super.nextToken();
type PositionAdjustingLexer struct {
antlr4.*BaseLexer
}
func NewPositionAdjustingLexer(input antlr4.CharStream) *PositionAdjustingLexer {
l := new(PositionAdjustingLexer)
l.BaseLexer = antlr4.NewBaseLexer( input )
return l
}
func (this *PositionAdjustingLexer) NextToken() *Token {
_,ok := this._interp.(*PositionAdjustingLexerATNSimulator)
if !ok {
this._interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache)
}
return this.BaseLexer.NextToken()
}
//@Override
func (this *PositionAdjustingLexer) Emit() *Token {
switch (_type) {
case TOKENS:
HandleAcceptPositionForKeyword("tokens");
this.HandleAcceptPositionForKeyword("tokens")
case LABEL:
HandleAcceptPositionForIdentifier();
this.HandleAcceptPositionForIdentifier()
}
return super.emit();
return this.BaseLexer.Emit()
}
func (this *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {
String tokenText = GetText();
int identifierLength = 0;
for (identifierLength \< tokenText.length() && isIdentifierChar(tokenText.charAt(identifierLength))) {
identifierLength++;
tokenText := GetText()
identifierLength int = 0
for identifierLength \< len(tokenText) && isIdentifierChar(tokenText.charAt(identifierLength)) {
identifierLength += 1
}
if (GetInputStream().Index() > _tokenStartCharIndex + identifierLength) {
int offset = identifierLength - 1;
GetInterpreter().ResetAcceptPosition(GetInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
if GetInputStream().Index() > _tokenStartCharIndex + identifierLength {
offset int = identifierLength - 1
this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)
return true
}
return false;
return false
}
func (this *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {
if (GetInputStream().Index() > _tokenStartCharIndex + keyword.length()) {
int offset = keyword.length() - 1;
this.GetInterpreter().ResetAcceptPosition(GetInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
if this.GetInputStream().Index() > this.TokenStartCharIndex + len(keyword) {
offset := len(keyword) - 1
this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)
return true
}
return false;
return false
}
//@Override
func (s *PositionAdjustingLexerATNSimulator) GetInterpreter() *LexerATNSimulator {
return s // return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter();
func (s *PositionAdjustingLexer) GetInterpreter() *LexerATNSimulator {
return s // return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter()
}
bool isIdentifierChar(char c) {
return Character.isLetterOrDigit(c) || c == '_';
func isIdentifierChar(c rune) bool {
return Character.isLetterOrDigit(c) || c == '_'
}
type PositionAdjustingLexerATNSimulator struct {
*antlr4.LexerATNSimulator
}
func NewPositionAdjustingLexerATNSimulator(recog antlr4.ILexer, atn *antlr4.ATN, decisionToDFA []*antlr4.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {
super(recog, atn, decisionToDFA, sharedContextCache);
func NewPositionAdjustingLexerATNSimulator(recog antlr4.Lexer, atn *antlr4.ATN, decisionToDFA []*antlr4.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {
l := new(PositionAdjustingLexerATNSimulator)
l.LexerATNSimulator = antlr4.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache)
return l
}
func ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {
input.seek(index);
func (this *NewPositionAdjustingLexerATNSimulator) ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {
this.input.seek(index);
this.line = line;
this.charPositionInLine = charPositionInLine;
consume(input);
this.consume(input);
}
>>
BasicListener(X) ::= <<
type LeafListener extends TBaseListener {
func visitTerminal(TerminalNode node) {
fmt.Println(node.GetSymbol().GetText())
}
func LeafListener struct {
*parser.BaseTListener
}
func NewLeafListener() *LeafListener {
l := new(LeafListener)
l.BaseTListener = new(parser.BaseTListener)
return l
}
func (this *LeafListener) VisitTerminal( node antlr4.TerminalNode ) {
fmt.Println(node.GetSymbol().GetText())
}
>>
WalkListener(s) ::= <<
ParseTreeWalker walker = NewParseTreeWalker();
walker.walk(NewLeafListener(), <s>);
walker := antlr4.NewParseTreeWalker();
walker.Walk(NewLeafListener(), <s>);
>>
TokenGetterListener(X) ::= <<
type LeafListener extends TBaseListener {
func ExitA(TParser.AContext ctx) {
if (ctx.GetChildCount()==2)
fmt.Printf("%s %s %s",ctx.INT(0).GetSymbol().GetText(),
ctx.INT(1).GetSymbol().GetText(),ctx.INT());
else
fmt.Println(ctx.ID().GetSymbol())
func LeafListener struct {
*parser.BaseTListener
}
func NewLeafListener() *LeafListener {
l := new(LeafListener)
l.BaseTListener = new(parser.BaseTListener)
return l
}
func (this *LeafListener) ExitA(ctx *parser.AContext) {
if (ctx.GetChildCount()==2){
fmt.Printf("%s %s %s",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());
} else {
fmt.Println(ctx.ID().GetSymbol())
}
}
>>
RuleGetterListener(X) ::= <<
type LeafListener extends TBaseListener {
func ExitA(TParser.AContext ctx) {
if (ctx.GetChildCount()==2) {
fmt.Printf("%s %s %s",ctx.b(0).start.GetText(),
ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());
} else
fmt.Println(ctx.b(0).start.GetText());
func LeafListener struct {
*parser.BaseTListener
}
func NewLeafListener() *LeafListener {
l := new(LeafListener)
l.BaseTListener = new(parser.BaseTListener)
return l
}
func (this *LeafListener) ExitA(ctx parser.AContext) {
if (ctx.GetChildCount()==2) {
fmt.Printf("%s %s %s",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());
} else
fmt.Println(ctx.b(0).start.GetText());
}
}
>>
LRListener(X) ::= <<
type LeafListener extends TBaseListener {
func ExitE(TParser.EContext ctx) {
if (ctx.GetChildCount()==3) {
fmt.Printf("%s %s %s\n",ctx.e(0).start.GetText(),
ctx.e(1).start.GetText(), ctx.e().Get(0).start.GetText());
} else
fmt.Println(ctx.INT().GetSymbol().GetText());
func LeafListener struct {
*parser.BaseTListener
}
func NewLeafListener() *LeafListener {
l := new(LeafListener)
l.BaseTListener = new(parser.BaseTListener)
return l
}
func (this *LeafListener) ExitE(ctx *parser.EContext) {
if (ctx.GetChildCount()==3) {
fmt.Printf("%s %s %s\n",ctx.e(0).GetStart().GetText(), ctx.e(1).GetStart().GetText(), ctx.e().Get(0).GetStart().GetText());
} else {
fmt.Println(ctx.INT().GetSymbol().GetText())
}
}
>>
LRWithLabelsListener(X) ::= <<
type LeafListener extends TBaseListener {
func ExitCall(TParser.CallContext ctx) {
fmt.Printf("%s %s",ctx.e().start.GetText(),ctx.eList());
}
func ExitInt(TParser.IntContext ctx) {
fmt.Println(ctx.INT().GetSymbol().GetText());
}
func LeafListener struct {
*parser.BaseTListener
}
func NewLeafListener() *LeafListener {
l := new(LeafListener)
l.BaseTListener = new(parser.BaseTListener)
return l`
}
func (this *LeafListener) ExitCall(ctx *parser.CallContext) {
fmt.Printf("%s %s",ctx.e().GetStart().GetText(),ctx.eList());
}
func (this *LeafListener) ExitInt(ctx *parser.IntContext) {
fmt.Println(ctx.INT().GetSymbol().GetText());
}
>>
@ -384,12 +439,15 @@ func foo() {
>>
Declare_foo() ::= <<
func foo() {fmt.Println("foo")}
func foo() {
fmt.Println("foo")
}
>>
Invoke_foo() ::= "foo();"
Invoke_foo() ::= "foo()"
Declare_pred() ::= <<bool pred(bool v) {
Declare_pred() ::= <<
bool pred(bool v) {
fmt.Println("eval="+fmt.Sprint(v))
return v
}

View File

@ -802,7 +802,7 @@ public abstract class BaseTest {
if (debug) {
createParserST = new ST(
" p := parser.New<parserName>(stream)\n"
+ " p.AddErrorListener(antlr4.NewDiagnosticErrorListener())\n");
+ " p.AddErrorListener(antlr4.NewDiagnosticErrorListener(true))\n");
}
outputFileST.add("createParser", createParserST);
outputFileST.add("parserName", parserName);

View File

@ -110,15 +110,17 @@ public class TestCompositeParsers extends BaseTest {
String slave_S =
"parser grammar S;\n" +
"@parser::members {\n" +
" func foo() {fmt.Println(\"foo\")}\n" +
"func foo() {\n" +
" fmt.Println(\"foo\")\n" +
"}\n" +
"}\n" +
"a : B;";
writeFile(parserpkgdir, "S.g4", slave_S);
StringBuilder grammarBuilder = new StringBuilder(122);
StringBuilder grammarBuilder = new StringBuilder(121);
grammarBuilder.append("grammar M; // uses no rules from the import\n");
grammarBuilder.append("import S;\n");
grammarBuilder.append("s : 'b' {foo();} ; // gS is import pointer\n");
grammarBuilder.append("s : 'b' {foo()} ; // gS is import pointer\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
String grammar = grammarBuilder.toString();
String input ="b";
@ -377,7 +379,7 @@ public class TestCompositeParsers extends BaseTest {
mkdir(parserpkgdir);
String slave_S =
"parser grammar S;\n" +
"a @after {int x = 0;} : B;";
"a @after {var x int = 0;} : B;";
writeFile(parserpkgdir, "S.g4", slave_S);
StringBuilder grammarBuilder = new StringBuilder(62);

View File

@ -34,10 +34,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testAmbiguityNoLoop() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(208);
StringBuilder grammarBuilder = new StringBuilder(218);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("prog\n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(" : expr expr {fmt.Println(\"alt 1\")}\n");
grammarBuilder.append(" | expr\n");
grammarBuilder.append(" ;\n");
@ -154,11 +154,11 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testExprAmbiguity_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(282);
StringBuilder grammarBuilder = new StringBuilder(293);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.toStringTree(this))};\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
grammarBuilder.append(" expr[int _p]\n");
grammarBuilder.append(" : ID \n");
grammarBuilder.append(" ( \n");
@ -184,11 +184,11 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testExprAmbiguity_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(282);
StringBuilder grammarBuilder = new StringBuilder(293);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.toStringTree(this))};\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(": expr[0] {fmt.Println($expr.ctx.ToStringTree(nil,p))};\n");
grammarBuilder.append(" expr[int _p]\n");
grammarBuilder.append(" : ID \n");
grammarBuilder.append(" ( \n");
@ -216,10 +216,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -242,10 +242,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -271,10 +271,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -301,10 +301,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -332,10 +332,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -366,10 +366,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testFullContextIF_THEN_ELSEParse_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(233);
StringBuilder grammarBuilder = new StringBuilder(243);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s \n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append("@after {p.DumpDFA()}\n");
grammarBuilder.append(" : '{' stat* '}' ;\n");
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
@ -400,10 +400,10 @@ public class TestFullContextParsing extends BaseTest {
@Test
public void testLoopsSimulateTailRecursion() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(307);
StringBuilder grammarBuilder = new StringBuilder(317);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("prog\n");
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
grammarBuilder.append("@init {p.Interpreter.SetPredictionMode(antlr4.PredictionModeLLExactAmbigDetection);}\n");
grammarBuilder.append(" : expr_or_assign*;\n");
grammarBuilder.append("expr_or_assign\n");
grammarBuilder.append(" : expr '++' {fmt.Println(\"fail.\")}\n");

View File

@ -187,9 +187,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -215,9 +215,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_10() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -243,9 +243,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -271,9 +271,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -299,9 +299,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -327,9 +327,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -355,9 +355,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -383,9 +383,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_7() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -411,9 +411,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_8() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -439,9 +439,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDeclarations_9() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(391);
StringBuilder grammarBuilder = new StringBuilder(392);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : declarator EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("declarator\n");
grammarBuilder.append(" : declarator '[' e ']'\n");
grammarBuilder.append(" | declarator '[' ']'\n");
@ -467,9 +467,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDirectCallToLeftRecursiveRule_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(119);
StringBuilder grammarBuilder = new StringBuilder(120);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a @after {fmt.Println($ctx.toStringTree(this))} : a ID\n");
grammarBuilder.append("a @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -487,9 +487,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDirectCallToLeftRecursiveRule_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(119);
StringBuilder grammarBuilder = new StringBuilder(120);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a @after {fmt.Println($ctx.toStringTree(this))} : a ID\n");
grammarBuilder.append("a @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -507,9 +507,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testDirectCallToLeftRecursiveRule_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(119);
StringBuilder grammarBuilder = new StringBuilder(120);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a @after {fmt.Println($ctx.toStringTree(this))} : a ID\n");
grammarBuilder.append("a @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
@ -527,9 +527,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -554,9 +554,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -581,9 +581,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -608,9 +608,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -635,9 +635,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -662,9 +662,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -689,9 +689,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testExpressions_7() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(250);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("e : e '.' ID\n");
grammarBuilder.append(" | e '.' 'this'\n");
grammarBuilder.append(" | '-' e\n");
@ -716,9 +716,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -787,9 +787,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_10() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -858,9 +858,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_11() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -929,9 +929,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_12() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1000,9 +1000,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1071,9 +1071,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1142,9 +1142,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1213,9 +1213,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1284,9 +1284,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1355,9 +1355,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_7() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1426,9 +1426,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_8() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1497,9 +1497,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testJavaExpressions_9() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(1247);
StringBuilder grammarBuilder = new StringBuilder(1248);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow\n");
grammarBuilder.append("expressionList\n");
grammarBuilder.append(" : e (',' e)*\n");
grammarBuilder.append(" ;\n");
@ -1568,9 +1568,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testLabelsOnOpSubrule_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(170);
StringBuilder grammarBuilder = new StringBuilder(171);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}\n");
grammarBuilder.append(" | INT {}\n");
grammarBuilder.append(" | '(' x=e ')' {}\n");
@ -1590,9 +1590,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testLabelsOnOpSubrule_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(170);
StringBuilder grammarBuilder = new StringBuilder(171);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}\n");
grammarBuilder.append(" | INT {}\n");
grammarBuilder.append(" | '(' x=e ')' {}\n");
@ -1612,9 +1612,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testLabelsOnOpSubrule_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(170);
StringBuilder grammarBuilder = new StringBuilder(171);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}\n");
grammarBuilder.append(" | INT {}\n");
grammarBuilder.append(" | '(' x=e ')' {}\n");
@ -1634,9 +1634,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActionsPredicatesOptions_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(239);
StringBuilder grammarBuilder = new StringBuilder(240);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{true}?\n");
grammarBuilder.append(" | a=e op=('+'|'-') b=e {}<p=3>{true}?<fail='Message'>\n");
grammarBuilder.append(" | INT {}{}\n");
@ -1657,9 +1657,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActionsPredicatesOptions_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(239);
StringBuilder grammarBuilder = new StringBuilder(240);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{true}?\n");
grammarBuilder.append(" | a=e op=('+'|'-') b=e {}<p=3>{true}?<fail='Message'>\n");
grammarBuilder.append(" | INT {}{}\n");
@ -1680,9 +1680,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActionsPredicatesOptions_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(239);
StringBuilder grammarBuilder = new StringBuilder(240);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{true}?\n");
grammarBuilder.append(" | a=e op=('+'|'-') b=e {}<p=3>{true}?<fail='Message'>\n");
grammarBuilder.append(" | INT {}{}\n");
@ -1703,9 +1703,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActions_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(177);
StringBuilder grammarBuilder = new StringBuilder(178);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{}\n");
grammarBuilder.append(" | INT {}{}\n");
grammarBuilder.append(" | '(' x=e ')' {}{}\n");
@ -1725,9 +1725,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActions_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(177);
StringBuilder grammarBuilder = new StringBuilder(178);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{}\n");
grammarBuilder.append(" | INT {}{}\n");
grammarBuilder.append(" | '(' x=e ')' {}{}\n");
@ -1747,9 +1747,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testMultipleActions_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(177);
StringBuilder grammarBuilder = new StringBuilder(178);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e ;\n");
grammarBuilder.append("e : a=e op=('*'|'/') b=e {}{}\n");
grammarBuilder.append(" | INT {}{}\n");
grammarBuilder.append(" | '(' x=e ')' {}{}\n");
@ -1889,10 +1889,10 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testPrecedenceFilterConsidersContext() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(142);
StringBuilder grammarBuilder = new StringBuilder(143);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("prog \n");
grammarBuilder.append("@after {fmt.Println($ctx.toStringTree(this))}\n");
grammarBuilder.append("@after {fmt.Println($ctx.ToStringTree(nil,p))}\n");
grammarBuilder.append(": statement* EOF {};\n");
grammarBuilder.append("statement: letterA | statement letterA 'b' ;\n");
grammarBuilder.append("letterA: 'a';");
@ -2093,9 +2093,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList1_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(300);
StringBuilder grammarBuilder = new StringBuilder(301);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr (',' b+=expr)* '>>' c=expr #Send\n");
@ -2120,9 +2120,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList1_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(300);
StringBuilder grammarBuilder = new StringBuilder(301);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr (',' b+=expr)* '>>' c=expr #Send\n");
@ -2147,9 +2147,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList1_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(300);
StringBuilder grammarBuilder = new StringBuilder(301);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr (',' b+=expr)* '>>' c=expr #Send\n");
@ -2174,9 +2174,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList1_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(300);
StringBuilder grammarBuilder = new StringBuilder(301);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr (',' b+=expr)* '>>' c=expr #Send\n");
@ -2201,9 +2201,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList2_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(317);
StringBuilder grammarBuilder = new StringBuilder(318);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr ',' b+=expr #Comma\n");
@ -2227,9 +2227,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList2_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(317);
StringBuilder grammarBuilder = new StringBuilder(318);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr ',' b+=expr #Comma\n");
@ -2253,9 +2253,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList2_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(317);
StringBuilder grammarBuilder = new StringBuilder(318);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr ',' b+=expr #Comma\n");
@ -2279,9 +2279,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActionsList2_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(317);
StringBuilder grammarBuilder = new StringBuilder(318);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : expr EOF;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : expr EOF;\n");
grammarBuilder.append("expr:\n");
grammarBuilder.append(" a=expr '*' a=expr #Factor\n");
grammarBuilder.append(" | b+=expr ',' b+=expr #Comma\n");
@ -2305,10 +2305,10 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActions_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(253);
StringBuilder grammarBuilder = new StringBuilder(249);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)}; \n");
grammarBuilder.append("e returns [int v, List<String> ignored]\n");
grammarBuilder.append("e returns [int v, []string ignored]\n");
grammarBuilder.append(" : a=e '*' b=e {$v = $a.v * $b.v;}\n");
grammarBuilder.append(" | a=e '+' b=e {$v = $a.v + $b.v;}\n");
grammarBuilder.append(" | INT {$v = $INT.int;}\n");
@ -2329,10 +2329,10 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActions_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(253);
StringBuilder grammarBuilder = new StringBuilder(249);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)}; \n");
grammarBuilder.append("e returns [int v, List<String> ignored]\n");
grammarBuilder.append("e returns [int v, []string ignored]\n");
grammarBuilder.append(" : a=e '*' b=e {$v = $a.v * $b.v;}\n");
grammarBuilder.append(" | a=e '+' b=e {$v = $a.v + $b.v;}\n");
grammarBuilder.append(" | INT {$v = $INT.int;}\n");
@ -2353,10 +2353,10 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActions_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(253);
StringBuilder grammarBuilder = new StringBuilder(249);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)}; \n");
grammarBuilder.append("e returns [int v, List<String> ignored]\n");
grammarBuilder.append("e returns [int v, []string ignored]\n");
grammarBuilder.append(" : a=e '*' b=e {$v = $a.v * $b.v;}\n");
grammarBuilder.append(" | a=e '+' b=e {$v = $a.v + $b.v;}\n");
grammarBuilder.append(" | INT {$v = $INT.int;}\n");
@ -2377,10 +2377,10 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testReturnValueAndActions_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(253);
StringBuilder grammarBuilder = new StringBuilder(249);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : e {fmt.Println($e.v)}; \n");
grammarBuilder.append("e returns [int v, List<String> ignored]\n");
grammarBuilder.append("e returns [int v, []string ignored]\n");
grammarBuilder.append(" : a=e '*' b=e {$v = $a.v * $b.v;}\n");
grammarBuilder.append(" | a=e '+' b=e {$v = $a.v + $b.v;}\n");
grammarBuilder.append(" | INT {$v = $INT.int;}\n");
@ -2401,9 +2401,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testSemPred() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(135);
StringBuilder grammarBuilder = new StringBuilder(136);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : a ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ;\n");
grammarBuilder.append("a : a {true}? ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
@ -2422,9 +2422,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testSemPredFailOption() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(159);
StringBuilder grammarBuilder = new StringBuilder(160);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : a ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ;\n");
grammarBuilder.append("a : a ID {false}?<fail='custom message'>\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
@ -2444,9 +2444,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testSimple_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(127);
StringBuilder grammarBuilder = new StringBuilder(128);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : a ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ;\n");
grammarBuilder.append("a : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
@ -2465,9 +2465,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testSimple_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(127);
StringBuilder grammarBuilder = new StringBuilder(128);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : a ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ;\n");
grammarBuilder.append("a : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
@ -2486,9 +2486,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testSimple_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(127);
StringBuilder grammarBuilder = new StringBuilder(128);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : a ;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : a ;\n");
grammarBuilder.append("a : a ID\n");
grammarBuilder.append(" | ID\n");
grammarBuilder.append(" ;\n");
@ -2507,9 +2507,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2531,9 +2531,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2555,9 +2555,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2579,9 +2579,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2603,9 +2603,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2627,9 +2627,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2651,9 +2651,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_7() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2675,9 +2675,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_8() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2699,9 +2699,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExprExplicitAssociativity_9() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(284);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e :<assoc=right> e '*' e\n");
grammarBuilder.append(" |<assoc=right> e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2723,9 +2723,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2747,9 +2747,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2771,9 +2771,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_3() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2795,9 +2795,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_4() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2819,9 +2819,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_5() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2843,9 +2843,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_6() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2867,9 +2867,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_7() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2891,9 +2891,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_8() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");
@ -2915,9 +2915,9 @@ public class TestLeftRecursion extends BaseTest {
@Test
public void testTernaryExpr_9() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(258);
StringBuilder grammarBuilder = new StringBuilder(259);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s @after {fmt.Println($ctx.toStringTree(this))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("s @after {fmt.Println($ctx.ToStringTree(nil,p))} : e EOF ; // must indicate EOF can follow or 'a<EOF>' won't match\n");
grammarBuilder.append("e : e '*' e\n");
grammarBuilder.append(" | e '+' e\n");
grammarBuilder.append(" |<assoc=right> e '?' e ':' e\n");

View File

@ -13,13 +13,13 @@ public class TestLexerExec extends BaseTest {
public void testActionPlacement() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(283);
StringBuilder grammarBuilder = new StringBuilder(268);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("I : ({fmt.Println(\"stuff fail: \" + this.GetText())} 'a'\n");
grammarBuilder.append("| {fmt.Println(\"stuff0: \" + this.GetText())}\n");
grammarBuilder.append(" 'a' {fmt.Println(\"stuff1: \" + this.GetText())}\n");
grammarBuilder.append(" 'b' {fmt.Println(\"stuff2: \" + this.GetText())})\n");
grammarBuilder.append(" {fmt.Println(this.GetText())} ;\n");
grammarBuilder.append("I : ({fmt.Println(\"stuff fail: \" + l.GetText())} 'a'\n");
grammarBuilder.append("| {fmt.Println(\"stuff0: \" + l.GetText())}\n");
grammarBuilder.append(" 'a' {fmt.Println(\"stuff1: \" + l.GetText())}\n");
grammarBuilder.append(" 'b' {fmt.Println(\"stuff2: \" + l.GetText())})\n");
grammarBuilder.append(" {fmt.Println(l.GetText())} ;\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip ;\n");
grammarBuilder.append("J : .;");
String grammar = grammarBuilder.toString();
@ -345,9 +345,9 @@ public class TestLexerExec extends BaseTest {
public void testGreedyConfigs() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(98);
StringBuilder grammarBuilder = new StringBuilder(95);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("I : ('a' | 'ab') {fmt.Println(this.GetText())} ;\n");
grammarBuilder.append("I : ('a' | 'ab') {fmt.Println(l.GetText())} ;\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip ;\n");
grammarBuilder.append("J : .;");
String grammar = grammarBuilder.toString();
@ -4503,11 +4503,11 @@ public class TestLexerExec extends BaseTest {
public void testNonGreedyConfigs() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(132);
StringBuilder grammarBuilder = new StringBuilder(126);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("I : .*? ('a' | 'ab') {fmt.Println(this.GetText())} ;\n");
grammarBuilder.append("I : .*? ('a' | 'ab') {fmt.Println(l.GetText())} ;\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip ;\n");
grammarBuilder.append("J : . {fmt.Println(this.GetText())};");
grammarBuilder.append("J : . {fmt.Println(l.GetText())};");
String grammar = grammarBuilder.toString();
String input ="ab";
String found = execLexer("L.g4", grammar, "L", input, false);
@ -4625,82 +4625,97 @@ public class TestLexerExec extends BaseTest {
public void testPositionAdjustingLexer() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(2633);
StringBuilder grammarBuilder = new StringBuilder(3026);
grammarBuilder.append("lexer grammar PositionAdjustingLexer;\n");
grammarBuilder.append("\n");
grammarBuilder.append("@members {\n");
grammarBuilder.append("package antlrtest\n");
grammarBuilder.append("\n");
grammarBuilder.append("//@Override\n");
grammarBuilder.append("func (this *PositionAdjustingLexer) NextToken() *Token {\n");
grammarBuilder.append(" if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {\n");
grammarBuilder.append(" _interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return super.nextToken();\n");
grammarBuilder.append("type PositionAdjustingLexer struct {\n");
grammarBuilder.append(" antlr4.*BaseLexer\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewPositionAdjustingLexer(input antlr4.CharStream) *PositionAdjustingLexer {\n");
grammarBuilder.append(" l := new(PositionAdjustingLexer)\n");
grammarBuilder.append(" l.BaseLexer = antlr4.NewBaseLexer( input )\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *PositionAdjustingLexer) NextToken() *Token {\n");
grammarBuilder.append("\n");
grammarBuilder.append(" _,ok := this._interp.(*PositionAdjustingLexerATNSimulator)\n");
grammarBuilder.append("\n");
grammarBuilder.append(" if !ok {\n");
grammarBuilder.append(" this._interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache)\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return this.BaseLexer.NextToken()\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("//@Override\n");
grammarBuilder.append("func (this *PositionAdjustingLexer) Emit() *Token {\n");
grammarBuilder.append(" switch (_type) {\n");
grammarBuilder.append(" case TOKENS:\n");
grammarBuilder.append(" HandleAcceptPositionForKeyword(\"tokens\");\n");
grammarBuilder.append(" this.HandleAcceptPositionForKeyword(\"tokens\")\n");
grammarBuilder.append("\n");
grammarBuilder.append(" case LABEL:\n");
grammarBuilder.append(" HandleAcceptPositionForIdentifier();\n");
grammarBuilder.append(" this.HandleAcceptPositionForIdentifier()\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return super.emit();\n");
grammarBuilder.append(" return this.BaseLexer.Emit()\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {\n");
grammarBuilder.append(" String tokenText = GetText();\n");
grammarBuilder.append(" int identifierLength = 0;\n");
grammarBuilder.append(" for (identifierLength < tokenText.length() && isIdentifierChar(tokenText.charAt(identifierLength))) {\n");
grammarBuilder.append(" identifierLength++;\n");
grammarBuilder.append(" tokenText := GetText()\n");
grammarBuilder.append(" identifierLength int = 0\n");
grammarBuilder.append(" for identifierLength < len(tokenText) && isIdentifierChar(tokenText.charAt(identifierLength)) {\n");
grammarBuilder.append(" identifierLength += 1\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" if (GetInputStream().Index() > _tokenStartCharIndex + identifierLength) {\n");
grammarBuilder.append(" int offset = identifierLength - 1;\n");
grammarBuilder.append(" GetInterpreter().ResetAcceptPosition(GetInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);\n");
grammarBuilder.append(" return true;\n");
grammarBuilder.append(" if GetInputStream().Index() > _tokenStartCharIndex + identifierLength {\n");
grammarBuilder.append(" offset int = identifierLength - 1\n");
grammarBuilder.append(" this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)\n");
grammarBuilder.append(" return true\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return false;\n");
grammarBuilder.append(" return false\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {\n");
grammarBuilder.append(" if (GetInputStream().Index() > _tokenStartCharIndex + keyword.length()) {\n");
grammarBuilder.append(" int offset = keyword.length() - 1;\n");
grammarBuilder.append(" this.GetInterpreter().ResetAcceptPosition(GetInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);\n");
grammarBuilder.append(" return true;\n");
grammarBuilder.append(" if this.GetInputStream().Index() > this.TokenStartCharIndex + len(keyword) {\n");
grammarBuilder.append(" offset := len(keyword) - 1\n");
grammarBuilder.append(" this.GetInterpreter().ResetAcceptPosition(this.GetInputStream(), this.TokenStartCharIndex + offset, this.TokenStartLine, this.TokenStartCharPositionInLine + offset)\n");
grammarBuilder.append(" return true\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("\n");
grammarBuilder.append(" return false;\n");
grammarBuilder.append(" return false\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("//@Override\n");
grammarBuilder.append("func (s *PositionAdjustingLexerATNSimulator) GetInterpreter() *LexerATNSimulator {\n");
grammarBuilder.append(" return s // return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter();\n");
grammarBuilder.append("func (s *PositionAdjustingLexer) GetInterpreter() *LexerATNSimulator {\n");
grammarBuilder.append(" return s // return super.(*PositionAdjustingLexerATNSimulator).GetInterpreter()\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("bool isIdentifierChar(char c) {\n");
grammarBuilder.append(" return Character.isLetterOrDigit(c) || c == '_';\n");
grammarBuilder.append("func isIdentifierChar(c rune) bool {\n");
grammarBuilder.append(" return Character.isLetterOrDigit(c) || c == '_'\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("type PositionAdjustingLexerATNSimulator struct {\n");
grammarBuilder.append(" *antlr4.LexerATNSimulator\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewPositionAdjustingLexerATNSimulator(recog antlr4.ILexer, atn *antlr4.ATN, decisionToDFA []*antlr4.DFA, sharedContextCache *PredictionContextCache) *PositionAdjustingLexerATNSimulator {\n");
grammarBuilder.append(" super(recog, atn, decisionToDFA, sharedContextCache);\n");
grammarBuilder.append("func NewPositionAdjustingLexerATNSimulator(recog antlr4.Lexer, atn *antlr4.ATN, decisionToDFA []*antlr4.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("\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {\n");
grammarBuilder.append(" input.seek(index);\n");
grammarBuilder.append("func (this *NewPositionAdjustingLexerATNSimulator) ResetAcceptPosition(input CharStream, index, line, charPositionInLine int) {\n");
grammarBuilder.append(" this.input.seek(index);\n");
grammarBuilder.append(" this.line = line;\n");
grammarBuilder.append(" this.charPositionInLine = charPositionInLine;\n");
grammarBuilder.append(" consume(input);\n");
grammarBuilder.append(" this.consume(input);\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("}\n");

View File

@ -12,24 +12,32 @@ public class TestListeners extends BaseTest {
@Test
public void testBasic() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(433);
StringBuilder grammarBuilder = new StringBuilder(583);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func visitTerminal(TerminalNode node) {\n");
grammarBuilder.append(" fmt.Println(node.GetSymbol().GetText())\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) VisitTerminal( node antlr4.TerminalNode ) {\n");
grammarBuilder.append(" fmt.Println(node.GetSymbol().GetText())\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : INT INT\n");
@ -56,28 +64,36 @@ public class TestListeners extends BaseTest {
@Test
public void testLR() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(607);
StringBuilder grammarBuilder = new StringBuilder(760);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitE(TParser.EContext ctx) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==3) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\",ctx.e(0).start.GetText(),\n");
grammarBuilder.append(" ctx.e(1).start.GetText(), ctx.e().Get(0).start.GetText());\n");
grammarBuilder.append(" } else\n");
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText());\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitE(ctx *parser.EContext) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==3) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\",ctx.e(0).GetStart().GetText(), ctx.e(1).GetStart().GetText(), ctx.e().Get(0).GetStart().GetText());\n");
grammarBuilder.append(" } else {\n");
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText())\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=e ;\n");
grammarBuilder.append("e : e op='*' e\n");
@ -108,27 +124,36 @@ public class TestListeners extends BaseTest {
@Test
public void testLRWithLabels() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(597);
StringBuilder grammarBuilder = new StringBuilder(763);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitCall(TParser.CallContext ctx) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s\",ctx.e().start.GetText(),ctx.eList());\n");
grammarBuilder.append(" }\n");
grammarBuilder.append(" func ExitInt(TParser.IntContext ctx) {\n");
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText());\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l`\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitCall(ctx *parser.CallContext) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s\",ctx.e().GetStart().GetText(),ctx.eList());\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitInt(ctx *parser.IntContext) {\n");
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText());\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=e ;\n");
grammarBuilder.append("e : e '(' eList ')' # Call\n");
@ -158,28 +183,36 @@ public class TestListeners extends BaseTest {
@Test
public void testRuleGetters_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(624);
StringBuilder grammarBuilder = new StringBuilder(759);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitA(TParser.AContext ctx) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),\n");
grammarBuilder.append(" ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
grammarBuilder.append(" } else\n");
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitA(ctx parser.AContext) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
grammarBuilder.append(" } else\n");
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : b b // forces list\n");
@ -206,28 +239,36 @@ public class TestListeners extends BaseTest {
@Test
public void testRuleGetters_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(624);
StringBuilder grammarBuilder = new StringBuilder(759);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitA(TParser.AContext ctx) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),\n");
grammarBuilder.append(" ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
grammarBuilder.append(" } else\n");
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitA(ctx parser.AContext) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
grammarBuilder.append(" } else\n");
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : b b // forces list\n");
@ -254,28 +295,36 @@ public class TestListeners extends BaseTest {
@Test
public void testTokenGetters_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(568);
StringBuilder grammarBuilder = new StringBuilder(710);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitA(TParser.AContext ctx) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2)\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(),\n");
grammarBuilder.append(" ctx.INT(1).GetSymbol().GetText(),ctx.INT());\n");
grammarBuilder.append(" else\n");
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *parser.AContext) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());\n");
grammarBuilder.append(" } else {\n");
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : INT INT\n");
@ -301,28 +350,36 @@ public class TestListeners extends BaseTest {
@Test
public void testTokenGetters_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(568);
StringBuilder grammarBuilder = new StringBuilder(710);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@parser::header {\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("@parser::members {\n");
grammarBuilder.append("type LeafListener extends TBaseListener {\n");
grammarBuilder.append(" func ExitA(TParser.AContext ctx) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2)\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(),\n");
grammarBuilder.append(" ctx.INT(1).GetSymbol().GetText(),ctx.INT());\n");
grammarBuilder.append(" else\n");
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
grammarBuilder.append("func LeafListener struct {\n");
grammarBuilder.append(" *parser.BaseTListener\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
grammarBuilder.append(" l := new(LeafListener)\n");
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
grammarBuilder.append(" return l\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *parser.AContext) {\n");
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());\n");
grammarBuilder.append(" } else {\n");
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
grammarBuilder.append(" }\n");
grammarBuilder.append("}\n");
grammarBuilder.append("}\n");
grammarBuilder.append("\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this))\n");
grammarBuilder.append("ParseTreeWalker walker = NewParseTreeWalker();\n");
grammarBuilder.append("walker.walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("fmt.Println($ctx.r.ToStringTree(nil,p))\n");
grammarBuilder.append("walker := antlr4.NewParseTreeWalker();\n");
grammarBuilder.append("walker.Walk(NewLeafListener(), $ctx.r);\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : INT INT\n");

View File

@ -12,14 +12,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void test2AltLoop() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(135);
StringBuilder grammarBuilder = new StringBuilder(136);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : ('x' | 'y')* 'z'\n");
@ -37,14 +37,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void test2Alts() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(128);
StringBuilder grammarBuilder = new StringBuilder(129);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' | 'y'\n");
@ -62,14 +62,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void testExtraToken() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(141);
StringBuilder grammarBuilder = new StringBuilder(142);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' 'y'\n");
@ -91,14 +91,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void testNoViableAlt() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(143);
StringBuilder grammarBuilder = new StringBuilder(144);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' | 'y'\n");
@ -120,14 +120,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void testRuleRef() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(137);
StringBuilder grammarBuilder = new StringBuilder(138);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : b 'x'\n");
@ -147,14 +147,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void testSync() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(144);
StringBuilder grammarBuilder = new StringBuilder(145);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' 'y'* '!'\n");
@ -175,14 +175,14 @@ public class TestParseTrees extends BaseTest {
@Test
public void testToken2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(126);
StringBuilder grammarBuilder = new StringBuilder(127);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s\n");
grammarBuilder.append("@init {\n");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' 'y'\n");
@ -200,18 +200,18 @@ 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");
grammarBuilder.append("this.BuildParseTrees = true\n");
grammarBuilder.append("}\n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($r.ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : r=a ;\n");
grammarBuilder.append("a : 'x' { \n");
grammarBuilder.append("fmt.Println(GetRuleInvocationStack())\n");
grammarBuilder.append("fmt.Println(p.GetRuleInvocationStack())\n");
grammarBuilder.append("} ;");
String grammar = grammarBuilder.toString();
String input ="x";

View File

@ -184,7 +184,7 @@ public class TestParserErrors extends BaseTest {
@Test
public void testLL1ErrorInfo() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(298);
StringBuilder grammarBuilder = new StringBuilder(314);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("start : animal (AND acClass)? service EOF;\n");
grammarBuilder.append("animal : (DOG | CAT );\n");
@ -197,7 +197,7 @@ public class TestParserErrors extends BaseTest {
grammarBuilder.append("WS : ' ' -> skip ;\n");
grammarBuilder.append("acClass\n");
grammarBuilder.append("@init\n");
grammarBuilder.append("{fmt.Println(this.GetExpectedTokens().toString(this.tokenNames))}\n");
grammarBuilder.append("{fmt.Println(p.GetExpectedTokens().StringVerbose(p.GetTokenNames(), nil, false))}\n");
grammarBuilder.append(" : ;");
String grammar = grammarBuilder.toString();
String input ="dog and software";

View File

@ -608,11 +608,11 @@ public class TestParserExec extends BaseTest {
@Test
public void testPredicatedIfIfElse() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(175);
StringBuilder grammarBuilder = new StringBuilder(182);
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 | { this._input.LA(1)!=TParser.ELSE }?);\n");
grammarBuilder.append("ifStmt : 'if' ID stmt ('else' stmt | { p.GetTokenStream().LA(1)!=TParser.ELSE }?);\n");
grammarBuilder.append("ELSE : 'else';\n");
grammarBuilder.append("ID : [a-zA-Z]+;\n");
grammarBuilder.append("WS : [ \\n\\t]+ -> skip;");
@ -632,10 +632,10 @@ public class TestParserExec extends BaseTest {
StringBuilder grammarBuilder = new StringBuilder(246);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("file_ @init{\n");
grammarBuilder.append("SetErrorHandler(NewBailErrorStrategy());\n");
grammarBuilder.append("SetErrorHandler(NewBailErrorStrategy())\n");
grammarBuilder.append("} \n");
grammarBuilder.append("@after {\n");
grammarBuilder.append("fmt.Println($ctx.toStringTree(this))\n");
grammarBuilder.append("fmt.Println($ctx.ToStringTree(nil,p))\n");
grammarBuilder.append("}\n");
grammarBuilder.append(" : item (SEMICOLON item)* SEMICOLON? EOF ;\n");
grammarBuilder.append("item : A B?;\n");

View File

@ -41,9 +41,9 @@ public class TestSemPredEvalLexer extends BaseTest {
public void testEnumNotID() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(108);
StringBuilder grammarBuilder = new StringBuilder(100);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("ENUM : [a-z]+ { this.GetText().equals(\"enum\") }? ;\n");
grammarBuilder.append("ENUM : [a-z]+ { l.GetText() == \"enum\" }? ;\n");
grammarBuilder.append("ID : [a-z]+ ;\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
String grammar = grammarBuilder.toString();
@ -150,12 +150,12 @@ public class TestSemPredEvalLexer extends BaseTest {
public void testLexerInputPositionSensitivePredicates() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(262);
StringBuilder grammarBuilder = new StringBuilder(250);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("WORD1 : ID1+ { fmt.Println(this.GetText()) } ;\n");
grammarBuilder.append("WORD2 : ID2+ { fmt.Println(this.GetText()) } ;\n");
grammarBuilder.append("fragment ID1 : { this.GetCharPositionInLine() < 2 }? [a-zA-Z];\n");
grammarBuilder.append("fragment ID2 : { this.GetCharPositionInLine() >= 2 }? [a-zA-Z];\n");
grammarBuilder.append("WORD1 : ID1+ { fmt.Println(l.GetText()) } ;\n");
grammarBuilder.append("WORD2 : ID2+ { fmt.Println(l.GetText()) } ;\n");
grammarBuilder.append("fragment ID1 : { l.GetCharPositionInLine() < 2 }? [a-zA-Z];\n");
grammarBuilder.append("fragment ID2 : { l.GetCharPositionInLine() >= 2 }? [a-zA-Z];\n");
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
String grammar = grammarBuilder.toString();
String input =
@ -180,10 +180,10 @@ public class TestSemPredEvalLexer extends BaseTest {
public void testPredicatedKeywords() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(171);
StringBuilder grammarBuilder = new StringBuilder(160);
grammarBuilder.append("lexer grammar L;\n");
grammarBuilder.append("ENUM : [a-z]+ { this.GetText().equals(\"enum\") }? { fmt.Println(\"enum!\") } ;\n");
grammarBuilder.append("ID : [a-z]+ { fmt.Println(\"ID \" + this.GetText()) } ;\n");
grammarBuilder.append("ENUM : [a-z]+ { l.GetText() == \"enum\" }? { fmt.Println(\"enum!\") } ;\n");
grammarBuilder.append("ID : [a-z]+ { fmt.Println(\"ID \" + l.GetText()) } ;\n");
grammarBuilder.append("WS : [ \\n] -> skip ;");
String grammar = grammarBuilder.toString();
String input ="enum enu a";

View File

@ -12,9 +12,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void test2UnpredicatedAlts() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(290);
StringBuilder grammarBuilder = new StringBuilder(300);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);} a ';' a; // do 2x: once in ATN, next in DFA\n");
grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr4.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");
@ -42,9 +42,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(341);
StringBuilder grammarBuilder = new StringBuilder(351);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);} a ';' a ';' a;\n");
grammarBuilder.append("s : {p.Interpreter.SetPredictionMode(antlr4.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");
@ -74,9 +74,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testActionHidesPreds() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(223);
StringBuilder grammarBuilder = new StringBuilder(227);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("@members {var i int = 0;}\n");
grammarBuilder.append("s : a+ ;\n");
grammarBuilder.append("a : {this.i = 1;} ID {this.i == 1}? {fmt.Println(\"alt 1\")}\n");
grammarBuilder.append(" | {this.i = 2;} ID {this.i == 2}? {fmt.Println(\"alt 2\")}\n");
@ -294,13 +294,13 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredFromAltTestedInLoopBack_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(203);
StringBuilder grammarBuilder = new StringBuilder(211);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("file_\n");
grammarBuilder.append("@after {fmt.Println($ctx.toStringTree(this))}\n");
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'|{this._input.LA(2)!=TParser.NL}? NL)+ ;\n");
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParser.NL}? NL)+ ;\n");
grammarBuilder.append("NL : '\\n' ;\n");
grammarBuilder.append("s : 's' ;\n");
grammarBuilder.append("X : 'x' ;");
@ -324,13 +324,13 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredFromAltTestedInLoopBack_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(203);
StringBuilder grammarBuilder = new StringBuilder(211);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("file_\n");
grammarBuilder.append("@after {fmt.Println($ctx.toStringTree(this))}\n");
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'|{this._input.LA(2)!=TParser.NL}? NL)+ ;\n");
grammarBuilder.append("paraContent : ('s'|'x'|{p.GetTokenStream().LA(2)!=TParser.NL}? NL)+ ;\n");
grammarBuilder.append("NL : '\\n' ;\n");
grammarBuilder.append("s : 's' ;\n");
grammarBuilder.append("X : 'x' ;");
@ -352,9 +352,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredTestedEvenWhenUnAmbig_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(199);
StringBuilder grammarBuilder = new StringBuilder(202);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {bool enumKeyword = true;}\n");
grammarBuilder.append("@members {var enumKeyword bool= true;}\n");
grammarBuilder.append("primary\n");
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
@ -374,9 +374,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredTestedEvenWhenUnAmbig_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(199);
StringBuilder grammarBuilder = new StringBuilder(202);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {bool enumKeyword = true;}\n");
grammarBuilder.append("@members {var enumKeyword bool= true;}\n");
grammarBuilder.append("primary\n");
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
@ -397,9 +397,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredicateDependentOnArg() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(198);
StringBuilder grammarBuilder = new StringBuilder(202);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("@members {var i int = 0;}\n");
grammarBuilder.append("s : a[2] a[1];\n");
grammarBuilder.append("a[int i]\n");
grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\")}\n");
@ -423,9 +423,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testPredicateDependentOnArg2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(154);
StringBuilder grammarBuilder = new StringBuilder(158);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("@members {var i int = 0;}\n");
grammarBuilder.append("s : a[2] a[1];\n");
grammarBuilder.append("a[int i]\n");
grammarBuilder.append(" : {$i==1}? ID \n");
@ -476,11 +476,11 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testRewindBeforePredEval() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(237);
StringBuilder grammarBuilder = new StringBuilder(241);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("s : a a;\n");
grammarBuilder.append("a : {this._input.LT(1).GetText().equals(\"x\")}? ID INT {fmt.Println(\"alt 1\")}\n");
grammarBuilder.append(" | {this._input.LT(1).GetText().equals(\"y\")}? ID INT {fmt.Println(\"alt 2\")}\n");
grammarBuilder.append("a : {p.GetTokenStream().LT(1).GetText() == \"x\"}? ID INT {fmt.Println(\"alt 1\")}\n");
grammarBuilder.append(" | {p.GetTokenStream().LT(1).GetText() == \"y\"}? ID INT {fmt.Println(\"alt 2\")}\n");
grammarBuilder.append(" ;\n");
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
grammarBuilder.append("INT : '0'..'9'+;\n");
@ -599,9 +599,9 @@ public class TestSemPredEvalParser extends BaseTest {
@Test
public void testToLeftWithVaryingPredicate() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(247);
StringBuilder grammarBuilder = new StringBuilder(251);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("@members {int i = 0;}\n");
grammarBuilder.append("@members {var i int = 0;}\n");
grammarBuilder.append("s : ({this.i += 1;\n");
grammarBuilder.append("fmt.Println(\"i=\" + this.i)} a)+ ;\n");
grammarBuilder.append("a : {this.i % 2 == 0}? ID {fmt.Println(\"alt 1\")}\n");

View File

@ -54,9 +54,9 @@ public class TestSets extends BaseTest {
@Test
public void testLexerOptionalSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(76);
StringBuilder grammarBuilder = new StringBuilder(77);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : ('a'|'b')? 'c' ;");
String grammar = grammarBuilder.toString();
String input ="ac";
@ -71,9 +71,9 @@ public class TestSets extends BaseTest {
@Test
public void testLexerPlusSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(76);
StringBuilder grammarBuilder = new StringBuilder(77);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : ('a'|'b')+ 'c' ;");
String grammar = grammarBuilder.toString();
String input ="abaac";
@ -88,9 +88,9 @@ public class TestSets extends BaseTest {
@Test
public void testLexerStarSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(76);
StringBuilder grammarBuilder = new StringBuilder(77);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : ('a'|'b')* 'c' ;");
String grammar = grammarBuilder.toString();
String input ="abaac";
@ -175,9 +175,9 @@ public class TestSets extends BaseTest {
@Test
public void testOptionalLexerSingleElement() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(70);
StringBuilder grammarBuilder = new StringBuilder(71);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : 'b'? 'c' ;");
String grammar = grammarBuilder.toString();
String input ="bc";
@ -192,9 +192,9 @@ public class TestSets extends BaseTest {
@Test
public void testOptionalSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(68);
StringBuilder grammarBuilder = new StringBuilder(69);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('a'|'b')? 'c' {fmt.Println(this._input.GetText())} ;");
grammarBuilder.append("a : ('a'|'b')? 'c' {fmt.Println(p.GetInput().GetText())} ;");
String grammar = grammarBuilder.toString();
String input ="ac";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
@ -208,9 +208,9 @@ public class TestSets extends BaseTest {
@Test
public void testOptionalSingleElement() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(70);
StringBuilder grammarBuilder = new StringBuilder(71);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A? 'c' {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A? 'c' {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : 'b' ;");
String grammar = grammarBuilder.toString();
String input ="bc";
@ -241,9 +241,9 @@ public class TestSets extends BaseTest {
@Test
public void testParserNotToken() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(62);
StringBuilder grammarBuilder = new StringBuilder(63);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ~'x' 'z' {fmt.Println(this._input.GetText())} ;");
grammarBuilder.append("a : ~'x' 'z' {fmt.Println(p.GetInput().GetText())} ;");
String grammar = grammarBuilder.toString();
String input ="zz";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
@ -289,9 +289,9 @@ public class TestSets extends BaseTest {
@Test
public void testPlusLexerSingleElement() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(70);
StringBuilder grammarBuilder = new StringBuilder(71);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : 'b'+ 'c' ;");
String grammar = grammarBuilder.toString();
String input ="bbbbc";
@ -306,9 +306,9 @@ public class TestSets extends BaseTest {
@Test
public void testPlusSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(68);
StringBuilder grammarBuilder = new StringBuilder(69);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('a'|'b')+ 'c' {fmt.Println(this._input.GetText())} ;");
grammarBuilder.append("a : ('a'|'b')+ 'c' {fmt.Println(p.GetInput().GetText())} ;");
String grammar = grammarBuilder.toString();
String input ="abaac";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
@ -322,9 +322,9 @@ public class TestSets extends BaseTest {
@Test
public void testRuleAsSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(75);
StringBuilder grammarBuilder = new StringBuilder(76);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a @after {fmt.Println(this._input.GetText())} : 'a' | 'b' |'c' ;");
grammarBuilder.append("a @after {fmt.Println(p.GetInput().GetText())} : 'a' | 'b' |'c' ;");
String grammar = grammarBuilder.toString();
String input ="b";
String found = execParser("T.g4", grammar, "TParser", "TLexer",
@ -338,9 +338,9 @@ public class TestSets extends BaseTest {
@Test
public void testSeqDoesNotBecomeSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(112);
StringBuilder grammarBuilder = new StringBuilder(113);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : C {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : C {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("fragment A : '1' | '2';\n");
grammarBuilder.append("fragment B : '3' '4';\n");
grammarBuilder.append("C : A | B;");
@ -357,9 +357,9 @@ public class TestSets extends BaseTest {
@Test
public void testStarLexerSingleElement_1() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(70);
StringBuilder grammarBuilder = new StringBuilder(71);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : 'b'* 'c' ;");
String grammar = grammarBuilder.toString();
String input ="bbbbc";
@ -374,9 +374,9 @@ public class TestSets extends BaseTest {
@Test
public void testStarLexerSingleElement_2() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(70);
StringBuilder grammarBuilder = new StringBuilder(71);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
grammarBuilder.append("a : A {fmt.Println(p.GetInput().GetText())} ;\n");
grammarBuilder.append("A : 'b'* 'c' ;");
String grammar = grammarBuilder.toString();
String input ="c";
@ -391,9 +391,9 @@ public class TestSets extends BaseTest {
@Test
public void testStarSet() throws Exception {
mkdir(parserpkgdir);
StringBuilder grammarBuilder = new StringBuilder(68);
StringBuilder grammarBuilder = new StringBuilder(69);
grammarBuilder.append("grammar T;\n");
grammarBuilder.append("a : ('a'|'b')* 'c' {fmt.Println(this._input.GetText())} ;");
grammarBuilder.append("a : ('a'|'b')* 'c' {fmt.Println(p.GetInput().GetText())} ;");
String grammar = grammarBuilder.toString();
String input ="abaac";
String found = execParser("T.g4", grammar, "TParser", "TLexer",

View File

@ -60,7 +60,7 @@ func NewATN(grammarType int, maxTokenType int) *ATN {
// If {@code ctx} is nil, the set of tokens will not include what can follow
// the rule surrounding {@code s}. In other words, the set will be
// restricted to tokens reachable staying within {@code s}'s rule.
func (this *ATN) nextTokensInContext(s ATNState, ctx RuleContext) *IntervalSet {
func (this *ATN) NextTokensInContext(s ATNState, ctx RuleContext) *IntervalSet {
var anal = NewLL1Analyzer(this)
var res = anal.LOOK(s, nil, ctx)
return res
@ -69,7 +69,7 @@ func (this *ATN) nextTokensInContext(s ATNState, ctx RuleContext) *IntervalSet {
// Compute the set of valid tokens that can occur starting in {@code s} and
// staying in same rule. {@link Token//EPSILON} is in set if we reach end of
// rule.
func (this *ATN) nextTokensNoContext(s ATNState) *IntervalSet {
func (this *ATN) NextTokensNoContext(s ATNState) *IntervalSet {
if s.GetNextTokenWithinRule() != nil {
if PortDebug {
fmt.Println("DEBUG 1")
@ -78,18 +78,18 @@ func (this *ATN) nextTokensNoContext(s ATNState) *IntervalSet {
}
if PortDebug {
fmt.Println("DEBUG 2")
fmt.Println(this.nextTokensInContext(s, nil))
fmt.Println(this.NextTokensInContext(s, nil))
}
s.SetNextTokenWithinRule(this.nextTokensInContext(s, nil))
s.SetNextTokenWithinRule(this.NextTokensInContext(s, nil))
s.GetNextTokenWithinRule().readOnly = true
return s.GetNextTokenWithinRule()
}
func (this *ATN) nextTokens(s ATNState, ctx RuleContext) *IntervalSet {
func (this *ATN) NextTokens(s ATNState, ctx RuleContext) *IntervalSet {
if ctx == nil {
return this.nextTokensNoContext(s)
return this.NextTokensNoContext(s)
} else {
return this.nextTokensInContext(s, ctx)
return this.NextTokensInContext(s, ctx)
}
}
@ -142,7 +142,7 @@ func (this *ATN) getExpectedTokens(stateNumber int, ctx RuleContext) *IntervalSe
panic("Invalid state number.")
}
var s = this.states[stateNumber]
var following = this.nextTokens(s, nil)
var following = this.NextTokens(s, nil)
if !following.contains(TokenEpsilon) {
return following
}
@ -152,7 +152,7 @@ func (this *ATN) getExpectedTokens(stateNumber int, ctx RuleContext) *IntervalSe
for ctx != nil && ctx.GetInvokingState() >= 0 && following.contains(TokenEpsilon) {
var invokingState = this.states[ctx.GetInvokingState()]
var rt = invokingState.GetTransitions()[0]
following = this.nextTokens(rt.(*RuleTransition).followState, nil)
following = this.NextTokens(rt.(*RuleTransition).followState, nil)
expected.addSet(following)
expected.removeOne(TokenEpsilon)
ctx = ctx.GetParent().(RuleContext)

View File

@ -57,7 +57,7 @@ type BaseATNState struct {
// Track the transitions emanating from this ATN state.
transitions []Transition
// Used to cache lookahead during parsing, not used during construction
nextTokenWithinRule *IntervalSet
NextTokenWithinRule *IntervalSet
}
func NewBaseATNState() *BaseATNState {
@ -73,7 +73,7 @@ func NewBaseATNState() *BaseATNState {
// Track the transitions emanating from this ATN state.
as.transitions = make([]Transition, 0)
// Used to cache lookahead during parsing, not used during construction
as.nextTokenWithinRule = nil
as.NextTokenWithinRule = nil
return as
}
@ -118,11 +118,11 @@ func (as *BaseATNState) SetStateNumber(stateNumber int) {
}
func (as *BaseATNState) GetNextTokenWithinRule() *IntervalSet {
return as.nextTokenWithinRule
return as.NextTokenWithinRule
}
func (as *BaseATNState) SetNextTokenWithinRule(v *IntervalSet) {
as.nextTokenWithinRule = v
as.NextTokenWithinRule = v
}
func (this *BaseATNState) String() string {

View File

@ -97,25 +97,25 @@ func (bt *CommonTokenStream) Get(index int) Token {
}
func (bt *CommonTokenStream) Consume() {
var skipEofCheck = false
var SkipEofCheck = false
if bt.index >= 0 {
if bt.fetchedEOF {
// the last token in tokens is EOF. skip check if p indexes any
// the last token in tokens is EOF. Skip check if p indexes any
// fetched token except the last.
skipEofCheck = bt.index < len(bt.tokens)-1
SkipEofCheck = bt.index < len(bt.tokens)-1
} else {
// no EOF token in tokens. skip check if p indexes a fetched token.
skipEofCheck = bt.index < len(bt.tokens)
// no EOF token in tokens. Skip check if p indexes a fetched token.
SkipEofCheck = bt.index < len(bt.tokens)
}
} else {
// not yet initialized
skipEofCheck = false
SkipEofCheck = false
}
if PortDebug {
fmt.Println("Consume 1")
}
if !skipEofCheck && bt.LA(1) == TokenEOF {
if !SkipEofCheck && bt.LA(1) == TokenEOF {
panic("cannot consume EOF")
}
if bt.Sync(bt.index + 1) {
@ -154,7 +154,7 @@ func (bt *CommonTokenStream) fetch(n int) int {
}
for i := 0; i < n; i++ {
var t Token = bt.tokenSource.nextToken()
var t Token = bt.tokenSource.NextToken()
if PortDebug {
fmt.Println("fetch loop")
}
@ -225,7 +225,7 @@ func (bt *CommonTokenStream) SetTokenSource(tokenSource TokenSource) {
// Return i if tokens[i] is on channel. Return -1 if there are no tokens
// on channel between i and EOF.
// /
func (bt *CommonTokenStream) nextTokenOnChannel(i, channel int) int {
func (bt *CommonTokenStream) NextTokenOnChannel(i, channel int) int {
bt.Sync(i)
if i >= len(bt.tokens) {
return -1
@ -260,7 +260,7 @@ func (bt *CommonTokenStream) getHiddenTokensToRight(tokenIndex, channel int) []T
if tokenIndex < 0 || tokenIndex >= len(bt.tokens) {
panic(strconv.Itoa(tokenIndex) + " not in 0.." + strconv.Itoa(len(bt.tokens)-1))
}
var nextOnChannel = bt.nextTokenOnChannel(tokenIndex+1, LexerDefaultTokenChannel)
var nextOnChannel = bt.NextTokenOnChannel(tokenIndex+1, LexerDefaultTokenChannel)
var from_ = tokenIndex + 1
// if none onchannel to right, nextOnChannel=-1 so set to = last token
var to int
@ -370,7 +370,7 @@ func (bt *CommonTokenStream) Fill() {
}
func (ts *CommonTokenStream) adjustSeekIndex(i int) int {
return ts.nextTokenOnChannel(i, ts.channel)
return ts.NextTokenOnChannel(i, ts.channel)
}
func (ts *CommonTokenStream) LB(k int) Token {
@ -381,7 +381,7 @@ func (ts *CommonTokenStream) LB(k int) Token {
var n = 1
// find k good tokens looking backwards
for n <= k {
// skip off-channel tokens
// Skip off-channel tokens
i = ts.previousTokenOnChannel(i-1, ts.channel)
n += 1
}
@ -403,9 +403,9 @@ func (ts *CommonTokenStream) LT(k int) Token {
var n = 1 // we know tokens[pos] is a good one
// find k good tokens
for n < k {
// skip off-channel tokens, but make sure to not look past EOF
// Skip off-channel tokens, but make sure to not look past EOF
if ts.Sync(i + 1) {
i = ts.nextTokenOnChannel(i+1, ts.channel)
i = ts.NextTokenOnChannel(i+1, ts.channel)
}
n += 1
}

View File

@ -38,7 +38,7 @@ func NewDiagnosticErrorListener(exactOnly bool) *DiagnosticErrorListener {
return n
}
func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer *BaseParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs ATNConfigSet) {
func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer Parser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs ATNConfigSet) {
if this.exactOnly && !exact {
return
}
@ -51,7 +51,7 @@ func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer *BaseParser, dfa
recognizer.NotifyErrorListeners(msg, nil, nil)
}
func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *BaseParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs ATNConfigSet) {
func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs ATNConfigSet) {
var msg = "ReportAttemptingFullContext d=" +
this.getDecisionDescription(recognizer, dfa) +
@ -60,7 +60,7 @@ func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Bas
recognizer.NotifyErrorListeners(msg, nil, nil)
}
func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *BaseParser, dfa *DFA, startIndex, stopIndex, prediction int, configs ATNConfigSet) {
func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs ATNConfigSet) {
var msg = "ReportContextSensitivity d=" +
this.getDecisionDescription(recognizer, dfa) +
", input='" +
@ -68,7 +68,7 @@ func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *BasePa
recognizer.NotifyErrorListeners(msg, nil, nil)
}
func (this *DiagnosticErrorListener) getDecisionDescription(recognizer *BaseParser, dfa *DFA) string {
func (this *DiagnosticErrorListener) getDecisionDescription(recognizer Parser, dfa *DFA) string {
var decision = dfa.decision
var ruleIndex = dfa.atnStartState.GetRuleIndex()

View File

@ -219,14 +219,14 @@ func (this *DefaultErrorStrategy) Sync(recognizer Parser) {
}
// try cheaper subset first might get lucky. seems to shave a wee bit off
if la == TokenEOF || recognizer.GetATN().nextTokens(s, nil).contains(la) {
if la == TokenEOF || recognizer.GetATN().NextTokens(s, nil).contains(la) {
if PortDebug {
fmt.Println("OK1")
}
return
}
// Return but don't end recovery. only do that upon valid token Match
if recognizer.isExpectedToken(la) {
if recognizer.IsExpectedToken(la) {
if PortDebug {
fmt.Println("OK2")
}
@ -235,7 +235,7 @@ func (this *DefaultErrorStrategy) Sync(recognizer Parser) {
if PortDebug {
fmt.Println("LA" + strconv.Itoa(la))
fmt.Println(recognizer.GetATN().nextTokens(s, nil))
fmt.Println(recognizer.GetATN().NextTokens(s, nil))
}
switch s.GetStateType() {
@ -257,7 +257,7 @@ func (this *DefaultErrorStrategy) Sync(recognizer Parser) {
case ATNStateStarLoopBack:
this.ReportUnwantedToken(recognizer)
var expecting = NewIntervalSet()
expecting.addSet(recognizer.getExpectedTokens())
expecting.addSet(recognizer.GetExpectedTokens())
var whatFollowsLoopIterationOrRule = expecting.addSet(this.getErrorRecoverySet(recognizer))
this.consumeUntil(recognizer, whatFollowsLoopIterationOrRule)
default:
@ -342,7 +342,7 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer Parser) {
return
}
this.beginErrorCondition(recognizer)
var t = recognizer.getCurrentToken()
var t = recognizer.GetCurrentToken()
var tokenName = this.GetTokenErrorDisplay(t)
var expecting = this.getExpectedTokens(recognizer)
var msg = "extraneous input " + tokenName + " expecting " +
@ -371,7 +371,7 @@ func (this *DefaultErrorStrategy) ReportMissingToken(recognizer Parser) {
return
}
this.beginErrorCondition(recognizer)
var t = recognizer.getCurrentToken()
var t = recognizer.GetCurrentToken()
var expecting = this.getExpectedTokens(recognizer)
var msg = "missing " + expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false) +
" at " + this.GetTokenErrorDisplay(t)
@ -469,7 +469,7 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer Parser) bool {
var atn = recognizer.GetInterpreter().atn
var currentState = atn.states[recognizer.GetState()]
var next = currentState.GetTransitions()[0].getTarget()
var expectingAtLL2 = atn.nextTokens(next, recognizer.GetParserRuleContext())
var expectingAtLL2 = atn.NextTokens(next, recognizer.GetParserRuleContext())
if expectingAtLL2.contains(currentSymbolType) {
this.ReportMissingToken(recognizer)
return true
@ -497,9 +497,9 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer Parser) bool {
// {@code nil}
//
func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer Parser) Token {
var nextTokenType = recognizer.GetTokenStream().LA(2)
var NextTokenType = recognizer.GetTokenStream().LA(2)
var expecting = this.getExpectedTokens(recognizer)
if expecting.contains(nextTokenType) {
if expecting.contains(NextTokenType) {
this.ReportUnwantedToken(recognizer)
// print("recoverFromMisMatchedToken deleting " \
// + str(recognizer.GetTokenStream().LT(1)) \
@ -507,7 +507,7 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer Parser) Token {
// + " is what we want", file=sys.stderr)
recognizer.Consume() // simply delete extra token
// we want to return the token we're actually Matching
var MatchedSymbol = recognizer.getCurrentToken()
var MatchedSymbol = recognizer.GetCurrentToken()
this.ReportMatch(recognizer) // we know current token is correct
return MatchedSymbol
} else {
@ -535,7 +535,7 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer Parser) Token {
// override this method to create the appropriate tokens.
//
func (this *DefaultErrorStrategy) getMissingSymbol(recognizer Parser) Token {
var currentSymbol = recognizer.getCurrentToken()
var currentSymbol = recognizer.GetCurrentToken()
var expecting = this.getExpectedTokens(recognizer)
var expectedTokenType = expecting.first()
var tokenText string
@ -559,7 +559,7 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer Parser) Token {
}
func (this *DefaultErrorStrategy) getExpectedTokens(recognizer Parser) *IntervalSet {
return recognizer.getExpectedTokens()
return recognizer.GetExpectedTokens()
}
// How should a token be displayed in an error message? The default
@ -692,7 +692,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer Parser) *Interv
// compute what follows who invoked us
var invokingState = atn.states[ctx.GetInvokingState()]
var rt = invokingState.GetTransitions()[0]
var follow = atn.nextTokens(rt.(*RuleTransition).followState, nil)
var follow = atn.NextTokens(rt.(*RuleTransition).followState, nil)
recoverSet.addSet(follow)
ctx = ctx.GetParent().(ParserRuleContext)
}

View File

@ -142,11 +142,11 @@ func NewNoViableAltException(recognizer Parser, input TokenStream, startToken To
}
if offendingToken == nil {
offendingToken = recognizer.getCurrentToken()
offendingToken = recognizer.GetCurrentToken()
}
if startToken == nil {
startToken = recognizer.getCurrentToken()
startToken = recognizer.GetCurrentToken()
}
if input == nil {
@ -181,7 +181,7 @@ func NewInputMisMatchException(recognizer Parser) *InputMisMatchException {
this := new(InputMisMatchException)
this.BaseRecognitionException = NewBaseRecognitionException("", recognizer, recognizer.GetInputStream(), recognizer.GetParserRuleContext())
this.offendingToken = recognizer.getCurrentToken()
this.offendingToken = recognizer.GetCurrentToken()
return this
@ -200,13 +200,13 @@ type FailedPredicateException struct {
predicate string
}
func NewFailedPredicateException(recognizer *BaseParser, predicate string, message string) *FailedPredicateException {
func NewFailedPredicateException(recognizer Parser, predicate string, message string) *FailedPredicateException {
this := new(FailedPredicateException)
this.BaseRecognitionException = NewBaseRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.GetInputStream(), recognizer._ctx)
this.BaseRecognitionException = NewBaseRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.GetInputStream(), recognizer.GetParserRuleContext())
var s = recognizer.Interpreter.atn.states[recognizer.state]
var s = recognizer.GetInterpreter().atn.states[recognizer.GetState()]
var trans = s.GetTransitions()[0]
if trans2, ok := trans.(*PredicateTransition); ok {
this.ruleIndex = trans2.ruleIndex
@ -216,7 +216,7 @@ func NewFailedPredicateException(recognizer *BaseParser, predicate string, messa
this.predicateIndex = 0
}
this.predicate = predicate
this.offendingToken = recognizer.getCurrentToken()
this.offendingToken = recognizer.GetCurrentToken()
return this
}

View File

@ -26,21 +26,22 @@ type BaseLexer struct {
*BaseRecognizer
Interpreter *LexerATNSimulator
TokenStartCharIndex int
TokenStartLine int
TokenStartColumn int
ActionType int
_input CharStream
_factory TokenFactory
_tokenFactorySourcePair *TokenSourceCharStreamPair
_token Token
_tokenStartCharIndex int
_tokenStartLine int
_tokenStartColumn int
_hitEOF bool
_channel int
_type int
_modeStack IntStack
_mode int
_text string
actionType int
}
func NewBaseLexer(input CharStream) *BaseLexer {
@ -57,7 +58,7 @@ func NewBaseLexer(input CharStream) *BaseLexer {
// The goal of all lexer rules/methods is to create a token object.
// l is an instance variable as multiple rules may collaborate to
// create a single token. nextToken will return l object after
// create a single token. NextToken will return l object after
// Matching lexer rule(s). If you subclass to allow multiple token
// emissions, then set l to the last token to be Matched or
// something nonnil so that the auto token emit mechanism will not
@ -66,14 +67,14 @@ func NewBaseLexer(input CharStream) *BaseLexer {
// What character index in the stream did the current token start at?
// Needed, for example, to get the text for current token. Set at
// the start of nextToken.
lexer._tokenStartCharIndex = -1
// the start of NextToken.
lexer.TokenStartCharIndex = -1
// The line on which the first character of the token resides///
lexer._tokenStartLine = -1
lexer.TokenStartLine = -1
// The character position of first character within the line///
lexer._tokenStartColumn = -1
lexer.TokenStartColumn = -1
// Once we see EOF on char stream, next token will be EOF.
// If you have DONE : EOF then you see DONE EOF.
@ -117,9 +118,9 @@ func (l *BaseLexer) reset() {
l._token = nil
l._type = TokenInvalidType
l._channel = TokenDefaultChannel
l._tokenStartCharIndex = -1
l._tokenStartColumn = -1
l._tokenStartLine = -1
l.TokenStartCharIndex = -1
l.TokenStartColumn = -1
l.TokenStartLine = -1
l._text = ""
l._hitEOF = false
@ -166,9 +167,9 @@ func (l *BaseLexer) safeMatch() (ret int) {
}
// Return a token from l source i.e., Match a token on the char stream.
func (l *BaseLexer) nextToken() Token {
func (l *BaseLexer) NextToken() Token {
if l._input == nil {
panic("nextToken requires a non-nil input stream.")
panic("NextToken requires a non-nil input stream.")
}
var tokenStartMarker = l._input.Mark()
@ -187,9 +188,9 @@ func (l *BaseLexer) nextToken() Token {
}
l._token = nil
l._channel = TokenDefaultChannel
l._tokenStartCharIndex = l._input.Index()
l._tokenStartColumn = l.Interpreter.column
l._tokenStartLine = l.Interpreter.line
l.TokenStartCharIndex = l._input.Index()
l.TokenStartColumn = l.Interpreter.column
l.TokenStartLine = l.Interpreter.line
l._text = ""
var continueOuter = false
for true {
@ -231,17 +232,17 @@ func (l *BaseLexer) nextToken() Token {
return nil
}
// Instruct the lexer to skip creating a token for current lexer rule
// and look for another token. nextToken() knows to keep looking when
// Instruct the lexer to Skip creating a token for current lexer rule
// and look for another token. NextToken() knows to keep looking when
// a lexer rule finishes with token set to SKIP_TOKEN. Recall that
// if token==nil at end of any token rule, it creates one for you
// and emits it.
// /
func (l *BaseLexer) skip() {
func (l *BaseLexer) Skip() {
l._type = LexerSkip
}
func (l *BaseLexer) more() {
func (l *BaseLexer) More() {
l._type = LexerMore
}
@ -281,8 +282,8 @@ func (l *BaseLexer) setInputStream(input CharStream) {
l._tokenFactorySourcePair = &TokenSourceCharStreamPair{l, l._input}
}
// By default does not support multiple emits per nextToken invocation
// for efficiency reasons. Subclass and override l method, nextToken,
// By default does not support multiple emits per NextToken invocation
// for efficiency reasons. Subclass and override l method, NextToken,
// and GetToken (to push tokens into a list and pull from that list
// rather than a single variable as l implementation does).
// /
@ -300,14 +301,14 @@ func (l *BaseLexer) emit() Token {
if PortDebug {
fmt.Println("emit")
}
var t = l._factory.Create(l._tokenFactorySourcePair, l._type, l._text, l._channel, l._tokenStartCharIndex, l.getCharIndex()-1, l._tokenStartLine, l._tokenStartColumn)
var t = l._factory.Create(l._tokenFactorySourcePair, l._type, l._text, l._channel, l.TokenStartCharIndex, l.getCharIndex()-1, l.TokenStartLine, l.TokenStartColumn)
l.emitToken(t)
return t
}
func (l *BaseLexer) emitEOF() Token {
cpos := l.getCharPositionInLine()
lpos := l.getLine()
cpos := l.GetCharPositionInLine()
lpos := l.GetLine()
if PortDebug {
fmt.Println("emitEOF")
}
@ -316,11 +317,11 @@ func (l *BaseLexer) emitEOF() Token {
return eof
}
func (l *BaseLexer) getCharPositionInLine() int {
func (l *BaseLexer) GetCharPositionInLine() int {
return l.Interpreter.column
}
func (l *BaseLexer) getLine() int {
func (l *BaseLexer) GetLine() int {
return l.Interpreter.line
}
@ -363,24 +364,24 @@ func (l *BaseLexer) getAllTokens() []Token {
fmt.Println("getAllTokens")
}
var tokens = make([]Token, 0)
var t = l.nextToken()
var t = l.NextToken()
for t.GetTokenType() != TokenEOF {
tokens = append(tokens, t)
if PortDebug {
fmt.Println("getAllTokens")
}
t = l.nextToken()
t = l.NextToken()
}
return tokens
}
func (l *BaseLexer) notifyListeners(e RecognitionException) {
var start = l._tokenStartCharIndex
var start = l.TokenStartCharIndex
var stop = l._input.Index()
var text = l._input.GetTextFromInterval(NewInterval(start, stop))
var msg = "token recognition error at: '" + text + "'"
var listener = l.getErrorListenerDispatch()
listener.SyntaxError(l, nil, l._tokenStartLine, l._tokenStartColumn, msg, e)
var listener = l.GetErrorListenerDispatch()
listener.SyntaxError(l, nil, l.TokenStartLine, l.TokenStartColumn, msg, e)
}
func (l *BaseLexer) getErrorDisplayForChar(c rune) string {
@ -409,7 +410,7 @@ func (l *BaseLexer) getCharErrorDisplay(c rune) string {
func (l *BaseLexer) Recover(re RecognitionException) {
if l._input.LA(1) != TokenEOF {
if _, ok := re.(*LexerNoViableAltException); ok {
// skip a char and try again
// Skip a char and try again
l.Interpreter.consume(l._input)
} else {
// TODO: Do we lose character or line position information?

View File

@ -313,11 +313,11 @@ func (this *LexerATNSimulator) failOrAccept(prevAccept *SimState, input CharStre
// we can reach upon input {@code t}. Parameter {@code reach} is a return
// parameter.
func (this *LexerATNSimulator) getReachableConfigSet(input CharStream, closure ATNConfigSet, reach ATNConfigSet, t int) {
// this is used to skip processing for configs which have a lower priority
// this is used to Skip processing for configs which have a lower priority
// than a config that already reached an accept state for the same rule
var skipAlt = ATNInvalidAltNumber
var SkipAlt = ATNInvalidAltNumber
for _, cfg := range closure.GetItems() {
var currentAltReachedAcceptState = (cfg.GetAlt() == skipAlt)
var currentAltReachedAcceptState = (cfg.GetAlt() == SkipAlt)
if currentAltReachedAcceptState && cfg.(*LexerATNConfig).passedThroughNonGreedyDecision {
continue
}
@ -337,7 +337,7 @@ func (this *LexerATNSimulator) getReachableConfigSet(input CharStream, closure A
currentAltReachedAcceptState, true, treatEofAsEpsilon) {
// any remaining configs for this alt have a lower priority
// than the one that just reached an accept state.
skipAlt = cfg.GetAlt()
SkipAlt = cfg.GetAlt()
}
}
}
@ -530,7 +530,7 @@ func (this *LexerATNSimulator) getEpsilonTarget(input CharStream, config *LexerA
// <p>If {@code speculative} is {@code true}, this method was called before
// {@link //consume} for the Matched character. This method should call
// {@link //consume} before evaluating the predicate to ensure position
// sensitive values, including {@link Lexer//GetText}, {@link Lexer//getLine},
// sensitive values, including {@link Lexer//GetText}, {@link Lexer//GetLine},
// and {@link Lexer//getcolumn}, properly reflect the current
// lexer state. This method should restore {@code input} and the simulator
// to the original state before returning (i.e. undo the actions made by the

View File

@ -56,9 +56,9 @@ func (this *BaseLexerAction) equals(other LexerAction) bool {
}
//
// Implements the {@code skip} lexer action by calling {@link Lexer//skip}.
// Implements the {@code Skip} lexer action by calling {@link Lexer//Skip}.
//
// <p>The {@code skip} command does not have any parameters, so this action is
// <p>The {@code Skip} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerSkipAction struct {
*BaseLexerAction
@ -74,7 +74,7 @@ func NewLexerSkipAction() *LexerSkipAction {
var LexerSkipActionINSTANCE = NewLexerSkipAction()
func (this *LexerSkipAction) execute(lexer Lexer) {
lexer.skip()
lexer.Skip()
}
func (this *LexerSkipAction) String() string {
@ -207,7 +207,7 @@ var LexerMoreActionINSTANCE = NewLexerMoreAction()
// <p>This action is implemented by calling {@link Lexer//popMode}.</p>
func (this *LexerMoreAction) execute(lexer Lexer) {
lexer.more()
lexer.More()
}
func (this *LexerMoreAction) String() string {

View File

@ -17,12 +17,12 @@ type Parser interface {
GetParseListeners() []ParseTreeListener
GetInputStream() IntStream
getCurrentToken() Token
getExpectedTokens() *IntervalSet
GetCurrentToken() Token
GetExpectedTokens() *IntervalSet
NotifyErrorListeners(string, Token, RecognitionException)
isExpectedToken(int) bool
getPrecedence() int
getRuleInvocationStack(ParserRuleContext) []string
IsExpectedToken(int) bool
GetPrecedence() int
GetRuleInvocationStack(ParserRuleContext) []string
}
type BaseParser struct {
@ -74,7 +74,7 @@ func NewBaseParser(input TokenStream) *BaseParser {
// The number of syntax errors Reported during parsing. p.value is
// incremented each time {@link //NotifyErrorListeners} is called.
p._SyntaxErrors = 0
p.setInputStream(input)
p.SetInputStream(input)
return p
}
@ -95,7 +95,7 @@ func (p *BaseParser) reset() {
p._errHandler.reset(p)
p._ctx = nil
p._SyntaxErrors = 0
p.setTrace(nil)
p.SetTrace(nil)
p._precedenceStack = make([]int, 0)
p._precedenceStack.Push(0)
if p.Interpreter != nil {
@ -107,10 +107,6 @@ func (p *BaseParser) GetErrorHandler() ErrorStrategy {
return p._errHandler
}
func (p *BaseParser) GetParseListeners() []ParseTreeListener {
return p._parseListeners
}
// 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.
@ -133,7 +129,7 @@ func (p *BaseParser) Match(ttype int) Token {
if PortDebug {
fmt.Println("get current token")
}
var t = p.getCurrentToken()
var t = p.GetCurrentToken()
if PortDebug {
fmt.Println("TOKEN IS " + t.GetText())
@ -176,7 +172,7 @@ func (p *BaseParser) Match(ttype int) Token {
// symbol
func (p *BaseParser) MatchWildcard() Token {
var t = p.getCurrentToken()
var t = p.GetCurrentToken()
if t.GetTokenType() > 0 {
p._errHandler.ReportMatch(p)
p.Consume()
@ -196,7 +192,7 @@ func (p *BaseParser) GetParserRuleContext() ParserRuleContext {
return p._ctx
}
func (p *BaseParser) getParseListeners() []ParseTreeListener {
func (p *BaseParser) GetParseListeners() []ParseTreeListener {
if p._parseListeners == nil {
return make([]ParseTreeListener, 0)
}
@ -231,7 +227,7 @@ func (p *BaseParser) getParseListeners() []ParseTreeListener {
//
// @panics nilPointerException if {@code} listener is {@code nil}
//
func (p *BaseParser) addParseListener(listener ParseTreeListener) {
func (p *BaseParser) AddParseListener(listener ParseTreeListener) {
if listener == nil {
panic("listener")
}
@ -248,7 +244,7 @@ func (p *BaseParser) addParseListener(listener ParseTreeListener) {
// listener, p.method does nothing.</p>
// @param listener the listener to remove
//
func (p *BaseParser) removeParseListener(listener ParseTreeListener) {
func (p *BaseParser) RemoveParseListener(listener ParseTreeListener) {
if p._parseListeners != nil {
@ -385,8 +381,8 @@ func (p *BaseParser) GetInputStream() IntStream {
return p.GetTokenStream()
}
func (p *BaseParser) setInputStream(input TokenStream) {
p.setTokenStream(input)
func (p *BaseParser) SetInputStream(input TokenStream) {
p.SetTokenStream(input)
}
func (p *BaseParser) GetTokenStream() TokenStream {
@ -394,7 +390,7 @@ func (p *BaseParser) GetTokenStream() TokenStream {
}
// Set the token stream and reset the parser.//
func (p *BaseParser) setTokenStream(input TokenStream) {
func (p *BaseParser) SetTokenStream(input TokenStream) {
p._input = nil
p.reset()
p._input = input
@ -403,23 +399,23 @@ func (p *BaseParser) setTokenStream(input TokenStream) {
// Match needs to return the current input symbol, which gets put
// into the label for the associated token ref e.g., x=ID.
//
func (p *BaseParser) getCurrentToken() Token {
func (p *BaseParser) GetCurrentToken() Token {
return p._input.LT(1)
}
func (p *BaseParser) NotifyErrorListeners(msg string, offendingToken Token, err RecognitionException) {
if offendingToken == nil {
offendingToken = p.getCurrentToken()
offendingToken = p.GetCurrentToken()
}
p._SyntaxErrors += 1
var line = offendingToken.GetLine()
var column = offendingToken.GetColumn()
listener := p.getErrorListenerDispatch()
listener := p.GetErrorListenerDispatch()
listener.SyntaxError(p, offendingToken, line, column, msg, err)
}
func (p *BaseParser) Consume() Token {
var o = p.getCurrentToken()
var o = p.GetCurrentToken()
if o.GetTokenType() != TokenEOF {
if PortDebug {
fmt.Println("Consuming")
@ -503,7 +499,7 @@ func (p *BaseParser) EnterOuterAlt(localctx ParserRuleContext, altNum int) {
// @return The precedence level for the top-most precedence rule, or -1 if
// the parser context is not nested within a precedence rule.
func (p *BaseParser) getPrecedence() int {
func (p *BaseParser) GetPrecedence() int {
if len(p._precedenceStack) == 0 {
return -1
} else {
@ -563,7 +559,7 @@ func (p *BaseParser) UnrollRecursionContexts(parentCtx ParserRuleContext) {
}
}
func (p *BaseParser) getInvokingContext(ruleIndex int) ParserRuleContext {
func (p *BaseParser) GetInvokingContext(ruleIndex int) ParserRuleContext {
var ctx = p._ctx
for ctx != nil {
if ctx.GetRuleIndex() == ruleIndex {
@ -597,11 +593,11 @@ func (p *BaseParser) inContext(context ParserRuleContext) bool {
// @return {@code true} if {@code symbol} can follow the current state in
// the ATN, otherwise {@code false}.
func (p *BaseParser) isExpectedToken(symbol int) bool {
func (p *BaseParser) IsExpectedToken(symbol int) bool {
var atn *ATN = p.Interpreter.atn
var ctx = p._ctx
var s = atn.states[p.state]
var following = atn.nextTokens(s, nil)
var following = atn.NextTokens(s, nil)
if following.contains(symbol) {
return true
}
@ -611,7 +607,7 @@ func (p *BaseParser) isExpectedToken(symbol int) bool {
for ctx != nil && ctx.GetInvokingState() >= 0 && following.contains(TokenEpsilon) {
var invokingState = atn.states[ctx.GetInvokingState()]
var rt = invokingState.GetTransitions()[0]
following = atn.nextTokens(rt.(*RuleTransition).followState, nil)
following = atn.NextTokens(rt.(*RuleTransition).followState, nil)
if following.contains(symbol) {
return true
}
@ -630,14 +626,14 @@ func (p *BaseParser) isExpectedToken(symbol int) bool {
//
// @see ATN//getExpectedTokens(int, RuleContext)
//
func (p *BaseParser) getExpectedTokens() *IntervalSet {
func (p *BaseParser) GetExpectedTokens() *IntervalSet {
return p.Interpreter.atn.getExpectedTokens(p.state, p._ctx)
}
func (p *BaseParser) getExpectedTokensWithinCurrentRule() *IntervalSet {
func (p *BaseParser) GetExpectedTokensWithinCurrentRule() *IntervalSet {
var atn = p.Interpreter.atn
var s = atn.states[p.state]
return atn.nextTokens(s, nil)
return atn.NextTokens(s, nil)
}
// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.//
@ -657,7 +653,7 @@ func (p *BaseParser) GetRuleIndex(ruleName string) int {
//
// this very useful for error messages.
func (this *BaseParser) getRuleInvocationStack(p ParserRuleContext) []string {
func (this *BaseParser) GetRuleInvocationStack(p ParserRuleContext) []string {
if p == nil {
p = this._ctx
}
@ -702,15 +698,15 @@ func (p *BaseParser) GetSourceName() string {
// During a parse is sometimes useful to listen in on the rule entry and exit
// events as well as token Matches. p.is for quick and dirty debugging.
//
func (p *BaseParser) setTrace(trace *TraceListener) {
func (p *BaseParser) SetTrace(trace *TraceListener) {
if trace == nil {
p.removeParseListener(p._tracer)
p.RemoveParseListener(p._tracer)
p._tracer = nil
} else {
if p._tracer != nil {
p.removeParseListener(p._tracer)
p.RemoveParseListener(p._tracer)
}
p._tracer = NewTraceListener(p)
p.addParseListener(p._tracer)
p.AddParseListener(p._tracer)
}
}

View File

@ -52,6 +52,14 @@ var ParserATNSimulatorListATNDecisions = false
var ParserATNSimulatorDFADebug = false
var ParserATNSimulatorRetryDebug = false
func (this *ParserATNSimulator) GetPredictionMode() int {
return this.predictionMode
}
func (this *ParserATNSimulator) SetPredictionMode(v int) {
this.predictionMode = v
}
func (this *ParserATNSimulator) reset() {
}
@ -91,7 +99,7 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
if dfa.precedenceDfa {
// the start state for a precedence DFA depends on the current
// parser precedence, and is provided by a DFA method.
s0 = dfa.getPrecedenceStartState(this.parser.getPrecedence())
s0 = dfa.getPrecedenceStartState(this.parser.GetPrecedence())
} else {
// the start state for a "regular" DFA is just s0
s0 = dfa.s0
@ -130,7 +138,7 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
//
s0_closure = this.applyPrecedenceFilter(s0_closure)
s0 = this.addDFAState(dfa, NewDFAState(-1, s0_closure))
dfa.setPrecedenceStartState(this.parser.getPrecedence(), s0)
dfa.setPrecedenceStartState(this.parser.GetPrecedence(), s0)
} else {
s0 = this.addDFAState(dfa, NewDFAState(-1, s0_closure))
dfa.s0 = s0
@ -415,7 +423,7 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
if reach.GetUniqueAlt() != ATNInvalidAltNumber {
predictedAlt = reach.GetUniqueAlt()
break
} else if this.predictionMode != PredictionModeLL_EXACT_AMBIG_DETECTION {
} else if this.predictionMode != PredictionModeLLExactAmbigDetection {
predictedAlt = PredictionModeresolvesToJustOneViableAlt(altSubSets)
if predictedAlt != ATNInvalidAltNumber {
break
@ -496,7 +504,7 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// ensure that the alternative Matching the longest overall sequence is
// chosen when multiple such configurations can Match the input.
var skippedStopStates []*BaseATNConfig = nil
var SkippedStopStates []*BaseATNConfig = nil
// First figure out where we can reach on input t
for _, c := range closure.GetItems() {
@ -508,12 +516,12 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
if ok {
if fullCtx || t == TokenEOF {
if skippedStopStates == nil {
skippedStopStates = make([]*BaseATNConfig, 0)
if SkippedStopStates == nil {
SkippedStopStates = make([]*BaseATNConfig, 0)
}
skippedStopStates = append(skippedStopStates, c.(*BaseATNConfig))
SkippedStopStates = append(SkippedStopStates, c.(*BaseATNConfig))
if ParserATNSimulatorDebug {
fmt.Println("added " + c.String() + " to skippedStopStates")
fmt.Println("added " + c.String() + " to SkippedStopStates")
}
}
continue
@ -541,9 +549,9 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// The conditions assume that intermediate
// contains all configurations relevant to the reach set, but this
// condition is not true when one or more configurations have been
// withheld in skippedStopStates, or when the current symbol is EOF.
// withheld in SkippedStopStates, or when the current symbol is EOF.
//
if skippedStopStates == nil && t != TokenEOF {
if SkippedStopStates == nil && t != TokenEOF {
if len(intermediate.configs) == 1 {
// Don't pursue the closure if there is just one state.
// It can only have one alternative just add to result
@ -580,14 +588,14 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// reachable rule stop states as well as configurations already in
// a rule stop state.
//
// This is handled before the configurations in skippedStopStates,
// This is handled before the configurations in SkippedStopStates,
// because any configurations potentially added from that list are
// already guaranteed to meet this condition whether or not it's
// required.
//
reach = this.removeAllConfigsNotInRuleStopState(reach, reach == intermediate)
}
// If skippedStopStates!=nil, then it contains at least one
// If SkippedStopStates!=nil, then it contains at least one
// configuration. For full-context reach operations, these
// configurations reached the end of the start rule, in which case we
// only add them back to reach if no configuration during the current
@ -595,9 +603,9 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// chooses an alternative Matching the longest overall sequence when
// multiple alternatives are viable.
//
if skippedStopStates != nil && ((!fullCtx) || (!PredictionModehasConfigInRuleStopState(reach))) {
for l := 0; l < len(skippedStopStates); l++ {
reach.Add(skippedStopStates[l], this.mergeCache)
if SkippedStopStates != nil && ((!fullCtx) || (!PredictionModehasConfigInRuleStopState(reach))) {
for l := 0; l < len(SkippedStopStates); l++ {
reach.Add(SkippedStopStates[l], this.mergeCache)
}
}
if len(reach.GetItems()) == 0 {
@ -614,7 +622,7 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// method simply returns {@code configs}.
//
// <p>When {@code lookToEndOfRule} is true, this method uses
// {@link ATN//nextTokens} for each configuration in {@code configs} which is
// {@link ATN//NextTokens} for each configuration in {@code configs} which is
// not already in a rule stop state to see if a rule stop state is reachable
// from the configuration via epsilon-only transitions.</p>
//
@ -641,8 +649,8 @@ func (this *ParserATNSimulator) removeAllConfigsNotInRuleStopState(configs ATNCo
continue
}
if lookToEndOfRule && config.GetState().GetEpsilonOnlyTransitions() {
var nextTokens = this.atn.nextTokens(config.GetState(), nil)
if nextTokens.contains(TokenEpsilon) {
var NextTokens = this.atn.NextTokens(config.GetState(), nil)
if NextTokens.contains(TokenEpsilon) {
var endOfRuleState = this.atn.ruleToStopState[config.GetState().GetRuleIndex()]
result.Add(NewBaseATNConfig4(config, endOfRuleState), this.mergeCache)
}
@ -1173,7 +1181,7 @@ func (this *ParserATNSimulator) precedenceTransition(config ATNConfig,
fmt.Println("PRED (collectPredicates=" + fmt.Sprint(collectPredicates) + ") " +
strconv.Itoa(pt.precedence) + ">=_p, ctx dependent=true")
if this.parser != nil {
fmt.Println("context surrounding pred is " + fmt.Sprint(this.parser.getRuleInvocationStack(nil)))
fmt.Println("context surrounding pred is " + fmt.Sprint(this.parser.GetRuleInvocationStack(nil)))
}
}
var c *BaseATNConfig = nil
@ -1209,7 +1217,7 @@ func (this *ParserATNSimulator) predTransition(config ATNConfig, pt *PredicateTr
fmt.Println("PRED (collectPredicates=" + fmt.Sprint(collectPredicates) + ") " + strconv.Itoa(pt.ruleIndex) +
":" + strconv.Itoa(pt.predIndex) + ", ctx dependent=" + fmt.Sprint(pt.isCtxDependent))
if this.parser != nil {
fmt.Println("context surrounding pred is " + fmt.Sprint(this.parser.getRuleInvocationStack(nil)))
fmt.Println("context surrounding pred is " + fmt.Sprint(this.parser.GetRuleInvocationStack(nil)))
}
}
var c *BaseATNConfig = nil
@ -1466,7 +1474,7 @@ func (this *ParserATNSimulator) ReportAttemptingFullContext(dfa *DFA, conflictin
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
}
if this.parser != nil {
this.parser.getErrorListenerDispatch().ReportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs)
this.parser.GetErrorListenerDispatch().ReportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs)
}
}
@ -1477,7 +1485,7 @@ func (this *ParserATNSimulator) ReportContextSensitivity(dfa *DFA, prediction in
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
}
if this.parser != nil {
this.parser.getErrorListenerDispatch().ReportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs)
this.parser.GetErrorListenerDispatch().ReportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs)
}
}
@ -1490,6 +1498,6 @@ func (this *ParserATNSimulator) ReportAmbiguity(dfa *DFA, D *DFAState, startInde
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
}
if this.parser != nil {
this.parser.getErrorListenerDispatch().ReportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
this.parser.GetErrorListenerDispatch().ReportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
}
}

View File

@ -170,7 +170,7 @@ func (prc *BaseParserRuleContext) GetChildOfType(i int, childType reflect.Type)
}
}
func (this *BaseParserRuleContext) StringTree(ruleNames []string, recog Recognizer) string {
func (this *BaseParserRuleContext) ToStringTree(ruleNames []string, recog Recognizer) string {
return TreesStringTree(this, ruleNames, recog)
}

View File

@ -638,7 +638,7 @@ func mergeArrays(a, b *ArrayPredictionContext, rootIsWildcard bool, mergeCache *
mergedReturnStates[k] = payload
}
i += 1 // hop over left one as usual
j += 1 // but also skip one in right side since we merge
j += 1 // but also Skip one in right side since we merge
} else if a.returnStates[i] < b.returnStates[j] { // copy a[i] to M
mergedParents[k] = a_parent
mergedReturnStates[k] = a.returnStates[i]

View File

@ -69,7 +69,7 @@ const (
// This prediction mode does not provide any guarantees for prediction
// behavior for syntactically-incorrect inputs.</p>
//
PredictionModeLL_EXACT_AMBIG_DETECTION = 2
PredictionModeLLExactAmbigDetection = 2
)
//

View File

@ -20,7 +20,7 @@ type Recognizer interface {
AddErrorListener(ErrorListener)
RemoveErrorListeners()
GetATN() *ATN
getErrorListenerDispatch() ErrorListener
GetErrorListenerDispatch() ErrorListener
}
type BaseRecognizer struct {
@ -201,7 +201,7 @@ func (this *BaseRecognizer) GetTokenErrorDisplay(t Token) string {
return "'" + s + "'"
}
func (this *BaseRecognizer) getErrorListenerDispatch() ErrorListener {
func (this *BaseRecognizer) GetErrorListenerDispatch() ErrorListener {
return NewProxyErrorListener(this._listeners)
}

View File

@ -264,7 +264,7 @@ func (this *AND) evalPrecedence(parser Recognizer, outerContext RuleContext) Sem
// The AND context is false if any element is false
return nil
} else if evaluated != SemanticContextNone {
// Reduce the result by skipping true elements
// Reduce the result by Skipping true elements
operands = append(operands, evaluated)
}
}
@ -399,7 +399,7 @@ func (this *OR) evalPrecedence(parser Recognizer, outerContext RuleContext) Sema
// The OR context is true if any element is true
return SemanticContextNone
} else if evaluated != nil {
// Reduce the result by skipping false elements
// Reduce the result by Skipping false elements
operands = append(operands, evaluated)
}
}

View File

@ -57,7 +57,7 @@ const (
TokenEOF = -1
// All tokens go to the parser (unless skip() is called in that rule)
// All tokens go to the parser (unless Skip() is called in that rule)
// on a particular "channel". The parser tunes to a particular channel
// so that whitespace etc... can go to the parser on a "hidden" channel.
@ -130,8 +130,8 @@ func NewCommonToken(source *TokenSourceCharStreamPair, tokenType, channel, start
t.stop = stop
t.tokenIndex = -1
if t.source.tokenSource != nil {
t.line = source.tokenSource.getLine()
t.column = source.tokenSource.getCharPositionInLine()
t.line = source.tokenSource.GetLine()
t.column = source.tokenSource.GetCharPositionInLine()
} else {
t.column = -1
}

View File

@ -1,11 +1,11 @@
package antlr4
type TokenSource interface {
nextToken() Token
skip()
more()
getLine() int
getCharPositionInLine() int
NextToken() Token
Skip()
More()
GetLine() int
GetCharPositionInLine() int
GetInputStream() CharStream
GetSourceName() string
setTokenFactory(factory TokenFactory)

View File

@ -14,7 +14,6 @@ type Tree interface {
GetChild(i int) Tree
GetChildCount() int
GetChildren() []Tree
// StringTree() string
}
type SyntaxTree interface {
@ -28,7 +27,8 @@ type ParseTree interface {
Accept(Visitor ParseTreeVisitor) interface{}
GetText() string
// StringTree([]string, IRecognizer) string
ToStringTree([]string, Recognizer) string
}
type RuleNode interface {
@ -167,6 +167,10 @@ func (this *TerminalNodeImpl) String() string {
}
}
func (this *TerminalNodeImpl) ToStringTree(s []string, r Recognizer) string {
return this.String()
}
// Represents a token that was consumed during reSynchronization
// rather than during a valid Match operation. For example,
// we will create this kind of a node during single token insertion

View File

@ -13,7 +13,7 @@ func TreesStringTree(tree Tree, ruleNames []string, recog Recognizer) string {
ruleNames = recog.GetRuleNames()
}
var s = TreesgetNodeText(tree, ruleNames, nil)
var s = TreesGetNodeText(tree, ruleNames, nil)
s = EscapeWhitespace(s, false)
var c = tree.GetChildCount()
@ -33,7 +33,7 @@ func TreesStringTree(tree Tree, ruleNames []string, recog Recognizer) string {
return res
}
func TreesgetNodeText(t Tree, ruleNames []string, recog *BaseParser) string {
func TreesGetNodeText(t Tree, ruleNames []string, recog Parser) string {
if recog != nil {
ruleNames = recog.GetRuleNames()

View File

@ -232,7 +232,7 @@ case <index>:
* overriding implementation impossible to maintain.
*/
RuleSempredFunction(r, actions) ::= <<
func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="cap">_Sempred(localctx antlr4.RuleContext, predIndex int) {
func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="cap">_Sempred(localctx antlr4.RuleContext, predIndex int) bool {
switch predIndex {
<actions:{index| case <index>:
return <actions.(index)>;}; separator="\n">
@ -256,7 +256,7 @@ func (p *<parser.name>) <currentRule.name; format="cap">(<currentRule.args:{a |
localctx := New<currentRule.ctxType>(p, p.GetParserRuleContext(), p.GetState()<currentRule.args:{a | , <a.name>}>)
p.EnterRule(localctx, <currentRule.startState>, <parser.name>RULE_<currentRule.name>)
<namedActions.init>
<locals; separator="\n">
<if(locals)>var <locals; separator="\nvar "><endif>
defer func(){
<finallyAction>
@ -305,7 +305,7 @@ func (p *<parser.name>) <currentRule.name; format="cap">(_p int<if(currentRule.a
_startState := <currentRule.startState>
p.EnterRecursionRule(localctx, <currentRule.startState>, <parser.name>RULE_<currentRule.name>, _p)
<namedActions.init>
<locals; separator="\n">
<if(locals)>var <locals; separator="\nvar "><endif>
defer func(){
<finallyAction>
@ -340,7 +340,7 @@ p.EnterOuterAlt(localctx, <currentOuterMostAltCodeBlock.alt.altNum>)
>>
CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= <<
<locals; separator="\n">
<if(locals)>var <locals; separator="\nvar "><endif>
<preamble; separator="\n">
<ops; separator="\n">
>>
@ -578,17 +578,17 @@ SetAttr(s,rhsChunks) ::= "<ctx(s)>.<s.name> = <rhsChunks>"
TokenLabelType() ::= "<file.TokenLabelType; null={antlr4.Token}>"
InputSymbolType() ::= "<file.InputSymbolType; null={antlr4.Token}>"
TokenPropertyRef_text(t) ::= "(<ctx(t)>.<t.label>==null ? null : <ctx(t)>.<t.label>.GetText())"
TokenPropertyRef_type(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : <ctx(t)>.<t.label>.GetTokenType())"
TokenPropertyRef_line(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : <ctx(t)>.<t.label>.GetLine())"
TokenPropertyRef_pos(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : <ctx(t)>.<t.label>.GetColumn())"
TokenPropertyRef_channel(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : <ctx(t)>.<t.label>.GetChannel())"
TokenPropertyRef_index(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : <ctx(t)>.<t.label>.GetTokenIndex())"
TokenPropertyRef_int(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : strconv.Atoi(<ctx(t)>.<t.label>.GetText()))"
TokenPropertyRef_text(t) ::= "(func() string { if <ctx(t)>.<t.label> == nil { return \"\" } else { return <ctx(t)>.<t.label>.GetText() }}())"
TokenPropertyRef_type(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return <ctx(t)>.<t.label>.GetTokenType() }}())"
TokenPropertyRef_line(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return <ctx(t)>.<t.label>.GetLine() }}())"
TokenPropertyRef_pos(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return <ctx(t)>.<t.label>.GetColumn() }}())"
TokenPropertyRef_channel(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return <ctx(t)>.<t.label>.GetChannel() }}())"
TokenPropertyRef_index(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return <ctx(t)>.<t.label>.GetTokenIndex() }}())"
TokenPropertyRef_int(t) ::= "(func() int { if <ctx(t)>.<t.label> == nil { return 0 } else { return strconv.Atoi(<ctx(t)>.<t.label>.GetText()) }}())"
RulePropertyRef_start(r) ::= "(<ctx(r)>.<r.label>==null ? null : <ctx(r)>.<r.label>.GetStart())"
RulePropertyRef_stop(r) ::= "(<ctx(r)>.<r.label>==null ? null : <ctx(r)>.<r.label>.GetStop())"
RulePropertyRef_text(r) ::= "(<ctx(r)>.<r.label>==null ? null : p.GetTokenStream().GetText(<ctx(r)>.<r.label>.GetStart().GetTokenIndex(),<ctx(r)>.<r.label>.GetStop().GetTokenIndex()))"
RulePropertyRef_start(r) ::= "(func() antlr4.Token { if <ctx(r)>.<r.label> == nil { return nil } else { return <ctx(r)>.<r.label>.GetStart() }}())"
RulePropertyRef_stop(r) ::= "(func() antlr4.Token { if <ctx(r)>.<r.label> == nil { return nil } else { return <ctx(r)>.<r.label>.GetStop() }}())"
RulePropertyRef_text(r) ::= "(func() string { if <ctx(r)>.<r.label> == nil { return \"\" } else { return p.GetTokenStream().GetTextFromInterval( antlr4.NewInterval( <ctx(r)>.<r.label>.GetStart().GetTokenIndex(),<ctx(r)>.<r.label>.GetStop().GetTokenIndex())) }}())"
RulePropertyRef_ctx(r) ::= "<ctx(r)>.<r.label>"
RulePropertyRef_parser(r) ::= "p"
@ -695,7 +695,7 @@ func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, inv
<if(struct.provideCopyFrom)> <! don't need copy unless we have subclasses !>
func (s *<struct.name>) CopyFrom(ctx *<struct.name>) {
s.BaseParserRuleContext.CopyFrom(ctx)
s.BaseParserRuleContext.CopyFrom(ctx.BaseParserRuleContext)
<struct.attrs:{a | s.<a.name> = ctx.<a.name>;}; separator="\n">
}
<endif>
@ -723,9 +723,8 @@ func New<struct.name>(parser antlr4.Parser, ctx antlr4.ParserRuleContext) *<stru
var p = new(<struct.name>)
p.<currentRule.name; format="cap">Context = new(<currentRule.name; format="cap">Context)
p.parser = parser
p.CopyFrom(ctx)
p.CopyFrom(ctx.(*<currentRule.name; format="cap">Context))
return p
}