forked from jasder/antlr
Various minor fixes
This commit is contained in:
parent
960c59e373
commit
81b47eedd7
|
@ -0,0 +1,6 @@
|
|||
grammar M;
|
||||
options { language = JavaScript; }
|
||||
import S;
|
||||
s : a;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
|
@ -0,0 +1,62 @@
|
|||
// Generated from M.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 MListener},
|
||||
* which can be extended to create a listener which only needs to handle a subset
|
||||
* of the available methods.
|
||||
*/
|
||||
public class MBaseListener implements MListener {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterS(MParser.SContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitS(MParser.SContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void enterA(MParser.AContext ctx) { }
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* <p>The default implementation does nothing.</p>
|
||||
*/
|
||||
@Override public void exitA(MParser.AContext 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) { }
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
// Generated from M.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 MLexer 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
|
||||
B=1, WS=2;
|
||||
public static String[] modeNames = {
|
||||
"DEFAULT_MODE"
|
||||
};
|
||||
|
||||
public static final String[] ruleNames = {
|
||||
"B", "WS"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'b'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, "B", "WS"
|
||||
};
|
||||
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 MLexer(CharStream input) {
|
||||
super(input);
|
||||
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGrammarFileName() { return "M.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\4\r\b\1\4\2\t\2\4"+
|
||||
"\3\t\3\3\2\3\2\3\3\3\3\3\3\3\3\2\2\4\3\3\5\4\3\2\3\4\2\f\f\"\"\f\2\3\3"+
|
||||
"\2\2\2\2\5\3\2\2\2\3\7\3\2\2\2\5\t\3\2\2\2\7\b\7d\2\2\b\4\3\2\2\2\t\n"+
|
||||
"\t\2\2\2\n\13\3\2\2\2\13\f\b\3\2\2\f\6\3\2\2\2\3\2\3\b\2\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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
// Generated from M.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 MParser}.
|
||||
*/
|
||||
public interface MListener extends ParseTreeListener {
|
||||
/**
|
||||
* Enter a parse tree produced by {@link MParser#s}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterS(MParser.SContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link MParser#s}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitS(MParser.SContext ctx);
|
||||
/**
|
||||
* Enter a parse tree produced by {@link MParser#a}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void enterA(MParser.AContext ctx);
|
||||
/**
|
||||
* Exit a parse tree produced by {@link MParser#a}.
|
||||
* @param ctx the parse tree
|
||||
*/
|
||||
void exitA(MParser.AContext ctx);
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
// Generated from M.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 MParser 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
|
||||
B=1, WS=2;
|
||||
public static final int
|
||||
RULE_s = 0, RULE_a = 1;
|
||||
public static final String[] ruleNames = {
|
||||
"s", "a"
|
||||
};
|
||||
|
||||
private static final String[] _LITERAL_NAMES = {
|
||||
null, "'b'"
|
||||
};
|
||||
private static final String[] _SYMBOLIC_NAMES = {
|
||||
null, "B", "WS"
|
||||
};
|
||||
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 "M.g4"; }
|
||||
|
||||
@Override
|
||||
public String[] getRuleNames() { return ruleNames; }
|
||||
|
||||
@Override
|
||||
public String getSerializedATN() { return _serializedATN; }
|
||||
|
||||
@Override
|
||||
public ATN getATN() { return _ATN; }
|
||||
|
||||
public MParser(TokenStream input) {
|
||||
super(input);
|
||||
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
|
||||
}
|
||||
public static class SContext extends ParserRuleContext {
|
||||
public AContext a() {
|
||||
return getRuleContext(AContext.class,0);
|
||||
}
|
||||
public SContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_s; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof MListener ) ((MListener)listener).enterS(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof MListener ) ((MListener)listener).exitS(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final SContext s() throws RecognitionException {
|
||||
SContext _localctx = new SContext(_ctx, getState());
|
||||
enterRule(_localctx, 0, RULE_s);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(4);
|
||||
a();
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
_localctx.exception = re;
|
||||
_errHandler.reportError(this, re);
|
||||
_errHandler.recover(this, re);
|
||||
}
|
||||
finally {
|
||||
exitRule();
|
||||
}
|
||||
return _localctx;
|
||||
}
|
||||
|
||||
public static class AContext extends ParserRuleContext {
|
||||
public TerminalNode B() { return getToken(MParser.B, 0); }
|
||||
public AContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@Override public int getRuleIndex() { return RULE_a; }
|
||||
@Override
|
||||
public void enterRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof MListener ) ((MListener)listener).enterA(this);
|
||||
}
|
||||
@Override
|
||||
public void exitRule(ParseTreeListener listener) {
|
||||
if ( listener instanceof MListener ) ((MListener)listener).exitA(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final AContext a() throws RecognitionException {
|
||||
AContext _localctx = new AContext(_ctx, getState());
|
||||
enterRule(_localctx, 2, RULE_a);
|
||||
try {
|
||||
enterOuterAlt(_localctx, 1);
|
||||
{
|
||||
setState(6);
|
||||
match(B);
|
||||
}
|
||||
int x = 0;
|
||||
}
|
||||
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\4\13\4\2\t\2\4\3"+
|
||||
"\t\3\3\2\3\2\3\3\3\3\3\3\2\2\4\2\4\2\2\b\2\6\3\2\2\2\4\b\3\2\2\2\6\7\5"+
|
||||
"\4\3\2\7\3\3\2\2\2\b\t\7\3\2\2\t\5\3\2\2\2\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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
parser grammar S;
|
||||
a @after {int x = 0;} : B;
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"antlr4"
|
||||
"parser"
|
||||
"fmt"
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -27,11 +27,11 @@ func main() {
|
|||
|
||||
a := antlr4.NewFileStream("foo.txt")
|
||||
|
||||
l := parser.NewArithmeticLexer(a)
|
||||
l := parser.NewMLexer(a)
|
||||
|
||||
s := antlr4.NewCommonTokenStream(l, 0)
|
||||
|
||||
p := parser.NewExprParser(s)
|
||||
p := parser.NewMParser(s)
|
||||
|
||||
p.BuildParseTrees = true
|
||||
|
||||
|
|
|
@ -149,9 +149,9 @@ string(text) ::= <<
|
|||
|
||||
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
|
||||
|
||||
writeln(s) ::= <<fmt.Println(<s>);>>
|
||||
writeln(s) ::= <<fmt.Println(<s>)>>
|
||||
|
||||
write(s) ::= <<fmt.Print(<s>);>>
|
||||
write(s) ::= <<fmt.Print(<s>)>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
|
@ -159,7 +159,7 @@ True() ::= "true"
|
|||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= <<assert(<s>);>>
|
||||
Assert(s) ::= <<assert(<s>)>>
|
||||
|
||||
Cast(t,v) ::= "((<t>)<v>)"
|
||||
|
||||
|
@ -167,7 +167,7 @@ Append(a,b) ::= "<a> + <b>"
|
|||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
DeclareLocal(s,v) ::= "<s> := <v>"
|
||||
|
||||
AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use type system
|
||||
|
||||
|
@ -191,15 +191,15 @@ ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
|||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.DumpDFA();"
|
||||
DumpDFA() ::= "p.DumpDFA()"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "List\<String>"
|
||||
|
||||
BuildParseTrees() ::= "SetBuildParseTree(true);"
|
||||
BuildParseTrees() ::= "this.BuildParseTrees = true"
|
||||
|
||||
BailErrorStrategy() ::= <%SetErrorHandler(new BailErrorStrategy());%>
|
||||
BailErrorStrategy() ::= <%SetErrorHandler(NewBailErrorStrategy());%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(this)%>
|
||||
|
||||
|
@ -243,7 +243,7 @@ package antlrtest
|
|||
//@Override
|
||||
func (this *PositionAdjustingLexer) NextToken() *Token {
|
||||
if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {
|
||||
_interp = new PositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
|
||||
_interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
|
||||
}
|
||||
|
||||
return super.nextToken();
|
||||
|
@ -323,8 +323,8 @@ type LeafListener extends TBaseListener {
|
|||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(new LeafListener(), <s>);
|
||||
ParseTreeWalker walker = NewParseTreeWalker();
|
||||
walker.walk(NewLeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
|
|
|
@ -14,7 +14,7 @@ public class TestCompositeLexers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"lexer grammar S;\n" +
|
||||
"A : 'a' {fmt.Println(\"S.A\");};\n" +
|
||||
"A : 'a' {fmt.Println(\"S.A\")};\n" +
|
||||
"C : 'c' ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
|
@ -42,15 +42,15 @@ public class TestCompositeLexers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"lexer grammar S;\n" +
|
||||
"A : 'a' {fmt.Println(\"S.A\");} ;\n" +
|
||||
"B : 'b' {fmt.Println(\"S.B\");} ;";
|
||||
"A : 'a' {fmt.Println(\"S.A\")} ;\n" +
|
||||
"B : 'b' {fmt.Println(\"S.B\")} ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(86);
|
||||
StringBuilder grammarBuilder = new StringBuilder(85);
|
||||
grammarBuilder.append("lexer grammar M;\n");
|
||||
grammarBuilder.append("import S;\n");
|
||||
grammarBuilder.append("A : 'a' B {fmt.Println(\"M.A\");} ;\n");
|
||||
grammarBuilder.append("A : 'a' B {fmt.Println(\"M.A\")} ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="ab";
|
||||
|
|
|
@ -16,7 +16,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : '=' 'a' {fmt.Print(\"S.a\");};";
|
||||
"a : '=' 'a' {fmt.Print(\"S.a\")};";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(54);
|
||||
|
@ -40,7 +40,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : 'x' INT {fmt.Println(\"S.x\");};\n" +
|
||||
"x : 'x' INT {fmt.Println(\"S.x\")};\n" +
|
||||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
@ -65,13 +65,13 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C, B, A } // reverse order\n" +
|
||||
"y : A {fmt.Println(\"T.y\");};";
|
||||
"y : A {fmt.Println(\"T.y\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"tokens { A, B, C }\n" +
|
||||
"x : A {fmt.Println(\"S.x\");};";
|
||||
"x : A {fmt.Println(\"S.x\")};";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(598);
|
||||
|
@ -135,7 +135,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {fmt.Println(\"S.a\");};";
|
||||
"a : B {fmt.Println(\"S.a\")};";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(104);
|
||||
|
@ -159,13 +159,13 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a[int x] returns [int y] : B {fmt.Print(\"S.a\");} {$y=1000;} ;";
|
||||
"a[int x] returns [int y] : B {fmt.Print(\"S.a\")} {$y=1000;} ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(138);
|
||||
StringBuilder grammarBuilder = new StringBuilder(137);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S;\n");
|
||||
grammarBuilder.append("s : label=a[3] {fmt.Println($label.y);} ;\n");
|
||||
grammarBuilder.append("s : label=a[3] {fmt.Println($label.y)} ;\n");
|
||||
grammarBuilder.append("B : 'b' ; // defines B from inherited token space\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -183,13 +183,13 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : B {fmt.Print(\"S.a\");} ;";
|
||||
"a : B {fmt.Print(\"S.a\")} ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(126);
|
||||
StringBuilder grammarBuilder = new StringBuilder(125);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S;\n");
|
||||
grammarBuilder.append("s : a {fmt.Print($a.text);} ;\n");
|
||||
grammarBuilder.append("s : a {fmt.Print($a.text)} ;\n");
|
||||
grammarBuilder.append("B : 'b' ; // defines B from inherited token space\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -207,12 +207,12 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {fmt.Println(\"T.a\");};";
|
||||
"a : B {fmt.Println(\"T.a\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {fmt.Println(\"S.a\");};\n" +
|
||||
"a : b {fmt.Println(\"S.a\")};\n" +
|
||||
"b : B;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
|
@ -237,7 +237,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
mkdir(parserpkgdir);
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {fmt.Print(\"S.a\");};\n" +
|
||||
"a : b {fmt.Print(\"S.a\")};\n" +
|
||||
"b : B ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
|
@ -262,19 +262,19 @@ public class TestCompositeParsers extends BaseTest {
|
|||
String slave_T =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A }\n" +
|
||||
"b : 'b' {fmt.Println(\"T.b\");};";
|
||||
"b : 'b' {fmt.Println(\"T.b\")};";
|
||||
writeFile(parserpkgdir, "T.g4", slave_T);
|
||||
|
||||
String slave_S =
|
||||
"parser grammar S;\n" +
|
||||
"a : b {fmt.Println(\"S.a\");};\n" +
|
||||
"a : b {fmt.Println(\"S.a\")};\n" +
|
||||
"b : 'b' ;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
StringBuilder grammarBuilder = new StringBuilder(87);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S, T;\n");
|
||||
grammarBuilder.append("b : 'b'|'c' {fmt.Println(\"M.b\");}|B|A;\n");
|
||||
grammarBuilder.append("b : 'b'|'c' {fmt.Println(\"M.b\")}|B|A;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="c";
|
||||
|
@ -295,7 +295,7 @@ public class TestCompositeParsers extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"type_ : 'int' ;\n" +
|
||||
"decl : type_ ID ';'\n" +
|
||||
" | type_ ID init ';' {fmt.Print(\"JavaDecl: \" + $text);};\n" +
|
||||
" | type_ ID init ';' {fmt.Print(\"JavaDecl: \" + $text)};\n" +
|
||||
"init : '=' INT;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
|
@ -404,11 +404,11 @@ public class TestCompositeParsers extends BaseTest {
|
|||
"ID : 'a'..'z'+;";
|
||||
writeFile(parserpkgdir, "S.g4", slave_S);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(115);
|
||||
StringBuilder grammarBuilder = new StringBuilder(113);
|
||||
grammarBuilder.append("grammar M;\n");
|
||||
grammarBuilder.append("import S;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(\"M.a: \" + $A);};\n");
|
||||
grammarBuilder.append("A : 'abc' {fmt.Println(\"M.A\");};\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(\"M.a: \" + $A)};\n");
|
||||
grammarBuilder.append("A : 'abc' {fmt.Println(\"M.A\")};\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abc";
|
||||
|
|
|
@ -12,9 +12,9 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testAmbigYieldsCtxSensitiveDFA() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(101);
|
||||
StringBuilder grammarBuilder = new StringBuilder(97);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("s @after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : ID | ID {} ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\t'|'\\n')+ -> skip ;");
|
||||
|
@ -34,11 +34,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testAmbiguityNoLoop() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(209);
|
||||
StringBuilder grammarBuilder = new StringBuilder(208);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("prog\n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append(" : expr expr {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" : expr expr {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | expr\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("expr: '@'\n");
|
||||
|
@ -65,9 +65,9 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testCtxSensitiveDFATwoDiffInput() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(165);
|
||||
StringBuilder grammarBuilder = new StringBuilder(161);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("s @after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : ('$' a | '@' b)+ ;\n");
|
||||
grammarBuilder.append("a : e ID ;\n");
|
||||
grammarBuilder.append("b : e INT ID ;\n");
|
||||
|
@ -96,9 +96,9 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testCtxSensitiveDFA_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(162);
|
||||
StringBuilder grammarBuilder = new StringBuilder(158);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("s @after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '$' a | '@' b ;\n");
|
||||
grammarBuilder.append("a : e ID ;\n");
|
||||
grammarBuilder.append("b : e INT ID ;\n");
|
||||
|
@ -125,9 +125,9 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testCtxSensitiveDFA_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(162);
|
||||
StringBuilder grammarBuilder = new StringBuilder(158);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("s @after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '$' a | '@' b ;\n");
|
||||
grammarBuilder.append("a : e ID ;\n");
|
||||
grammarBuilder.append("b : e INT ID ;\n");
|
||||
|
@ -154,11 +154,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testExprAmbiguity_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(283);
|
||||
StringBuilder grammarBuilder = new StringBuilder(282);
|
||||
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(": expr[0] {fmt.Println($expr.ctx.toStringTree(this))};\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(283);
|
||||
StringBuilder grammarBuilder = new StringBuilder(282);
|
||||
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(": expr[0] {fmt.Println($expr.ctx.toStringTree(this))};\n");
|
||||
grammarBuilder.append(" expr[int _p]\n");
|
||||
grammarBuilder.append(" : ID \n");
|
||||
grammarBuilder.append(" ( \n");
|
||||
|
@ -216,11 +216,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -242,11 +242,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -271,11 +271,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_3() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -301,11 +301,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_4() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -332,11 +332,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_5() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -366,11 +366,11 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testFullContextIF_THEN_ELSEParse_6() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
StringBuilder grammarBuilder = new StringBuilder(233);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s \n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append("@after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("@after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : '{' stat* '}' ;\n");
|
||||
grammarBuilder.append("stat: 'if' ID 'then' stat ('else' ID)?\n");
|
||||
grammarBuilder.append(" | 'return'\n");
|
||||
|
@ -400,14 +400,14 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testLoopsSimulateTailRecursion() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(309);
|
||||
StringBuilder grammarBuilder = new StringBuilder(307);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("prog\n");
|
||||
grammarBuilder.append("@init {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);}\n");
|
||||
grammarBuilder.append(" : expr_or_assign*;\n");
|
||||
grammarBuilder.append("expr_or_assign\n");
|
||||
grammarBuilder.append(" : expr '++' {fmt.Println(\"fail.\");}\n");
|
||||
grammarBuilder.append(" | expr {fmt.Println(\"pass: \"+$expr.text);}\n");
|
||||
grammarBuilder.append(" : expr '++' {fmt.Println(\"fail.\")}\n");
|
||||
grammarBuilder.append(" | expr {fmt.Println(\"pass: \"+$expr.text)}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("expr: expr_primary ('<-' ID)?;\n");
|
||||
grammarBuilder.append("expr_primary\n");
|
||||
|
@ -432,9 +432,9 @@ public class TestFullContextParsing extends BaseTest {
|
|||
@Test
|
||||
public void testSLLSeesEOFInLLGrammar() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(149);
|
||||
StringBuilder grammarBuilder = new StringBuilder(145);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s @after {this.DumpDFA();}\n");
|
||||
grammarBuilder.append("s @after {p.DumpDFA()}\n");
|
||||
grammarBuilder.append(" : a;\n");
|
||||
grammarBuilder.append("a : e ID ;\n");
|
||||
grammarBuilder.append("b : e INT ID ;\n");
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,13 +13,13 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testActionPlacement() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(288);
|
||||
StringBuilder grammarBuilder = new StringBuilder(283);
|
||||
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: \" + 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("WS : (' '|'\\n') -> skip ;\n");
|
||||
grammarBuilder.append("J : .;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -40,9 +40,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(79);
|
||||
StringBuilder grammarBuilder = new StringBuilder(78);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : '0'..'9'+ {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : '0'..'9'+ {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u000D] -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input =
|
||||
|
@ -63,9 +63,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetInSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(86);
|
||||
StringBuilder grammarBuilder = new StringBuilder(85);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : (~[ab \\n]|'a') {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : (~[ab \\n]|'a') {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u000D]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="a x";
|
||||
|
@ -84,9 +84,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetNot() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(89);
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : ~[ab \\n] ~[ \\ncd]* {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : ~[ab \\n] ~[ \\ncd]* {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u000D]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="xaf";
|
||||
|
@ -103,9 +103,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetPlus() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(80);
|
||||
StringBuilder grammarBuilder = new StringBuilder(79);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : '0'..'9'+ {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : '0'..'9'+ {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u000D]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input =
|
||||
|
@ -126,10 +126,10 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetRange() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(129);
|
||||
StringBuilder grammarBuilder = new StringBuilder(127);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : [0-9]+ {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("ID : [a-zA-Z] [a-zA-Z0-9]* {fmt.Println(\"ID\");} ;\n");
|
||||
grammarBuilder.append("I : [0-9]+ {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("ID : [a-zA-Z] [a-zA-Z0-9]* {fmt.Println(\"ID\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u0009\\r]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input =
|
||||
|
@ -155,9 +155,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithEscapedChar() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
StringBuilder grammarBuilder = new StringBuilder(87);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("DASHBRACK : [\\-\\]]+ {fmt.Println(\"DASHBRACK\");} ;\n");
|
||||
grammarBuilder.append("DASHBRACK : [\\-\\]]+ {fmt.Println(\"DASHBRACK\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\u]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="- ] ";
|
||||
|
@ -176,9 +176,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithMissingEndRange() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(76);
|
||||
StringBuilder grammarBuilder = new StringBuilder(75);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : [0-]+ {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : [0-]+ {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\u000D]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="00\n";
|
||||
|
@ -195,9 +195,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithMissingEscapeChar() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : [0-9]+ {fmt.Println(\"I\");} ;\n");
|
||||
grammarBuilder.append("I : [0-9]+ {fmt.Println(\"I\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\u]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="34 ";
|
||||
|
@ -214,9 +214,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithQuote1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(74);
|
||||
StringBuilder grammarBuilder = new StringBuilder(73);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("A : [\"a-z]+ {fmt.Println(\"A\");} ;\n");
|
||||
grammarBuilder.append("A : [\"a-z]+ {fmt.Println(\"A\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\t]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="b\"a";
|
||||
|
@ -233,9 +233,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithQuote2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(75);
|
||||
StringBuilder grammarBuilder = new StringBuilder(74);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("A : [\"\\\\ab]+ {fmt.Println(\"A\");} ;\n");
|
||||
grammarBuilder.append("A : [\"\\\\ab]+ {fmt.Println(\"A\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\n\\t]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="b\"\\a";
|
||||
|
@ -252,9 +252,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testCharSetWithReversedRange() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(72);
|
||||
StringBuilder grammarBuilder = new StringBuilder(71);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("A : [z-a9]+ {fmt.Println(\"A\");} ;\n");
|
||||
grammarBuilder.append("A : [z-a9]+ {fmt.Println(\"A\")} ;\n");
|
||||
grammarBuilder.append("WS : [ \\u]+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="9";
|
||||
|
@ -345,9 +345,9 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testGreedyConfigs() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(99);
|
||||
StringBuilder grammarBuilder = new StringBuilder(98);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : ('a' | 'ab') {fmt.Println(this.GetText());} ;\n");
|
||||
grammarBuilder.append("I : ('a' | 'ab') {fmt.Println(this.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(134);
|
||||
StringBuilder grammarBuilder = new StringBuilder(132);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("I : .*? ('a' | 'ab') {fmt.Println(this.GetText());} ;\n");
|
||||
grammarBuilder.append("I : .*? ('a' | 'ab') {fmt.Println(this.GetText())} ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;\n");
|
||||
grammarBuilder.append("J : . {fmt.Println(this.GetText());};");
|
||||
grammarBuilder.append("J : . {fmt.Println(this.GetText())};");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="ab";
|
||||
String found = execLexer("L.g4", grammar, "L", input, false);
|
||||
|
@ -4625,7 +4625,7 @@ public class TestLexerExec extends BaseTest {
|
|||
public void testPositionAdjustingLexer() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(2634);
|
||||
StringBuilder grammarBuilder = new StringBuilder(2633);
|
||||
grammarBuilder.append("lexer grammar PositionAdjustingLexer;\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
|
@ -4634,7 +4634,7 @@ public class TestLexerExec extends BaseTest {
|
|||
grammarBuilder.append("//@Override\n");
|
||||
grammarBuilder.append("func (this *PositionAdjustingLexer) NextToken() *Token {\n");
|
||||
grammarBuilder.append(" if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {\n");
|
||||
grammarBuilder.append(" _interp = new PositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);\n");
|
||||
grammarBuilder.append(" _interp = NewPositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append(" return super.nextToken();\n");
|
||||
|
|
|
@ -12,7 +12,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(436);
|
||||
StringBuilder grammarBuilder = new StringBuilder(433);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -27,9 +27,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
@ -56,7 +56,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLR() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(610);
|
||||
StringBuilder grammarBuilder = new StringBuilder(607);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -75,9 +75,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e op='*' e\n");
|
||||
|
@ -108,7 +108,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(600);
|
||||
StringBuilder grammarBuilder = new StringBuilder(597);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -126,9 +126,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=e ;\n");
|
||||
grammarBuilder.append("e : e '(' eList ')' # Call\n");
|
||||
|
@ -158,7 +158,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(627);
|
||||
StringBuilder grammarBuilder = new StringBuilder(624);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -177,9 +177,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
|
@ -206,7 +206,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(627);
|
||||
StringBuilder grammarBuilder = new StringBuilder(624);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -225,9 +225,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : b b // forces list\n");
|
||||
|
@ -254,7 +254,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(571);
|
||||
StringBuilder grammarBuilder = new StringBuilder(568);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -273,9 +273,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
@ -301,7 +301,7 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(571);
|
||||
StringBuilder grammarBuilder = new StringBuilder(568);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -320,9 +320,9 @@ public class TestListeners extends BaseTest {
|
|||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@after {\n");
|
||||
grammarBuilder.append("fmt.Println($ctx.r.toStringTree(this));\n");
|
||||
grammarBuilder.append("ParseTreeWalker walker = new ParseTreeWalker();\n");
|
||||
grammarBuilder.append("walker.walk(new LeafListener(), $ctx.r);\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("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : INT INT\n");
|
||||
|
|
|
@ -12,14 +12,14 @@ public class TestParseTrees extends BaseTest {
|
|||
@Test
|
||||
public void test2AltLoop() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(133);
|
||||
StringBuilder grammarBuilder = new StringBuilder(135);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(126);
|
||||
StringBuilder grammarBuilder = new StringBuilder(128);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(139);
|
||||
StringBuilder grammarBuilder = new StringBuilder(141);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(141);
|
||||
StringBuilder grammarBuilder = new StringBuilder(143);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(135);
|
||||
StringBuilder grammarBuilder = new StringBuilder(137);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(142);
|
||||
StringBuilder grammarBuilder = new StringBuilder(144);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(124);
|
||||
StringBuilder grammarBuilder = new StringBuilder(126);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\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(162);
|
||||
StringBuilder grammarBuilder = new StringBuilder(163);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s\n");
|
||||
grammarBuilder.append("@init {\n");
|
||||
grammarBuilder.append("SetBuildParseTree(true);\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(this))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : r=a ;\n");
|
||||
grammarBuilder.append("a : 'x' { \n");
|
||||
grammarBuilder.append("fmt.Println(GetRuleInvocationStack());\n");
|
||||
grammarBuilder.append("fmt.Println(GetRuleInvocationStack())\n");
|
||||
grammarBuilder.append("} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
|
|
|
@ -12,9 +12,9 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testConjuringUpToken() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(63);
|
||||
StringBuilder grammarBuilder = new StringBuilder(62);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : 'a' x='b' {fmt.Println(\"conjured=\" + $x);} 'c' ;");
|
||||
grammarBuilder.append("a : 'a' x='b' {fmt.Println(\"conjured=\" + $x)} 'c' ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="ac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -29,9 +29,9 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testConjuringUpTokenFromSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(69);
|
||||
StringBuilder grammarBuilder = new StringBuilder(68);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : 'a' x=('b'|'c') {fmt.Println(\"conjured=\" + $x);} 'd' ;");
|
||||
grammarBuilder.append("a : 'a' x=('b'|'c') {fmt.Println(\"conjured=\" + $x)} 'd' ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="ad";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -46,7 +46,7 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testContextListGetters() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(207);
|
||||
StringBuilder grammarBuilder = new StringBuilder(205);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::members{\n");
|
||||
grammarBuilder.append("func foo() {\n");
|
||||
|
@ -56,8 +56,8 @@ public class TestParserErrors extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : (a | b)+;\n");
|
||||
grammarBuilder.append("a : 'a' {fmt.Print('a');};\n");
|
||||
grammarBuilder.append("b : 'b' {fmt.Print('b');};");
|
||||
grammarBuilder.append("a : 'a' {fmt.Print('a')};\n");
|
||||
grammarBuilder.append("b : 'b' {fmt.Print('b')};");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abab";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -184,7 +184,7 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testLL1ErrorInfo() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(299);
|
||||
StringBuilder grammarBuilder = new StringBuilder(298);
|
||||
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(this.GetExpectedTokens().toString(this.tokenNames))}\n");
|
||||
grammarBuilder.append(" : ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="dog and software";
|
||||
|
@ -383,10 +383,10 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testSingleSetInsertionConsumption() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(82);
|
||||
StringBuilder grammarBuilder = new StringBuilder(81);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("myset: ('b'|'c') ;\n");
|
||||
grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop);} ; ");
|
||||
grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop)} ; ");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="ad";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -496,10 +496,10 @@ public class TestParserErrors extends BaseTest {
|
|||
@Test
|
||||
public void testSingleTokenDeletionConsumption() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(82);
|
||||
StringBuilder grammarBuilder = new StringBuilder(81);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("myset: ('b'|'c') ;\n");
|
||||
grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop);} ; ");
|
||||
grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop)} ; ");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="aabd";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
|
|
@ -12,10 +12,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAPlus() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(84);
|
||||
StringBuilder grammarBuilder = new StringBuilder(83);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ID+ {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -32,10 +32,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAStar_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(84);
|
||||
StringBuilder grammarBuilder = new StringBuilder(83);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ID* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -52,10 +52,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAStar_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(84);
|
||||
StringBuilder grammarBuilder = new StringBuilder(83);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ID* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -72,10 +72,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorAPlus() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(89);
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|ID)+ {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -92,10 +92,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorAStar_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(89);
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|ID)* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -112,10 +112,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorAStar_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(89);
|
||||
StringBuilder grammarBuilder = new StringBuilder(88);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|ID)* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -132,12 +132,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorB() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(136);
|
||||
StringBuilder grammarBuilder = new StringBuilder(134);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ID {\n");
|
||||
grammarBuilder.append("fmt.Println(\"alt 1\");\n");
|
||||
grammarBuilder.append("fmt.Println(\"alt 1\")\n");
|
||||
grammarBuilder.append("} | INT {\n");
|
||||
grammarBuilder.append("fmt.Println(\"alt 2\");\n");
|
||||
grammarBuilder.append("fmt.Println(\"alt 2\")\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -155,11 +155,11 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorBPlus() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
StringBuilder grammarBuilder = new StringBuilder(111);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|INT{\n");
|
||||
grammarBuilder.append("})+ {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -177,11 +177,11 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorBStar_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
StringBuilder grammarBuilder = new StringBuilder(111);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|INT{\n");
|
||||
grammarBuilder.append("})* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -199,11 +199,11 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testAorBStar_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
StringBuilder grammarBuilder = new StringBuilder(111);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|INT{\n");
|
||||
grammarBuilder.append("})* {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -221,10 +221,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(105);
|
||||
StringBuilder grammarBuilder = new StringBuilder(104);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ID INT {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -259,12 +259,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testIfIfElseGreedyBinding1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(193);
|
||||
StringBuilder grammarBuilder = new StringBuilder(192);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("start : statement+ ;\n");
|
||||
grammarBuilder.append("statement : 'x' | ifStatement;\n");
|
||||
grammarBuilder.append("ifStatement : 'if' 'y' statement ('else' statement)? {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> channel(HIDDEN);");
|
||||
|
@ -283,12 +283,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testIfIfElseGreedyBinding2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(193);
|
||||
StringBuilder grammarBuilder = new StringBuilder(192);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("start : statement+ ;\n");
|
||||
grammarBuilder.append("statement : 'x' | ifStatement;\n");
|
||||
grammarBuilder.append("ifStatement : 'if' 'y' statement ('else' statement|) {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> channel(HIDDEN);");
|
||||
|
@ -307,12 +307,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testIfIfElseNonGreedyBinding1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(194);
|
||||
StringBuilder grammarBuilder = new StringBuilder(193);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("start : statement+ ;\n");
|
||||
grammarBuilder.append("statement : 'x' | ifStatement;\n");
|
||||
grammarBuilder.append("ifStatement : 'if' 'y' statement ('else' statement)?? {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> channel(HIDDEN);");
|
||||
|
@ -331,12 +331,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testIfIfElseNonGreedyBinding2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(193);
|
||||
StringBuilder grammarBuilder = new StringBuilder(192);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("start : statement+ ;\n");
|
||||
grammarBuilder.append("statement : 'x' | ifStatement;\n");
|
||||
grammarBuilder.append("ifStatement : 'if' 'y' statement (|'else' statement) {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> channel(HIDDEN);");
|
||||
|
@ -355,10 +355,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testLL1OptionalBlock_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(110);
|
||||
StringBuilder grammarBuilder = new StringBuilder(109);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|{}INT)? {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+ ;\n");
|
||||
|
@ -376,10 +376,10 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testLL1OptionalBlock_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(110);
|
||||
StringBuilder grammarBuilder = new StringBuilder(109);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|{}INT)? {\n");
|
||||
grammarBuilder.append("fmt.Println($text);\n");
|
||||
grammarBuilder.append("fmt.Println($text)\n");
|
||||
grammarBuilder.append("};\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+ ;\n");
|
||||
|
@ -397,12 +397,12 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testLabelAliasingAcrossLabeledAlternatives() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(171);
|
||||
StringBuilder grammarBuilder = new StringBuilder(169);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("start : a* EOF;\n");
|
||||
grammarBuilder.append("a\n");
|
||||
grammarBuilder.append(" : label=subrule {fmt.Println($label.text);} #One\n");
|
||||
grammarBuilder.append(" | label='y' {fmt.Println($label.text);} #Two\n");
|
||||
grammarBuilder.append(" : label=subrule {fmt.Println($label.text)} #One\n");
|
||||
grammarBuilder.append(" | label='y' {fmt.Println($label.text)} #Two\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("subrule : 'x';\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
@ -584,14 +584,14 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testParserProperty() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(158);
|
||||
StringBuilder grammarBuilder = new StringBuilder(157);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool Property() {\n");
|
||||
grammarBuilder.append(" return true;\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {fmt.Println(\"valid\");}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {fmt.Println(\"valid\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
@ -629,13 +629,13 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testPredictionIssue334() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(248);
|
||||
StringBuilder grammarBuilder = new StringBuilder(246);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("file_ @init{\n");
|
||||
grammarBuilder.append("SetErrorHandler(new BailErrorStrategy());\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(this))\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append(" : item (SEMICOLON item)* SEMICOLON? EOF ;\n");
|
||||
grammarBuilder.append("item : A B?;\n");
|
||||
|
@ -656,9 +656,9 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testReferenceToATN_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(113);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|ATN)* ATN? {fmt.Println($text);} ;\n");
|
||||
grammarBuilder.append("a : (ID|ATN)* ATN? {fmt.Println($text)} ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("ATN : '0'..'9'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
@ -675,9 +675,9 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testReferenceToATN_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(113);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (ID|ATN)* ATN? {fmt.Println($text);} ;\n");
|
||||
grammarBuilder.append("a : (ID|ATN)* ATN? {fmt.Println($text)} ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("ATN : '0'..'9'+;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip ;");
|
||||
|
|
|
@ -113,11 +113,11 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
public void testIndent() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(154);
|
||||
StringBuilder grammarBuilder = new StringBuilder(153);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("INDENT : [ \\t]+ { this._tokenStartCharPositionInLine==0 }?\n");
|
||||
grammarBuilder.append(" { fmt.Println(\"INDENT\"); } ;\n");
|
||||
grammarBuilder.append(" { fmt.Println(\"INDENT\") } ;\n");
|
||||
grammarBuilder.append("NL : '\\n';\n");
|
||||
grammarBuilder.append("WS : [ \\t]+ ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -150,10 +150,10 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
public void testLexerInputPositionSensitivePredicates() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(264);
|
||||
StringBuilder grammarBuilder = new StringBuilder(262);
|
||||
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("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("WS : (' '|'\\n') -> skip;");
|
||||
|
@ -180,10 +180,10 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
public void testPredicatedKeywords() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(173);
|
||||
StringBuilder grammarBuilder = new StringBuilder(171);
|
||||
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]+ { this.GetText().equals(\"enum\") }? { fmt.Println(\"enum!\") } ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ { fmt.Println(\"ID \" + this.GetText()) } ;\n");
|
||||
grammarBuilder.append("WS : [ \\n] -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="enum enu a";
|
||||
|
|
|
@ -12,12 +12,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void test2UnpredicatedAlts() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(293);
|
||||
StringBuilder grammarBuilder = new StringBuilder(290);
|
||||
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("a : ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append(" | {false}? ID {fmt.Println(\"alt 3\");}\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");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -42,13 +42,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void test2UnpredicatedAltsAndOneOrthogonalAlt() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(345);
|
||||
StringBuilder grammarBuilder = new StringBuilder(341);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : {_interp.SetPredictionMode(PredictionModeLL_EXACT_AMBIG_DETECTION);} 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");
|
||||
grammarBuilder.append(" | {false}? ID {fmt.Println(\"alt 4\");}\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");
|
||||
grammarBuilder.append(" | {false}? ID {fmt.Println(\"alt 4\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -74,12 +74,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testActionHidesPreds() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(225);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {int i = 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");
|
||||
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");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -100,7 +100,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testActionsHidePredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(281);
|
||||
StringBuilder grammarBuilder = new StringBuilder(280);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool pred(bool v) {\n");
|
||||
|
@ -108,7 +108,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : e {} {this.pred(true)}? {fmt.Println(\"parse\");} '!' ;\n");
|
||||
grammarBuilder.append("s : e {} {this.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {} {this.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
|
@ -148,7 +148,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testDepedentPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(304);
|
||||
StringBuilder grammarBuilder = new StringBuilder(303);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool pred(bool v) {\n");
|
||||
|
@ -157,7 +157,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : a[99] ;\n");
|
||||
grammarBuilder.append("a[int i] : e {this.pred($i==99)}? {fmt.Println(\"parse\");} '!' ;\n");
|
||||
grammarBuilder.append("a[int i] : e {this.pred($i==99)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("b[int i] : e {this.pred($i==99)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
|
@ -178,13 +178,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testDependentPredNotInOuterCtxShouldBeIgnored() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(270);
|
||||
StringBuilder grammarBuilder = new StringBuilder(268);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : b[2] ';' | b[2] '.' ; // decision in s drills down to ctx-dependent pred in a;\n");
|
||||
grammarBuilder.append("b[int i] : a[i] ;\n");
|
||||
grammarBuilder.append("a[int i]\n");
|
||||
grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -221,13 +221,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testIndependentPredNotPassedOuterCtxToAvoidCastException() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(183);
|
||||
StringBuilder grammarBuilder = new StringBuilder(181);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : b ';' | b '.' ;\n");
|
||||
grammarBuilder.append("b : a ;\n");
|
||||
grammarBuilder.append("a\n");
|
||||
grammarBuilder.append(" : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append(" : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -245,11 +245,11 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testNoTruePredsThrowsNoViableAlt() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(171);
|
||||
StringBuilder grammarBuilder = new StringBuilder(169);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a a;\n");
|
||||
grammarBuilder.append("a : {false}? ID INT {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {false}? ID INT {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID INT {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {false}? ID INT {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -268,13 +268,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testOrder() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(297);
|
||||
StringBuilder grammarBuilder = new StringBuilder(295);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a {} a; // do 2x: once in ATN, next in DFA;\n");
|
||||
grammarBuilder.append("// action blocks lookahead from falling off of 'a'\n");
|
||||
grammarBuilder.append("// and looking into 2nd 'a' ref. !ctx dependent pred\n");
|
||||
grammarBuilder.append("a : ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -294,10 +294,10 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredFromAltTestedInLoopBack_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(204);
|
||||
StringBuilder grammarBuilder = new StringBuilder(203);
|
||||
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(this))}\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");
|
||||
|
@ -324,10 +324,10 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredFromAltTestedInLoopBack_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(204);
|
||||
StringBuilder grammarBuilder = new StringBuilder(203);
|
||||
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(this))}\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");
|
||||
|
@ -352,12 +352,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(201);
|
||||
StringBuilder grammarBuilder = new StringBuilder(199);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {bool enumKeyword = true;}\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text);}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\");}\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
|
||||
|
@ -374,12 +374,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(201);
|
||||
StringBuilder grammarBuilder = new StringBuilder(199);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {bool enumKeyword = true;}\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text);}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\");}\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
|
||||
|
@ -397,13 +397,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredicateDependentOnArg() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(200);
|
||||
StringBuilder grammarBuilder = new StringBuilder(198);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {int i = 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");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {$i==2}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -447,7 +447,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(275);
|
||||
StringBuilder grammarBuilder = new StringBuilder(274);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool pred(bool v) {\n");
|
||||
|
@ -455,7 +455,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : e {this.pred(true)}? {fmt.Println(\"parse\");} '!' ;\n");
|
||||
grammarBuilder.append("s : e {this.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {this.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
|
@ -476,11 +476,11 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testRewindBeforePredEval() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(239);
|
||||
StringBuilder grammarBuilder = new StringBuilder(237);
|
||||
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 : {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(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -500,12 +500,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testSimple() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(256);
|
||||
StringBuilder grammarBuilder = new StringBuilder(253);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a a a; // do 3x: once in ATN, next in DFA then INT in ATN\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append(" | INT {fmt.Println(\"alt 3\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" | INT {fmt.Println(\"alt 3\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -526,11 +526,11 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testSimpleValidate() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(164);
|
||||
StringBuilder grammarBuilder = new StringBuilder(162);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a ;\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -549,11 +549,11 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testSimpleValidate2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(167);
|
||||
StringBuilder grammarBuilder = new StringBuilder(165);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a a a;\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -574,11 +574,11 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testToLeft() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(164);
|
||||
StringBuilder grammarBuilder = new StringBuilder(162);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append(" s : a+ ;\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -599,13 +599,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testToLeftWithVaryingPredicate() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(250);
|
||||
StringBuilder grammarBuilder = new StringBuilder(247);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {int i = 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");
|
||||
grammarBuilder.append(" | {this.i % 2 != 0}? ID {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("fmt.Println(\"i=\" + this.i)} a)+ ;\n");
|
||||
grammarBuilder.append("a : {this.i % 2 == 0}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {this.i % 2 != 0}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -629,10 +629,10 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testUnpredicatedPathsInAlt() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(183);
|
||||
StringBuilder grammarBuilder = new StringBuilder(181);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | b {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("s : a {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | b {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("a : {false}? ID INT\n");
|
||||
grammarBuilder.append(" | ID INT\n");
|
||||
|
@ -655,14 +655,14 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testValidateInDFA() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(332);
|
||||
StringBuilder grammarBuilder = new StringBuilder(330);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("s : a ';' a;\n");
|
||||
grammarBuilder.append("// ';' helps us to resynchronize without consuming\n");
|
||||
grammarBuilder.append("// 2nd 'a' reference. We our testing that the DFA also\n");
|
||||
grammarBuilder.append("// throws an exception if the validating predicate fails\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\");}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\");}\n");
|
||||
grammarBuilder.append("a : {false}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {true}? INT {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
|
|
@ -12,9 +12,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testCharSetLiteral() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(85);
|
||||
StringBuilder grammarBuilder = new StringBuilder(84);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : (A {fmt.Println($A.text);})+ ;\n");
|
||||
grammarBuilder.append("a : (A {fmt.Println($A.text)})+ ;\n");
|
||||
grammarBuilder.append("A : [AaBb] ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n')+ -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -54,9 +54,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testLexerOptionalSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(77);
|
||||
StringBuilder grammarBuilder = new StringBuilder(76);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(77);
|
||||
StringBuilder grammarBuilder = new StringBuilder(76);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(77);
|
||||
StringBuilder grammarBuilder = new StringBuilder(76);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText())} ;\n");
|
||||
grammarBuilder.append("A : ('a'|'b')* 'c' ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
|
@ -105,9 +105,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testNotChar() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(53);
|
||||
StringBuilder grammarBuilder = new StringBuilder(52);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text);} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text)} ;\n");
|
||||
grammarBuilder.append("A : ~'b' ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
|
@ -122,9 +122,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testNotCharSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(59);
|
||||
StringBuilder grammarBuilder = new StringBuilder(58);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text);} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text)} ;\n");
|
||||
grammarBuilder.append("A : ~('b'|'c') ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
|
@ -139,9 +139,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testNotCharSetWithLabel() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(61);
|
||||
StringBuilder grammarBuilder = new StringBuilder(60);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text);} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text)} ;\n");
|
||||
grammarBuilder.append("A : h=~('b'|'c') ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
|
@ -156,9 +156,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testNotCharSetWithRuleRef3() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(125);
|
||||
StringBuilder grammarBuilder = new StringBuilder(124);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text);} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println($A.text)} ;\n");
|
||||
grammarBuilder.append("A : ('a'|B) ; // this doesn't collapse to set but works\n");
|
||||
grammarBuilder.append("fragment\n");
|
||||
grammarBuilder.append("B : ~('a'|'c') ;");
|
||||
|
@ -175,9 +175,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testOptionalLexerSingleElement() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(69);
|
||||
StringBuilder grammarBuilder = new StringBuilder(68);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ('a'|'b')? 'c' {fmt.Println(this._input.GetText());} ;");
|
||||
grammarBuilder.append("a : ('a'|'b')? 'c' {fmt.Println(this._input.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(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A? 'c' {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A? 'c' {fmt.Println(this._input.GetText())} ;\n");
|
||||
grammarBuilder.append("A : 'b' ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="bc";
|
||||
|
@ -225,9 +225,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testParserNotSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(57);
|
||||
StringBuilder grammarBuilder = new StringBuilder(56);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : t=~('x'|'y') 'z' {fmt.Println($t.text);} ;");
|
||||
grammarBuilder.append("a : t=~('x'|'y') 'z' {fmt.Println($t.text)} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -241,9 +241,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testParserNotToken() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(63);
|
||||
StringBuilder grammarBuilder = new StringBuilder(62);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ~'x' 'z' {fmt.Println(this._input.GetText());} ;");
|
||||
grammarBuilder.append("a : ~'x' 'z' {fmt.Println(this._input.GetText())} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -257,9 +257,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testParserNotTokenWithLabel() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(51);
|
||||
StringBuilder grammarBuilder = new StringBuilder(50);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : t=~'x' 'z' {fmt.Println($t.text);} ;");
|
||||
grammarBuilder.append("a : t=~'x' 'z' {fmt.Println($t.text)} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="zz";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
@ -273,9 +273,9 @@ public class TestSets extends BaseTest {
|
|||
@Test
|
||||
public void testParserSet() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(52);
|
||||
StringBuilder grammarBuilder = new StringBuilder(51);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : t=('x'|'y') {fmt.Println($t.text);} ;");
|
||||
grammarBuilder.append("a : t=('x'|'y') {fmt.Println($t.text)} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="x";
|
||||
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(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(69);
|
||||
StringBuilder grammarBuilder = new StringBuilder(68);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ('a'|'b')+ 'c' {fmt.Println(this._input.GetText());} ;");
|
||||
grammarBuilder.append("a : ('a'|'b')+ 'c' {fmt.Println(this._input.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(76);
|
||||
StringBuilder grammarBuilder = new StringBuilder(75);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a @after {fmt.Println(this._input.GetText());} : 'a' | 'b' |'c' ;");
|
||||
grammarBuilder.append("a @after {fmt.Println(this._input.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(113);
|
||||
StringBuilder grammarBuilder = new StringBuilder(112);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : C {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : C {fmt.Println(this._input.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(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(71);
|
||||
StringBuilder grammarBuilder = new StringBuilder(70);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.GetText());} ;\n");
|
||||
grammarBuilder.append("a : A {fmt.Println(this._input.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(69);
|
||||
StringBuilder grammarBuilder = new StringBuilder(68);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("a : ('a'|'b')* 'c' {fmt.Println(this._input.GetText());} ;");
|
||||
grammarBuilder.append("a : ('a'|'b')* 'c' {fmt.Println(this._input.GetText())} ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input ="abaac";
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package antlr4
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Parser interface {
|
||||
Recognizer
|
||||
|
@ -673,27 +676,23 @@ func (this *BaseParser) getRuleInvocationStack(p ParserRuleContext) []string {
|
|||
}
|
||||
|
||||
// For debugging and other purposes.//
|
||||
func (p *BaseParser) getDFAStrings() {
|
||||
panic("dumpDFA Not implemented!")
|
||||
// return p._interp.decisionToDFA.String()
|
||||
func (p *BaseParser) GetDFAStrings() string {
|
||||
return fmt.Sprint(p.Interpreter.decisionToDFA)
|
||||
}
|
||||
|
||||
// For debugging and other purposes.//
|
||||
func (p *BaseParser) dumpDFA() {
|
||||
panic("dumpDFA Not implemented!")
|
||||
|
||||
// var seenOne = false
|
||||
// for i := 0; i < p._interp.decisionToDFA.length; i++ {
|
||||
// var dfa = p._interp.decisionToDFA[i]
|
||||
// if ( len(dfa.states) > 0) {
|
||||
// if (seenOne) {
|
||||
// fmt.Println()
|
||||
// }
|
||||
// p.printer.println("Decision " + dfa.decision + ":")
|
||||
// p.printer.print(dfa.String(p.LiteralNames, p.SymbolicNames))
|
||||
// seenOne = true
|
||||
// }
|
||||
// }
|
||||
func (p *BaseParser) DumpDFA() {
|
||||
var seenOne = false
|
||||
for _, dfa := range p.Interpreter.decisionToDFA {
|
||||
if ( len(dfa.GetStates()) > 0) {
|
||||
if (seenOne) {
|
||||
fmt.Println()
|
||||
}
|
||||
fmt.Println("Decision " + strconv.Itoa(dfa.decision) + ":")
|
||||
fmt.Print(dfa.String(p.LiteralNames, p.SymbolicNames))
|
||||
seenOne = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *BaseParser) GetSourceName() string {
|
||||
|
|
|
@ -251,7 +251,7 @@ RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,fina
|
|||
|
||||
<altLabelCtxs:{l | <altLabelCtxs.(l)>}; separator="\n">
|
||||
|
||||
func (p *<parser.name>) <currentRule.name; format="cap">(<currentRule.args:{a | <a.name>}; separator=", ">) *<currentRule.ctxType> {
|
||||
func (p *<parser.name>) <currentRule.name; format="cap">(<currentRule.args:{a | <a.name> <a.type>}; separator=", ">) *<currentRule.ctxType> {
|
||||
|
||||
localctx := New<currentRule.ctxType>(p, p.GetParserRuleContext(), p.GetState()<currentRule.args:{a | , <a.name>}>)
|
||||
p.EnterRule(localctx, <currentRule.startState>, <parser.name>RULE_<currentRule.name>)
|
||||
|
@ -295,7 +295,7 @@ LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,
|
|||
<ruleCtx>
|
||||
<altLabelCtxs:{l | <altLabelCtxs.(l)>}; separator="\n">
|
||||
|
||||
func (p *<parser.name>) <currentRule.name; format="cap">(_p int<if(currentRule.args)>, <args:{a | , <a>}><endif>) *<currentRule.ctxType> {
|
||||
func (p *<parser.name>) <currentRule.name; format="cap">(_p int<if(currentRule.args)>, <args:{a | , <a.name> <a.type>}><endif>) *<currentRule.ctxType> {
|
||||
|
||||
_parentctx := p.GetParserRuleContext()
|
||||
_parentState := p.GetState()
|
||||
|
@ -575,8 +575,8 @@ LabelRef(t) ::= "<ctx(t)>.<t.name>"
|
|||
ListLabelRef(t) ::= "<ctx(t)>.<ListLabelName(t.name)>"
|
||||
SetAttr(s,rhsChunks) ::= "<ctx(s)>.<s.name> = <rhsChunks>"
|
||||
|
||||
TokenLabelType() ::= "<file.TokenLabelType; null={Token}>"
|
||||
InputSymbolType() ::= "<file.InputSymbolType; null={Token}>"
|
||||
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())"
|
||||
|
@ -588,26 +588,26 @@ TokenPropertyRef_int(t) ::= "(<ctx(t)>.<t.label> == null ? 0 : strconv.Atoi(<ctx
|
|||
|
||||
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().GetTextFromInterval(antlr4.NewInterval(<ctx(r)>.<r.label>.GetStart(),<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_ctx(r) ::= "<ctx(r)>.<r.label>"
|
||||
RulePropertyRef_parser(r) ::= "p"
|
||||
|
||||
ThisRulePropertyRef_start(r) ::= "localctx.GetStart()"
|
||||
ThisRulePropertyRef_stop(r) ::= "localctx.GetStop()"
|
||||
ThisRulePropertyRef_text(r) ::= "p.GetTokenStream().GetTextFromInterval(antlr4.NewInterval(localctx.GetStart(), p.GetTokenStream().LT(-1)))"
|
||||
ThisRulePropertyRef_text(r) ::= "p.GetTokenStream().GetTextFromInterval(antlr4.NewInterval(localctx.GetStart().GetTokenIndex(), p.GetTokenStream().LT(-1).GetTokenIndex()))"
|
||||
ThisRulePropertyRef_ctx(r) ::= "localctx"
|
||||
ThisRulePropertyRef_parser(r) ::= "p"
|
||||
|
||||
NonLocalAttrRef(s) ::= "GetInvokingContext(<s.ruleIndex>).<s.name>"
|
||||
SetNonLocalAttr(s, rhsChunks) ::= "GetInvokingContext(<s.ruleIndex>).<s.name> = <rhsChunks>"
|
||||
|
||||
AddToLabelList(a) ::= "<ctx(a.label)>.<a.listName> = append(<ctx(a.label)>.<a.listName>, push(<labelref(a.label)>)"
|
||||
AddToLabelList(a) ::= "<ctx(a.label)>.<a.listName> = append(<ctx(a.label)>.<a.listName>, <labelref(a.label)>)"
|
||||
|
||||
TokenDecl(t) ::= "p.<t.name> = nil // <TokenLabelType()>"
|
||||
TokenTypeDecl(t) ::= "<t.name> := 0 // <TokenLabelType()> type"
|
||||
TokenListDecl(t) ::= "p.<t.name> = [] // of <TokenLabelType()>s"
|
||||
RuleContextDecl(r) ::= "p.<r.name> = nil // reflect.TypeOf((*<r.ctxName>)(nil)).Elem()"
|
||||
RuleContextListDecl(rdecl) ::= "p.<rdecl.name> = [] // of <rdecl.ctxName>s"
|
||||
TokenDecl(t) ::= "<t.name> <TokenLabelType()>"
|
||||
TokenTypeDecl(t) ::= "<t.name> int"
|
||||
TokenListDecl(t) ::= "var <t.name> Token[] = make([]<TokenLabelType()>, 0)"
|
||||
RuleContextDecl(r) ::= "<r.name> *<r.ctxName>"
|
||||
RuleContextListDecl(rdecl) ::= "var <rdecl.name> []*<rdecl.ctxName> = make([]*<rdecl.ctxName>, 0)"
|
||||
|
||||
ContextTokenGetterDecl(t) ::= <<
|
||||
<t.name; format="cap">() interface{} {
|
||||
|
@ -629,7 +629,6 @@ ContextTokenListIndexedGetterDecl(t) ::= <<
|
|||
return s.GetToken(<parser.name><t.name>, i)
|
||||
}
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
ContextRuleGetterDecl(r) ::= <<
|
||||
|
@ -677,9 +676,10 @@ type <struct.name> struct {
|
|||
*antlr4.BaseParserRuleContext
|
||||
|
||||
parser antlr4.Parser
|
||||
<attrs:{a | <a>}; separator="\n">
|
||||
}
|
||||
|
||||
func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name>}>) *<struct.name> {
|
||||
func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name> <a.type>}>) *<struct.name> {
|
||||
|
||||
var p = new(<struct.name>)
|
||||
|
||||
|
@ -687,7 +687,6 @@ func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, inv
|
|||
|
||||
p.parser = parser
|
||||
p.RuleIndex = <parser.name>RULE_<struct.derivedFromName>
|
||||
<attrs:{a | <a>}; separator="\n">
|
||||
<struct.ctorAttrs:{a | p.<a.name> = <a.name>}; separator="\n">
|
||||
return p
|
||||
}
|
||||
|
@ -715,6 +714,8 @@ AltLabelStructDecl(struct,attrs,getters,dispatchMethods) ::= <<
|
|||
|
||||
type <struct.name> struct {
|
||||
*<currentRule.name; format="cap">Context
|
||||
|
||||
<attrs:{a | <a>}; separator="\n">
|
||||
}
|
||||
|
||||
func New<struct.name>(parser antlr4.Parser, ctx antlr4.ParserRuleContext) *<struct.name> {
|
||||
|
@ -723,8 +724,6 @@ func New<struct.name>(parser antlr4.Parser, ctx antlr4.ParserRuleContext) *<stru
|
|||
|
||||
p.<currentRule.name; format="cap">Context = new(<currentRule.name; format="cap">Context)
|
||||
|
||||
<attrs:{a | <a>;}; separator="\n">
|
||||
|
||||
p.parser = parser
|
||||
p.CopyFrom(ctx)
|
||||
|
||||
|
@ -743,7 +742,9 @@ func (s *<struct.name>) GetRuleContext() antlr4.RuleContext {
|
|||
|
||||
ListenerDispatchMethod(method) ::= <<
|
||||
func (s *<struct.name>) <if(method.isEnter)>Enter<else>Exit<endif>Rule(listener antlr4.ParseTreeListener) {
|
||||
listener.(<parser.grammarName>Listener).<if(method.isEnter)>Enter<else>Exit<endif><struct.derivedFromName; format="cap">(s)
|
||||
if listenerT, ok := listener.(<parser.grammarName>Listener); ok {
|
||||
listenerT.<if(method.isEnter)>Enter<else>Exit<endif><struct.derivedFromName; format="cap">(s)
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
@ -758,7 +759,7 @@ func (s *<struct.name>) Accept(visitor antlr4.ParseTreeVisitor) interface{} {
|
|||
}
|
||||
>>
|
||||
|
||||
AttributeDecl(d) ::= "p.<d.name> = <if(d.initValue)><d.initValue><else>null<endif>"
|
||||
AttributeDecl(d) ::= "<d.name> <d.type><if(d.initValue)>// TODO = <d.initValue><endif>"
|
||||
|
||||
/** If we don't know location of label def x, use this template */
|
||||
labelref(x) ::= "<if(!x.isLocal)>localctx.<endif><x.name>"
|
||||
|
@ -773,7 +774,7 @@ recRuleSetStopToken() ::= "p.GetParserRuleContext().SetStop( p.G
|
|||
|
||||
recRuleAltStartAction(ruleName, ctxName, label) ::= <<
|
||||
localctx = New<ctxName>Context(p, _parentctx, _parentState)
|
||||
<if(label)>localctx.<label> = _prevctx;<endif>
|
||||
<if(label)>localctx.<label> = _prevctx<endif>
|
||||
p.PushNewRecursionContext(localctx, _startState, <parser.name>RULE_<ruleName>)
|
||||
>>
|
||||
|
||||
|
@ -781,9 +782,9 @@ recRuleLabeledAltStartAction(ruleName, currentAltLabel, label, isListLabel) ::=
|
|||
localctx = New<currentAltLabel; format="cap">Context(p, New<ruleName; format="cap">Context(p, _parentctx, _parentState))
|
||||
<if(label)>
|
||||
<if(isListLabel)>
|
||||
localctx.<label> = append( localctx.<label>, _prevctx))
|
||||
localctx.(*<currentAltLabel; format="cap">Context).<label> = append( localctx.(*<currentAltLabel; format="cap">Context).<label>, _prevctx))
|
||||
<else>
|
||||
localctx.<label> = _prevctx
|
||||
localctx.(*<currentAltLabel; format="cap">Context).<label> = _prevctx
|
||||
<endif>
|
||||
<endif>
|
||||
p.PushNewRecursionContext(localctx, _startState, <parser.name>RULE_<ruleName>)
|
||||
|
|
Loading…
Reference in New Issue