
org.antlr.v4.tool.templates.codegen.Java.Java.stg Maven / Gradle / Ivy
/*
* Copyright (c) 2012 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD-3-Clause license that
* can be found in the LICENSE.txt file in the project root.
*/
javaTypeInitMap ::= [
"int":"0",
"long":"0",
"float":"0.0f",
"double":"0.0",
"boolean":"false",
"byte":"0",
"short":"0",
"char":"0",
default:"null" // anything other than a primitive type is an object
]
// args must be ,
ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
package ;
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;
>>
ListenerFile(file, header, namedActions) ::= <<
package ;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link }.
*/
public interface Listener extends ParseTreeListener {
* Enter a parse tree produced by the {@code \}
* labeled alternative in {@link #\}.
* Enter a parse tree produced by {@link #\}.
* @param ctx the parse tree
*/
void enter(@NotNull .Context ctx);
/**
* Exit a parse tree produced by the {@code \}
* labeled alternative in {@link #\}.
* Exit a parse tree produced by {@link #\}.
* @param ctx the parse tree
*/
void exit(@NotNull .Context ctx);}; separator="\n">
}
>>
BaseListenerFile(file, header, namedActions) ::= <<
package ;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link Listener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class BaseListener implements Listener {
The default implementation does nothing.\
*/
@Override public void enter(@NotNull .Context ctx) { \}
/**
* {@inheritDoc\}
*
* \The default implementation does nothing.\
*/
@Override public void exit(@NotNull .Context ctx) { \}}; separator="\n">
/**
* {@inheritDoc\}
*
* \The default implementation does nothing.\
*/
@Override public void enterEveryRule(@NotNull ParserRuleContext ctx) { }
/**
* {@inheritDoc\}
*
* \The default implementation does nothing.\
*/
@Override public void exitEveryRule(@NotNull ParserRuleContext ctx) { }
/**
* {@inheritDoc\}
*
* \The default implementation does nothing.\
*/
@Override public void visitTerminal(@NotNull TerminalNode node) { }
/**
* {@inheritDoc\}
*
* \The default implementation does nothing.\
*/
@Override public void visitErrorNode(@NotNull ErrorNode node) { }
}
>>
VisitorFile(file, header, namedActions) ::= <<
package ;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
/**
* This interface defines a complete generic visitor for a parse tree produced
* by {@link }.
*
* @param \ The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public interface Visitor\ extends ParseTreeVisitor\ {
* Visit a parse tree produced by the {@code \}
* labeled alternative in {@link #\}.
* Visit a parse tree produced by {@link #\}.
* @param ctx the parse tree
* @return the visitor result
*/
Result visit(@NotNull .Context ctx);}; separator="\n">
}
>>
BaseVisitorFile(file, header, namedActions) ::= <<
package ;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
/**
* This class provides an empty implementation of {@link Visitor},
* which can be extended to create a visitor which only needs to handle a subset
* of the available methods.
*
* @param \ The return type of the visit operation. Use {@link Void} for
* operations with no return type.
*/
public class BaseVisitor\ extends AbstractParseTreeVisitor\ implements Visitor\ {
The default implementation returns the result of calling
* {@link #visitChildren\} on {@code ctx\}.\
*/
@Override public Result visit(@NotNull .Context ctx) { return visitChildren(ctx); \}}; separator="\n">
}
>>
fileHeader(grammarFileName, ANTLRVersion) ::= <<
// Generated from by ANTLR
>>
Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
>>
Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= <<
public abstract class extends {
public static final int
=}; separator=", ", wrap, anchor>;
public static final int
= }; separator=", ", wrap, anchor>;
private static String[] makeRuleNames() {
return new String[] {
"}; separator=", ", wrap, anchor>
};
}
public static final String[] ruleNames = makeRuleNames();
@Override
public String getGrammarFileName() { return ""; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@NotNull
private FailedPredicateException createFailedPredicateException() {
return createFailedPredicateException(null);
}
@NotNull
private FailedPredicateException createFailedPredicateException(@Nullable String predicate) {
return createFailedPredicateException(predicate, null);
}
@NotNull
protected FailedPredicateException createFailedPredicateException(@Nullable String predicate, @Nullable String message) {
return new FailedPredicateException(this, predicate, message);
}
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
:
return _sempred(()_localctx, predIndex);}; separator="\n">
}
return true;
}
}
>>
vocabulary(literalNames, symbolicNames) ::= <<
private static String[] makeLiteralNames() {
return new String[] {
}; null="null", separator=", ", wrap, anchor>
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
}; null="null", separator=", ", wrap, anchor>
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
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] = "\";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
@NotNull
public Vocabulary getVocabulary() {
return VOCABULARY;
}
>>
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
@Override
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
switch (ruleIndex) {
:
_action(()_localctx, actionIndex);
break;}; separator="\n">
}
}
@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
:
return _sempred(()_localctx, predIndex);}; separator="\n">
}
return true;
}
>>
parser_ctor(p) ::= <<
public (TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN);
}
>>
/* This generates a private method since the actionIndex is generated, making an
* overriding implementation impossible to maintain.
*/
RuleActionFunction(r, actions) ::= <<
private void _action( _localctx, int actionIndex) {
switch (actionIndex) {
:
break;}; separator="\n">
}
}
>>
/* This generates a private method since the predIndex is generated, making an
* overriding implementation impossible to maintain.
*/
RuleSempredFunction(r, actions) ::= <<
private boolean _sempred( _localctx, int predIndex) {
switch (predIndex) {
:
return ;}; separator="\n">
}
return true;
}
>>
RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,finallyAction,postamble,exceptions) ::= <<
}; separator="\n">
@RuleVersion()
}>public final () throws RecognitionException {
_localctx = new (_ctx, getState()}>);
enterRule(_localctx, , RULE_);
try {
int _alt;
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
>>
LeftFactoredRuleFunction(currentRule,args,code,locals,namedActions,finallyAction,postamble) ::=
<<
}>private final () throws RecognitionException {
_localctx = new (_ctx, getState()}>);
enterLeftFactoredRule(_localctx, , RULE_);
try {
int _alt;
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
>>
// This behaves similar to RuleFunction (enterRule is called, and no adjustments
// are made to the parse tree), but since it's still a variant no context class
// needs to be generated.
LeftUnfactoredRuleFunction(currentRule,args,code,locals,namedActions,finallyAction,postamble) ::=
<<
}>private final () throws RecognitionException {
_localctx = new (_ctx, getState()}>);
enterRule(_localctx, , RULE_);
try {
int _alt;
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
>>
LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,
namedActions,finallyAction,postamble) ::=
<<
}; separator="\n">
@RuleVersion()
}>public final () throws RecognitionException {
return (0}>);
}
private (int _p}>) throws RecognitionException {
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
_localctx = new (_ctx, _parentState}>);
_prevctx = _localctx;
int _startState = ;
enterRecursionRule(_localctx, , RULE_, _p);
try {
int _alt;
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
unrollRecursionContexts(_parentctx);
}
return _localctx;
}
>>
CodeBlockForOuterMostAlt(currentOuterMostAltCodeBlock, locals, preamble, ops) ::= <<
_localctx = new Context(_localctx);
enterOuterAlt(_localctx, );
>>
CodeBlockForAlt(currentAltCodeBlock, locals, preamble, ops) ::= <<
{
}
>>
LL1AltBlock(choice, preamble, alts, error) ::= <<
setState(