forked from jasder/antlr
Updated Parser documentation
This commit is contained in:
parent
f12de7dfa7
commit
a087ed17ee
|
@ -348,10 +348,8 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get number of recognition errors (lexer, parser). Each recognizer tracks
|
* Gets the number of syntax errors reported during parsing. This value is
|
||||||
* its own number. So parser and lexer each have separate count. Does not
|
* incremented each time {@link #notifyErrorListeners} is called.
|
||||||
* count the spurious errors found between an error and next valid token
|
|
||||||
* match
|
|
||||||
*
|
*
|
||||||
* @see #notifyErrorListeners
|
* @see #notifyErrorListeners
|
||||||
*/
|
*/
|
||||||
|
@ -391,7 +389,7 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
return _input;
|
return _input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the token stream and reset the parser */
|
/** Set the token stream and reset the parser. */
|
||||||
public void setTokenStream(TokenStream input) {
|
public void setTokenStream(TokenStream input) {
|
||||||
this._input = null;
|
this._input = null;
|
||||||
reset();
|
reset();
|
||||||
|
@ -422,18 +420,26 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
listener.syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
listener.syntaxError(this, offendingToken, line, charPositionInLine, msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Consume the current symbol and return it. E.g., given the following
|
/**
|
||||||
* input with A being the current lookahead symbol:
|
* Consume and return the {@linkplain #getCurrentToken current symbol}.
|
||||||
|
* <p/>
|
||||||
|
* E.g., given the following input with {@code A} being the current
|
||||||
|
* lookahead symbol, this function moves the cursor to {@code B} and returns
|
||||||
|
* {@code A}.
|
||||||
*
|
*
|
||||||
* A B
|
* <pre>
|
||||||
* ^
|
* A B
|
||||||
|
* ^
|
||||||
|
* </pre>
|
||||||
*
|
*
|
||||||
* this function moves the cursor to B and returns A.
|
* If the parser is not in error recovery mode, the consumed symbol is added
|
||||||
*
|
* to the parse tree using {@link ParserRuleContext#addChild(Token)}, and
|
||||||
* If the parser is creating parse trees, the current symbol
|
* {@link ParseTreeListener#visitTerminal} is called on any parse listeners.
|
||||||
* would also be added as a child to the current context (node).
|
* If the parser <em>is</em> in error recovery mode, the consumed symbol is
|
||||||
*
|
* added to the parse tree using
|
||||||
* Trigger listener events if there's a listener.
|
* {@link ParserRuleContext#addErrorNode(Token)}, and
|
||||||
|
* {@link ParseTreeListener#visitErrorNode} is called on any parse
|
||||||
|
* listeners.
|
||||||
*/
|
*/
|
||||||
public Token consume() {
|
public Token consume() {
|
||||||
Token o = getCurrentToken();
|
Token o = getCurrentToken();
|
||||||
|
@ -470,12 +476,9 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Always called by generated parsers upon entry to a rule.
|
/**
|
||||||
* This occurs after the new context has been pushed. Access field
|
* Always called by generated parsers upon entry to a rule. Access field
|
||||||
* _ctx get the current context.
|
* {@link #_ctx} get the current context.
|
||||||
*
|
|
||||||
* This is flexible because users do not have to regenerate parsers
|
|
||||||
* to get trace facilities.
|
|
||||||
*/
|
*/
|
||||||
public void enterRule(@NotNull ParserRuleContext localctx, int state, int ruleIndex) {
|
public void enterRule(@NotNull ParserRuleContext localctx, int state, int ruleIndex) {
|
||||||
setState(state);
|
setState(state);
|
||||||
|
@ -515,7 +518,9 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* like enterRule but for recursive rules */
|
/**
|
||||||
|
* Like {@link #enterRule} but for recursive rules.
|
||||||
|
*/
|
||||||
public void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex) {
|
public void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex) {
|
||||||
ParserRuleContext previous = _ctx;
|
ParserRuleContext previous = _ctx;
|
||||||
previous.parent = localctx;
|
previous.parent = localctx;
|
||||||
|
@ -575,6 +580,20 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether or not {@code symbol} can follow the current state in the
|
||||||
|
* ATN. The behavior of this method is equivalent to the following, but is
|
||||||
|
* implemented such that the complete context-sensitive follow set does not
|
||||||
|
* need to be explicitly constructed.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* return getExpectedTokens().contains(symbol);
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param symbol the symbol type to check
|
||||||
|
* @return {@code true} if {@code symbol} can follow the current state in
|
||||||
|
* the ATN, otherwise {@code false}.
|
||||||
|
*/
|
||||||
public boolean isExpectedToken(int symbol) {
|
public boolean isExpectedToken(int symbol) {
|
||||||
// return getInterpreter().atn.nextTokens(_ctx);
|
// return getInterpreter().atn.nextTokens(_ctx);
|
||||||
ATN atn = getInterpreter().atn;
|
ATN atn = getInterpreter().atn;
|
||||||
|
@ -636,7 +655,7 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
|
|
||||||
public ParserRuleContext getRuleContext() { return _ctx; }
|
public ParserRuleContext getRuleContext() { return _ctx; }
|
||||||
|
|
||||||
/** Return List<String> of the rule names in your parser instance
|
/** Return List<String> of the rule names in your parser instance
|
||||||
* leading up to a call to the current rule. You could override if
|
* leading up to a call to the current rule. You could override if
|
||||||
* you want more details such as the file/line info of where
|
* you want more details such as the file/line info of where
|
||||||
* in the ATN a rule is invoked.
|
* in the ATN a rule is invoked.
|
||||||
|
@ -660,7 +679,7 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For debugging and other purposes */
|
/** For debugging and other purposes. */
|
||||||
public List<String> getDFAStrings() {
|
public List<String> getDFAStrings() {
|
||||||
synchronized (_interp.decisionToDFA) {
|
synchronized (_interp.decisionToDFA) {
|
||||||
List<String> s = new ArrayList<String>();
|
List<String> s = new ArrayList<String>();
|
||||||
|
@ -672,7 +691,7 @@ public abstract class Parser extends Recognizer<Token, ParserATNSimulator> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For debugging and other purposes */
|
/** For debugging and other purposes. */
|
||||||
public void dumpDFA() {
|
public void dumpDFA() {
|
||||||
synchronized (_interp.decisionToDFA) {
|
synchronized (_interp.decisionToDFA) {
|
||||||
boolean seenOne = false;
|
boolean seenOne = false;
|
||||||
|
|
Loading…
Reference in New Issue