
org.antlr.v4.test.runtime.java.Java.test.stg Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of antlr4-runtime-testsuite Show documentation
Show all versions of antlr4-runtime-testsuite Show documentation
A collection of tests for ANTLR 4 Runtime libraries.
TestFile(file) ::= <<
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
package org.antlr.v4.test.runtime.java;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
import org.antlr.v4.tool.Grammar;
public class Test extends BaseTest {
}; separator="\n", wrap, anchor>
}<\n>
>>
LexerTestMethod(test) ::= <<
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
public void test() throws Exception {
mkdir(tmpdir);
=;
writeFile(tmpdir, ".g4", slave_);
}; separator="\n">
String input =;
String found = execLexer(".g4", grammar, "Lexer", input, );
assertEquals(, found);
assertEquals(, this.stderrDuringParse);
assertNull(this.stderrDuringParse);
}>
}
>>
CompositeLexerTestMethod(test) ::= <<
>>
ParserTestMethod(test) ::= <<
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
public void test() throws Exception {
mkdir(tmpdir);
=;
rawGenerateAndBuildRecognizer(".g4", slave_, null, "");
writeFile(tmpdir, ".g4", slave_);
}; separator="\n">
String input =;
String found = execParser(".g4", grammar, "Parser", "Lexer", "", input, );
assertEquals(, found);
assertEquals(, this.stderrDuringParse);
assertNull(this.stderrDuringParse);
}>
}
>>
CompositeParserTestMethod(test) ::= <<
>>
AbstractParserTestMethod(test) ::= <<
String test(String input) throws Exception {
String grammar = };separator="\\n\" +\n", wrap, anchor>";
return execParser(".g4", grammar, "Parser", "Lexer", "", input, );
}
>>
ConcreteParserTestMethod(test) ::= <<
public void test() throws Exception {
String found = test("");
assertEquals("", found);
assertEquals("", this.stderrDuringParse);
assertNull(this.stderrDuringParse);
}
>>
testAnnotations(test) ::= <%
@Test
(timeout = )
<\n>@Ignore()
.})))>
<\n>@Ignore(.})))>)
%>
buildStringLiteral(text, variable) ::= <<
StringBuilder Builder = new StringBuilder();
Builder.append("");}; separator="\n">
String = Builder.toString();
>>
writeStringLiteral(text) ::= <%
""
%>
writeLines(textLines) ::= <%
"}; separator="\" +">"
""
%>
string(text) ::= <<
""
>>
writeBoolean(o) ::= "truefalse"
writeln(s) ::= <);>>
write(s) ::= <);>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!"
Assert(s) ::= <);>>
Cast(t,v) ::= "(())"
Append(a,b) ::= " + "
Concat(a,b) ::= ""
DeclareLocal(s,v) ::= "Object = ;"
AssertIsList(v) ::= "List\> __ttt__ = ;" // just use static type system
AssignLocal(s,v) ::= " = ;"
InitIntMember(n,v) ::= <%int = ;%>
InitBooleanMember(n,v) ::= <%boolean = ;%>
GetMember(n) ::= <%this.%>
SetMember(n,v) ::= <%this. = ;%>
AddMember(n,v) ::= <%this. += ;%>
PlusMember(v,n) ::= <% + this.%>
MemberEquals(n,v) ::= <%this. == %>
ModMemberEquals(n,m,v) ::= <%this. % == %>
ModMemberNotEquals(n,m,v) ::= <%this. % != %>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "List\"
BuildParseTrees() ::= "setBuildParseTree(true);"
BailErrorStrategy() ::= <%setErrorHandler(new BailErrorStrategy());%>
ToStringTree(s) ::= <%.toStringTree(this)%>
Column() ::= "this.getCharPositionInLine()"
Text() ::= "this.getText()"
ValEquals(a,b) ::= <%==%>
TextEquals(a) ::= <%this.getText().equals("")%>
PlusText(a) ::= <%"" + this.getText()%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT().getText().equals()%>
LANotEquals(i, v) ::= <%this._input.LA()!=%>
TokenStartColumnEquals(i) ::= <%this._tokenStartCharPositionInLine==%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.tokenNames)"
RuleInvocationStack() ::= "getRuleInvocationStack()"
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>>
ParserPropertyMember() ::= <<
@members {
boolean Property() {
return true;
}
}
>>
PositionAdjustingLexer() ::= <<
@Override
public Token nextToken() {
if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {
_interp = new PositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
return super.nextToken();
}
@Override
public Token emit() {
switch (_type) {
case TOKENS:
handleAcceptPositionForKeyword("tokens");
break;
case LABEL:
handleAcceptPositionForIdentifier();
break;
default:
break;
}
return super.emit();
}
private boolean handleAcceptPositionForIdentifier() {
String tokenText = getText();
int identifierLength = 0;
while (identifierLength \< tokenText.length() && isIdentifierChar(tokenText.charAt(identifierLength))) {
identifierLength++;
}
if (getInputStream().index() > _tokenStartCharIndex + identifierLength) {
int offset = identifierLength - 1;
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
private boolean handleAcceptPositionForKeyword(String keyword) {
if (getInputStream().index() > _tokenStartCharIndex + keyword.length()) {
int offset = keyword.length() - 1;
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
@Override
public PositionAdjustingLexerATNSimulator getInterpreter() {
return (PositionAdjustingLexerATNSimulator)super.getInterpreter();
}
private static boolean isIdentifierChar(char c) {
return Character.isLetterOrDigit(c) || c == '_';
}
protected static class PositionAdjustingLexerATNSimulator extends LexerATNSimulator {
public PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache)
{
super(recog, atn, decisionToDFA, sharedContextCache);
}
protected void resetAcceptPosition(CharStream input, int index, int line, int charPositionInLine) {
input.seek(index);
this.line = line;
this.charPositionInLine = charPositionInLine;
consume(input);
}
}
>>
BasicListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void visitTerminal(TerminalNode node) {
System.out.println(node.getSymbol().getText());
}
}
>>
WalkListener(s) ::= <<
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new LeafListener(), );
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
public static class MyRuleNode extends ParserRuleContext {
public int altNum;
public MyRuleNode(ParserRuleContext parent, int invokingStateNumber) {
super(parent, invokingStateNumber);
}
@Override public int getAltNumber() { return altNum; }
@Override public void setAltNumber(int altNum) { this.altNum = altNum; }
}
}
>>
TokenGetterListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void exitA(TParser.AContext ctx) {
if (ctx.getChildCount()==2)
System.out.printf("%s %s %s",ctx.INT(0).getSymbol().getText(),
ctx.INT(1).getSymbol().getText(),ctx.INT());
else
System.out.println(ctx.ID().getSymbol());
}
}
>>
RuleGetterListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void exitA(TParser.AContext ctx) {
if (ctx.getChildCount()==2) {
System.out.printf("%s %s %s",ctx.b(0).start.getText(),
ctx.b(1).start.getText(),ctx.b().get(0).start.getText());
} else
System.out.println(ctx.b(0).start.getText());
}
}
>>
LRListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void exitE(TParser.EContext ctx) {
if (ctx.getChildCount()==3) {
System.out.printf("%s %s %s\n",ctx.e(0).start.getText(),
ctx.e(1).start.getText(), ctx.e().get(0).start.getText());
} else
System.out.println(ctx.INT().getSymbol().getText());
}
}
>>
LRWithLabelsListener(X) ::= <<
public static class LeafListener extends TBaseListener {
public void exitCall(TParser.CallContext ctx) {
System.out.printf("%s %s",ctx.e().start.getText(),ctx.eList());
}
public void exitInt(TParser.IntContext ctx) {
System.out.println(ctx.INT().getSymbol().getText());
}
}
>>
DeclareContextListGettersFunction() ::= <<
void foo() {
SContext s = null;
List\ extends AContext> a = s.a();
List\ extends BContext> b = s.b();
}
>>
Declare_foo() ::= <<
public void foo() {System.out.println("foo");}
>>
Invoke_foo() ::= "foo();"
Declare_pred() ::= <>
Invoke_pred(v) ::= <)>>
IgnoredTests ::= [
default: false
]
isEmpty ::= [
"": true,
default: false
]
© 2015 - 2025 Weber Informatics LLC | Privacy Policy