public abstract class Parser extends Recognizer<Token,ParserATNSimulator>
Modifier and Type | Class and Description |
---|---|
class |
Parser.TraceListener |
static class |
Parser.TrimToSizeListener |
Modifier and Type | Field and Description |
---|---|
protected boolean |
_buildParseTrees |
protected ParserRuleContext |
_ctx
The RuleContext object for the currently executing rule.
|
protected ANTLRErrorStrategy |
_errHandler |
protected TokenStream |
_input |
protected List<ParseTreeListener> |
_parseListeners
If the listener is non-null, trigger enter and exit rule events
*during* the parse.
|
protected int |
_syntaxErrors
Did the recognizer encounter a syntax error? Track how many.
|
protected Parser.TraceListener |
_tracer |
_interp, EOF
Constructor and Description |
---|
Parser(TokenStream input) |
Modifier and Type | Method and Description |
---|---|
protected void |
addContextToParseTree() |
void |
addParseListener(ParseTreeListener listener)
Provide a listener that gets notified about token matches,
and rule entry/exit events DURING the parse.
|
Token |
consume()
Consume the current symbol and return it.
|
void |
dumpDFA()
For debugging and other purposes
|
void |
enterOuterAlt(ParserRuleContext localctx,
int altNum) |
void |
enterRecursionRule(ParserRuleContext localctx,
int ruleIndex) |
void |
enterRule(ParserRuleContext localctx,
int state,
int ruleIndex)
Always called by generated parsers upon entry to a rule.
|
void |
exitRule() |
boolean |
getBuildParseTree() |
ParserRuleContext |
getContext() |
Token |
getCurrentToken()
Match needs to return the current input symbol, which gets put
into the label for the associated token ref; e.g., x=ID.
|
List<String> |
getDFAStrings()
For debugging and other purposes
|
ANTLRErrorStrategy |
getErrorHandler() |
IntervalSet |
getExpectedTokens()
Compute the set of valid tokens reachable from the current
position in the parse.
|
IntervalSet |
getExpectedTokensWithinCurrentRule() |
TokenStream |
getInputStream() |
ParserRuleContext |
getInvokingContext(int ruleIndex) |
int |
getNumberOfSyntaxErrors()
Get number of recognition errors (lexer, parser, tree parser).
|
List<ParseTreeListener> |
getParseListeners() |
ParserRuleContext |
getRuleContext() |
List<String> |
getRuleInvocationStack()
Return List
|
List<String> |
getRuleInvocationStack(RuleContext p) |
String |
getSourceName() |
TokenStream |
getTokenStream() |
boolean |
getTrimParseTree() |
boolean |
inContext(String context) |
boolean |
isExpectedToken(int symbol) |
Token |
match(int ttype)
Match current input symbol against ttype.
|
Token |
matchWildcard() |
void |
notifyErrorListeners(String msg) |
void |
notifyErrorListeners(Token offendingToken,
String msg,
RecognitionException e) |
void |
pushNewRecursionContext(ParserRuleContext localctx,
int state,
int ruleIndex) |
void |
removeParseListener(ParseTreeListener l) |
void |
removeParseListeners() |
void |
reset()
reset the parser's state
|
void |
setBuildParseTree(boolean buildParseTrees)
Track the RuleContext objects during the parse and hook them up
using the children list so that it forms a parse tree.
|
void |
setErrorHandler(ANTLRErrorStrategy handler) |
void |
setInputStream(IntStream input) |
void |
setTokenFactory(TokenFactory<?> factory)
Tell our token source and error strategy about a new way to create tokens
|
void |
setTokenStream(TokenStream input)
Set the token stream and reset the parser
|
void |
setTrace(boolean trace)
During a parse is sometimes useful to listen in on the rule entry and exit
events as well as token matches.
|
void |
setTrimParseTree(boolean trimParseTrees)
Trim the internal lists of the parse tree during parsing to conserve memory.
|
List<String> |
toStrings(List<? extends Token> tokens)
A convenience method for use most often with template rewrites.
|
void |
triggerEnterRuleEvent()
Notify any parse listeners (implemented as ParseTreeListener's)
of an enter rule event.
|
void |
triggerExitRuleEvent()
Notify any parse listeners (implemented as ParseTreeListener's)
of an exit rule event.
|
void |
unrollRecursionContexts(ParserRuleContext _parentctx) |
action, addErrorListener, getATN, getErrorHeader, getErrorListenerDispatch, getErrorListeners, getGrammarFileName, getInterpreter, getRuleNames, getState, getTokenErrorDisplay, getTokenNames, removeErrorListener, removeErrorListeners, sempred, setInterpreter, setState
protected ANTLRErrorStrategy _errHandler
protected TokenStream _input
protected ParserRuleContext _ctx
protected boolean _buildParseTrees
protected Parser.TraceListener _tracer
protected List<ParseTreeListener> _parseListeners
ParseTreeWalker
protected int _syntaxErrors
public Parser(TokenStream input)
public void reset()
public Token match(int ttype) throws RecognitionException
RecognitionException
public Token matchWildcard() throws RecognitionException
RecognitionException
public void setBuildParseTree(boolean buildParseTrees)
public boolean getBuildParseTree()
public void setTrimParseTree(boolean trimParseTrees)
false
by default for a newly constructed parser.trimParseTrees
- true
to trim the capacity of the ParserRuleContext.children
list to its size after a rule is parsed.public boolean getTrimParseTree()
true
if the ParserRuleContext.children
list is trimmed
using the default Parser.TrimToSizeListener
during the parse process.public List<ParseTreeListener> getParseListeners()
public void addParseListener(ParseTreeListener listener)
public void removeParseListener(ParseTreeListener l)
public void removeParseListeners()
public void triggerEnterRuleEvent()
public void triggerExitRuleEvent()
public int getNumberOfSyntaxErrors()
public void setTokenFactory(TokenFactory<?> factory)
setTokenFactory
in class Recognizer<Token,ParserATNSimulator>
public ANTLRErrorStrategy getErrorHandler()
public void setErrorHandler(ANTLRErrorStrategy handler)
public TokenStream getInputStream()
getInputStream
in class Recognizer<Token,ParserATNSimulator>
public final void setInputStream(IntStream input)
setInputStream
in class Recognizer<Token,ParserATNSimulator>
public TokenStream getTokenStream()
public void setTokenStream(TokenStream input)
public Token getCurrentToken()
public void notifyErrorListeners(String msg)
public void notifyErrorListeners(Token offendingToken, String msg, @Nullable RecognitionException e)
public Token consume()
protected void addContextToParseTree()
public void enterRule(ParserRuleContext localctx, int state, int ruleIndex)
public void exitRule()
public void enterOuterAlt(ParserRuleContext localctx, int altNum)
public void enterRecursionRule(ParserRuleContext localctx, int ruleIndex)
public void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex)
public void unrollRecursionContexts(ParserRuleContext _parentctx)
public ParserRuleContext getInvokingContext(int ruleIndex)
public ParserRuleContext getContext()
public boolean inContext(String context)
public boolean isExpectedToken(int symbol)
public IntervalSet getExpectedTokens()
public IntervalSet getExpectedTokensWithinCurrentRule()
public ParserRuleContext getRuleContext()
public List<String> getRuleInvocationStack()
public List<String> getRuleInvocationStack(RuleContext p)
public void dumpDFA()
public String getSourceName()
public List<String> toStrings(List<? extends Token> tokens)
public void setTrace(boolean trace)
Copyright © 1992-2013 ANTLR. All Rights Reserved.