| Modifier and Type | Field and Description |
|---|---|
| protected CharStream | input
Where is the lexer drawing characters from? |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public Token | |
| public String | |
| public int | |
| public int | |
| public CharStream | |
| public Token | getEOFToken()
Returns the EOF token (default), if you need to return a custom token instead override this method. |
| public String | getErrorMessage(RecognitionException e, String[] tokenNames)
What error message should be generated for the various
exception types?
|
| public int | |
| public String | getSourceName()
Implements abstract org. Implements org. |
| public String | |
| public void | |
| public void | |
| public void | |
| public void | |
| public abstract void | |
| public Token | nextToken()
Implements org. |
| public void | recover(RecognitionException re)
Lexers can normally match any char in it's vocabulary after matching a token, so do the easy thing and just kill a character and hope it all works out. |
| public void | reportError(RecognitionException e)
Overrides org. |
| public void | reset()
Overrides org. |
| public void | |
| public void | |
| public void | skip()
Instruct the lexer to skip creating a token for current lexer rule and look for another token. |
| public void | |
| public void |
| input | back to summary |
|---|---|
| protected CharStream input Where is the lexer drawing characters from? | |
| Lexer | back to summary |
|---|---|
| public Lexer() | |
| Lexer | back to summary |
|---|---|
| public Lexer(CharStream input) | |
| Lexer | back to summary |
|---|---|
| public Lexer(CharStream input, RecognizerSharedState state) | |
| emit | back to summary |
|---|---|
| public void emit(Token token) Currently does not support multiple emits per nextToken invocation for efficiency reasons. Subclass and override this method and nextToken (to push tokens into a list and pull from that list rather than a single variable as this implementation does). | |
| emit | back to summary |
|---|---|
| public Token emit() The standard method called to automatically emit a token at the outermost lexical rule. The token object should point into the char buffer start..stop. If there is a text override in 'text', use that to set the token's text. Override this method to emit custom Token objects. If you are building trees, then you should also override Parser or TreeParser.getMissingSymbol(). | |
| getCharErrorDisplay | back to summary |
|---|---|
| public String getCharErrorDisplay(int c) | |
| getCharIndex | back to summary |
|---|---|
| public int getCharIndex() What is the index of the current character of lookahead? | |
| getCharPositionInLine | back to summary |
|---|---|
| public int getCharPositionInLine() | |
| getCharStream | back to summary |
|---|---|
| public CharStream getCharStream() | |
| getEOFToken | back to summary |
|---|---|
| public Token getEOFToken() Returns the EOF token (default), if you need to return a custom token instead override this method. | |
| getErrorMessage | back to summary |
|---|---|
| public String getErrorMessage(RecognitionException e, String[] tokenNames) Overrides org. Doc from org. 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. This also makes it much easier for the exception handling because the exception classes do not have to have pointers back to this object to access utility routines and so on. Also, changing the message for an exception type would be difficult because you would have to subclassing exception, but then somehow get ANTLR to make those kinds of exception objects instead of the default. This looks weird, but trust me--it makes the most sense in terms of flexibility. For grammar debugging, you will want to override this to add more information such as the stack frame with getRuleInvocationStack(e, this.getClass().getName()) and, for no viable alts, the decision description and state etc... Override this to change the message generated for one or more exception types.
| |
| getLine | back to summary |
|---|---|
| public int getLine() | |
| getSourceName | back to summary |
|---|---|
| public String getSourceName() Implements abstract org. Implements org. Doc from org. Where are you getting tokens from? normally the implication will simply ask lexers input stream.
| |
| getText | back to summary |
|---|---|
| public String getText() Return the text matched so far for the current token or any text override. | |
| match | back to summary |
|---|---|
| public void match(String s) throws MismatchedTokenException | |
| match | back to summary |
|---|---|
| public void match(int c) throws MismatchedTokenException | |
| matchAny | back to summary |
|---|---|
| public void matchAny() | |
| matchRange | back to summary |
|---|---|
| public void matchRange(int a, int b) throws MismatchedRangeException | |
| mTokens | back to summary |
|---|---|
| public abstract void mTokens() throws RecognitionException This is the lexer entry point that sets instance var 'token' | |
| nextToken | back to summary |
|---|---|
| public Token nextToken() Implements org. Return a token from this source; i.e., match a token on the char stream. | |
| recover | back to summary |
|---|---|
| public void recover(RecognitionException re) Lexers can normally match any char in it's vocabulary after matching a token, so do the easy thing and just kill a character and hope it all works out. You can instead use the rule invocation stack to do sophisticated error recovery if you are in a fragment rule. | |
| reportError | back to summary |
|---|---|
| public void reportError(RecognitionException e) Overrides org. Doc from org. Report a recognition problem. This method sets errorRecovery to indicate the parser is recovering not parsing. Once in recovery mode, no errors are generated. To get out of recovery mode, the parser must successfully match a token (after a resync). So it will go: 1. error occurs 2. enter recovery mode, report error 3. consume until token found in resynch set 4. try to resume parsing 5. next match() will reset errorRecovery mode If you override, make sure to update syntaxErrors if you care about that.
| |
| reset | back to summary |
|---|---|
| public void reset() Overrides org. Doc from org. reset the parser's state; subclasses must rewinds the input stream
| |
| setCharStream | back to summary |
|---|---|
| public void setCharStream(CharStream input) Set the char stream and reset the lexer | |
| setText | back to summary |
|---|---|
| public void setText(String text) Set the complete text of this token; it wipes any previous changes to the text. | |
| skip | back to summary |
|---|---|
| public void skip() Instruct the lexer to skip creating a token for current lexer rule and look for another token. nextToken() knows to keep looking when a lexer rule finishes with token set to SKIP_TOKEN. Recall that if token==null at end of any token rule, it creates one for you and emits it. | |
| traceIn | back to summary |
|---|---|
| public void traceIn(String ruleName, int ruleIndex) | |
| traceOut | back to summary |
|---|---|
| public void traceOut(String ruleName, int ruleIndex) | |