public abstract class BaseRecognizer extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TOKEN_CHANNEL |
static int |
HIDDEN |
static int |
INITIAL_FOLLOW_STACK_SIZE |
static int |
MEMO_RULE_FAILED |
static int |
MEMO_RULE_UNKNOWN |
static String |
NEXT_TOKEN_RULE_NAME |
protected RecognizerSharedState |
state
State of a lexer, parser, or tree parser are collected into a state
object so the state can be shared.
|
Constructor and Description |
---|
BaseRecognizer() |
BaseRecognizer(RecognizerSharedState state) |
Modifier and Type | Method and Description |
---|---|
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(String[] tokenNames,
RecognitionException e) |
void |
emitErrorMessage(String msg)
Override this method to change where error messages go
|
void |
endResync() |
boolean |
failed()
Return whether or not a backtracking attempt failed.
|
int |
getBacktrackingLevel() |
protected Object |
getCurrentInputSymbol(IntStream input)
Match needs to return the current input symbol, which gets put
into the label for the associated token ref; e.g., x=ID.
|
String |
getErrorHeader(RecognitionException e)
What is the error header, normally line/character position information?
|
String |
getErrorMessage(RecognitionException e,
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.
|
String |
getGrammarFileName()
For debugging and other purposes, might want the grammar name.
|
protected Object |
getMissingSymbol(IntStream input,
RecognitionException e,
int expectedTokenType,
BitSet follow)
Conjure up a missing token during error recovery.
|
int |
getNumberOfSyntaxErrors()
Get number of recognition errors (lexer, parser, tree parser).
|
List<String> |
getRuleInvocationStack()
Return List<String> of the rules in your parser instance
leading up to a call to this method.
|
static List<String> |
getRuleInvocationStack(Throwable e,
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.
|
abstract String |
getSourceName() |
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.
|
String[] |
getTokenNames()
Used to print out token names like ID during debugging and
error reporting.
|
Object |
match(IntStream input,
int ttype,
BitSet follow)
Match current input symbol against ttype.
|
void |
matchAny(IntStream input)
Match the wildcard: in a symbol
|
void |
memoize(IntStream input,
int ruleIndex,
int ruleStartIndex)
Record whether or not this rule parsed the input at this position
successfully.
|
boolean |
mismatchIsMissingToken(IntStream input,
BitSet follow) |
boolean |
mismatchIsUnwantedToken(IntStream input,
int ttype) |
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.
|
Object |
recoverFromMismatchedSet(IntStream input,
RecognitionException e,
BitSet follow)
Not currently used
|
protected Object |
recoverFromMismatchedToken(IntStream input,
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
|
void |
setBacktrackingLevel(int n) |
List<String> |
toStrings(List<? extends Token> tokens)
A convenience method for use most often with template rewrites.
|
void |
traceIn(String ruleName,
int ruleIndex,
Object inputSymbol) |
void |
traceOut(String ruleName,
int ruleIndex,
Object inputSymbol) |
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 int DEFAULT_TOKEN_CHANNEL
public static final int HIDDEN
public static final String NEXT_TOKEN_RULE_NAME
protected RecognizerSharedState state
public BaseRecognizer()
public BaseRecognizer(RecognizerSharedState state)
public void reset()
public Object match(IntStream input, int ttype, BitSet follow) throws RecognitionException
RecognitionException
public void matchAny(IntStream input)
public boolean mismatchIsUnwantedToken(IntStream input, int ttype)
public void reportError(RecognitionException e)
public void displayRecognitionError(String[] tokenNames, RecognitionException e)
public String getErrorMessage(RecognitionException e, String[] tokenNames)
public int getNumberOfSyntaxErrors()
public String getErrorHeader(RecognitionException e)
public String getTokenErrorDisplay(Token t)
public void emitErrorMessage(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)
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException
RecognitionException
public Object recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException
RecognitionException
protected Object getCurrentInputSymbol(IntStream input)
protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow)
public void consumeUntil(IntStream input, int tokenType)
public void consumeUntil(IntStream input, BitSet set)
protected void pushFollow(BitSet fset)
public List<String> getRuleInvocationStack()
public static List<String> getRuleInvocationStack(Throwable e, String recognizerClassName)
public int getBacktrackingLevel()
public void setBacktrackingLevel(int n)
public boolean failed()
public String[] getTokenNames()
public String getGrammarFileName()
public abstract String getSourceName()
public List<String> toStrings(List<? extends Token> 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()
Copyright © 1992–2015 ANTLR. All rights reserved.