|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.runtime.BaseRecognizer
public abstract class BaseRecognizer
A generic recognizer that can handle recognizers generated from lexer, parser, and tree grammars. This is all the parsing support code essentially; most of it is error recovery stuff and backtracking.
Field Summary | |
---|---|
protected int |
_fsp
|
protected int |
backtracking
If 0, no backtracking is going on. |
static int |
DEFAULT_TOKEN_CHANNEL
|
protected boolean |
errorRecovery
This is true when we see an error and before having successfully matched a token. |
protected boolean |
failed
In lieu of a return value, this indicates that a rule or token has failed to match. |
protected BitSet[] |
following
Track the set of token types that can follow any rule invocation. |
static int |
HIDDEN
|
static int |
INITIAL_FOLLOW_STACK_SIZE
|
protected int |
lastErrorIndex
The index into the input stream where the last error occurred. |
static int |
MEMO_RULE_FAILED
|
static java.lang.Integer |
MEMO_RULE_FAILED_I
|
static int |
MEMO_RULE_UNKNOWN
|
static java.lang.String |
NEXT_TOKEN_RULE_NAME
|
protected java.util.Map[] |
ruleMemo
An array[size num rules] of Map |
Constructor Summary | |
---|---|
BaseRecognizer()
|
Method Summary | |
---|---|
boolean |
alreadyParsedRule(IntStream input,
int ruleIndex)
Has this rule already parsed input at the current index in the input stream? Return the stop token index or MEMO_RULE_UNKNOWN. |
void |
beginResync()
A hook to listen in on the token consumption during error recovery. |
protected BitSet |
combineFollows(boolean exact)
|
protected BitSet |
computeContextSensitiveRuleFOLLOW()
Compute the context-sensitive FOLLOW set for current rule. |
protected BitSet |
computeErrorRecoverySet()
|
void |
consumeUntil(IntStream input,
BitSet set)
Consume tokens until one matches the given token set |
void |
consumeUntil(IntStream input,
int tokenType)
|
void |
displayRecognitionError(java.lang.String[] tokenNames,
RecognitionException e)
|
void |
emitErrorMessage(java.lang.String msg)
Override this method to change where error messages go |
void |
endResync()
|
int |
getBacktrackingLevel()
|
java.lang.String |
getErrorHeader(RecognitionException e)
What is the error header, normally line/character position information? |
java.lang.String |
getErrorMessage(RecognitionException e,
java.lang.String[] tokenNames)
What error message should be generated for the various exception types? Not very object-oriented code, but I like having all error message generation within one method rather than spread among all of the exception classes. |
java.lang.String |
getGrammarFileName()
For debugging and other purposes, might want the grammar name. |
java.util.List |
getRuleInvocationStack()
Return List |
static java.util.List |
getRuleInvocationStack(java.lang.Throwable e,
java.lang.String recognizerClassName)
A more general version of getRuleInvocationStack where you can pass in, for example, a RecognitionException to get it's rule stack trace. |
int |
getRuleMemoization(int ruleIndex,
int ruleStartIndex)
Given a rule number and a start token index number, return MEMO_RULE_UNKNOWN if the rule has not parsed input starting from start index. |
int |
getRuleMemoizationCacheSize()
return how many rule/input-index pairs there are in total. |
java.lang.String |
getTokenErrorDisplay(Token t)
How should a token be displayed in an error message? The default is to display just the text, but during development you might want to have a lot of information spit out. |
java.lang.String[] |
getTokenNames()
Used to print out token names like ID during debugging and error reporting. |
void |
match(IntStream input,
int ttype,
BitSet follow)
Match current input symbol against ttype. |
void |
matchAny(IntStream input)
|
void |
memoize(IntStream input,
int ruleIndex,
int ruleStartIndex)
Record whether or not this rule parsed the input at this position successfully. |
protected void |
mismatch(IntStream input,
int ttype,
BitSet follow)
factor out what to do upon token mismatch so tree parsers can behave differently. |
protected void |
pushFollow(BitSet fset)
Push a rule's follow set using our own hardcoded stack |
void |
recover(IntStream input,
RecognitionException re)
Recover from an error found on the input stream. |
protected boolean |
recoverFromMismatchedElement(IntStream input,
RecognitionException e,
BitSet follow)
This code is factored out from mismatched token and mismatched set recovery. |
void |
recoverFromMismatchedSet(IntStream input,
RecognitionException e,
BitSet follow)
|
void |
recoverFromMismatchedToken(IntStream input,
RecognitionException e,
int ttype,
BitSet follow)
Attempt to recover from a single missing or extra token. |
void |
reportError(RecognitionException e)
Report a recognition problem. |
void |
reset()
reset the parser's state; subclasses must rewinds the input stream |
java.util.List |
toStrings(java.util.List tokens)
A convenience method for use most often with template rewrites. |
void |
traceIn(java.lang.String ruleName,
int ruleIndex,
java.lang.Object inputSymbol)
|
void |
traceOut(java.lang.String ruleName,
int ruleIndex,
java.lang.Object inputSymbol)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MEMO_RULE_FAILED
public static final int MEMO_RULE_UNKNOWN
public static final int INITIAL_FOLLOW_STACK_SIZE
public static final java.lang.Integer MEMO_RULE_FAILED_I
public static final int DEFAULT_TOKEN_CHANNEL
public static final int HIDDEN
public static final java.lang.String NEXT_TOKEN_RULE_NAME
protected BitSet[] following
protected int _fsp
protected boolean errorRecovery
protected int lastErrorIndex
protected boolean failed
protected int backtracking
protected java.util.Map[] ruleMemo
Constructor Detail |
---|
public BaseRecognizer()
Method Detail |
---|
public void reset()
public void match(IntStream input, int ttype, BitSet follow) throws RecognitionException
RecognitionException
public void matchAny(IntStream input)
protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException
RecognitionException
public void reportError(RecognitionException e)
public void displayRecognitionError(java.lang.String[] tokenNames, RecognitionException e)
public java.lang.String getErrorMessage(RecognitionException e, java.lang.String[] tokenNames)
public java.lang.String getErrorHeader(RecognitionException e)
public java.lang.String getTokenErrorDisplay(Token t)
public void emitErrorMessage(java.lang.String msg)
public void recover(IntStream input, RecognitionException re)
public void beginResync()
public void endResync()
protected BitSet computeErrorRecoverySet()
protected BitSet computeContextSensitiveRuleFOLLOW()
protected BitSet combineFollows(boolean exact)
public void recoverFromMismatchedToken(IntStream input, RecognitionException e, int ttype, BitSet follow) throws RecognitionException
RecognitionException
public void recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException
RecognitionException
protected boolean recoverFromMismatchedElement(IntStream input, RecognitionException e, BitSet follow)
public void consumeUntil(IntStream input, int tokenType)
public void consumeUntil(IntStream input, BitSet set)
protected void pushFollow(BitSet fset)
public java.util.List getRuleInvocationStack()
public static java.util.List getRuleInvocationStack(java.lang.Throwable e, java.lang.String recognizerClassName)
public int getBacktrackingLevel()
public java.lang.String[] getTokenNames()
public java.lang.String getGrammarFileName()
public java.util.List toStrings(java.util.List tokens)
public int getRuleMemoization(int ruleIndex, int ruleStartIndex)
public boolean alreadyParsedRule(IntStream input, int ruleIndex)
public void memoize(IntStream input, int ruleIndex, int ruleStartIndex)
public int getRuleMemoizationCacheSize()
public void traceIn(java.lang.String ruleName, int ruleIndex, java.lang.Object inputSymbol)
public void traceOut(java.lang.String ruleName, int ruleIndex, java.lang.Object inputSymbol)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |