Packageorg.antlr.runtime
Classpublic class Lexer
InheritanceLexer Inheritance BaseRecognizer
ImplementsTokenSource

A lexer is recognizer that draws input symbols from a character stream. lexer grammars result in a subclass of this object. A Lexer object uses simplified match() and error recovery mechanisms in the interest of speed.



Public Properties
 PropertyDefined by
 InheritedbacktrackingLevel : int
BaseRecognizer
  charIndex : int
[read-only] What is the index of the current character of lookahead?
Lexer
  charPositionInLine : int
[read-only]
Lexer
  charStream : CharStream
Lexer
 InheritedgrammarFileName : String
For debugging and other purposes, might want the grammar name.
BaseRecognizer
  line : int
[read-only]
Lexer
 InheritednumberOfSyntaxErrors : int
Get number of recognition errors (lexer, parser, tree parser).
BaseRecognizer
  sourceName : String
[read-only]
Lexer
 Inheritedstate : RecognizerSharedState
State of a lexer, parser, or tree parser are collected into a state object so the state can be shared.
BaseRecognizer
  text : String
Return the text matched so far for the current token or any text override.
Lexer
 InheritedtokenNames : Array
Used to print out token names like ID during debugging and error reporting.
BaseRecognizer
Protected Properties
 PropertyDefined by
  input : CharStream
Where is the lexer drawing characters from?
Lexer
Public Methods
 MethodDefined by
  
Lexer(input:CharStream = null, state:RecognizerSharedState = null)
Lexer
 Inherited
alreadyParsedRule(input:IntStream, ruleIndex:int):Boolean
Has this rule already parsed input at the current index in the input stream? Return the stop token index or MEMO_RULE_UNKNOWN.
BaseRecognizer
 Inherited
beginResync():void
A hook to listen in on the token consumption during error recovery.
BaseRecognizer
 Inherited
consumeUntil(input:IntStream, bitSet:BitSet):void
Consume tokens until one matches the given token set
BaseRecognizer
 Inherited
consumeUntilToken(input:IntStream, tokenType:int):void
BaseRecognizer
 Inherited
BaseRecognizer
  
The standard method called to automatically emit a token at the outermost lexical rule.
Lexer
 Inherited
emitErrorMessage(msg:String):void
Override this method to change where error messages go
BaseRecognizer
  
emitToken(token:Token):void
Currently does not support multiple emits per nextToken invocation for efficiency reasons.
Lexer
 Inherited
endResync():void
BaseRecognizer
  
getCharErrorDisplay(c:int):String
Lexer
 Inherited
What is the error header, normally line/character position information?
BaseRecognizer
  
getErrorMessage(e:RecognitionException, tokenNames:Array):String
Lexer
 Inherited
getRuleMemoization(ruleIndex:int, ruleStartIndex:int):int
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.
BaseRecognizer
 Inherited
return how many rule/input-index pairs there are in total.
BaseRecognizer
 Inherited
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.
BaseRecognizer
  
match(c:int):void
Lexer
  
matchAny():void
Lexer
 Inherited
Match the wildcard: in a symbol
BaseRecognizer
  
matchRange(a:int, b:int):void
Lexer
 Inherited
matchStream(input:IntStream, ttype:int, follow:BitSet):Object
Match current input symbol against ttype.
BaseRecognizer
  
matchString(s:String):void
Lexer
 Inherited
memoize(input:IntStream, ruleIndex:int, ruleStartIndex:int):void
Record whether or not this rule parsed the input at this position successfully.
BaseRecognizer
 Inherited
mismatchIsMissingToken(input:IntStream, follow:BitSet):Boolean
BaseRecognizer
 Inherited
mismatchIsUnwantedToken(input:IntStream, ttype:int):Boolean
BaseRecognizer
  
mTokens():void
This is the lexer entry point that sets instance var 'token'
Lexer
  
Return a token from this source; i.e., match a token on the char stream.
Lexer
  
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.
Lexer
 Inherited
Not currently used
BaseRecognizer
 Inherited
recoverFromMismatchedToken(input:IntStream, ttype:int, follow:BitSet):Object
Attempt to recover from a single missing or extra token.
BaseRecognizer
 Inherited
Recover from an error found on the input stream.
BaseRecognizer
  
Lexer
  
reset():void
Lexer
  
skip():void
Instruct the lexer to skip creating a token for current lexer rule and look for another token.
Lexer
 Inherited
toStrings(tokens:Array):Array
A convenience method for use most often with template rewrites.
BaseRecognizer
  
traceIn(ruleName:String, ruleIndex:int):void
Lexer
 Inherited
traceInSymbol(ruleName:String, ruleIndex:int, inputSymbol:Object):void
BaseRecognizer
  
traceOut(ruleName:String, ruleIndex:int):void
Lexer
 Inherited
traceOutSymbol(ruleName:String, ruleIndex:int, inputSymbol:Object):void
BaseRecognizer
Protected Methods
 MethodDefined by
 Inherited
combineFollows(exact:Boolean):BitSet
BaseRecognizer
 Inherited
Compute the context-sensitive FOLLOW set for current rule.
BaseRecognizer
 Inherited
BaseRecognizer
 Inherited
Match needs to return the current input symbol, which gets put into the label for the associated token ref; e.g., x=ID.
BaseRecognizer
 Inherited
getMissingSymbol(input:IntStream, e:RecognitionException, expectedTokenType:int, follow:BitSet):Object
Conjure up a missing token during error recovery.
BaseRecognizer
 Inherited
mismatch(input:IntStream, ttype:int, follow:BitSet):void
Factor out what to do upon token mismatch so tree parsers can behave differently.
BaseRecognizer
 Inherited
pushFollow(fset:BitSet):void
Push a rule's follow set using our own hardcoded stack
BaseRecognizer
Public Constants
 ConstantDefined by
 InheritedDEFAULT_TOKEN_CHANNEL : int = 0
[static]
BaseRecognizer
 InheritedHIDDEN : int = 99
[static]
BaseRecognizer
 InheritedINITIAL_FOLLOW_STACK_SIZE : int = 100
[static]
BaseRecognizer
 InheritedMEMO_RULE_FAILED : int = -2
[static]
BaseRecognizer
 InheritedMEMO_RULE_UNKNOWN : int = -1
[static]
BaseRecognizer
 InheritedNEXT_TOKEN_RULE_NAME : String = "nextToken"
[static]
BaseRecognizer
Property detail
charIndexproperty
charIndex:int  [read-only]

What is the index of the current character of lookahead?

Implementation
    public function get charIndex():int
charPositionInLineproperty 
charPositionInLine:int  [read-only]Implementation
    public function get charPositionInLine():int
charStreamproperty 
charStream:CharStream  [read-write]Implementation
    public function get charStream():CharStream
    public function set charStream(value:CharStream):void
inputproperty 
protected var input:CharStream

Where is the lexer drawing characters from?

lineproperty 
line:int  [read-only]Implementation
    public function get line():int
sourceNameproperty 
sourceName:String  [read-only]Implementation
    public function get sourceName():String
textproperty 
text:String  [read-write]

Return the text matched so far for the current token or any text override.

Implementation
    public function get text():String
    public function set text(value:String):void
Constructor detail
Lexer()constructor
public function Lexer(input:CharStream = null, state:RecognizerSharedState = null)Parameters
input:CharStream (default = null)
 
state:RecognizerSharedState (default = null)
Method detail
emit()method
public function emit():Token

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.

Returns
Token
emitToken()method 
public function emitToken(token:Token):void

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).

Parameters
token:Token
getCharErrorDisplay()method 
public function getCharErrorDisplay(c:int):StringParameters
c:int

Returns
String
getErrorMessage()method 
public override function getErrorMessage(e:RecognitionException, tokenNames:Array):StringParameters
e:RecognitionException
 
tokenNames:Array

Returns
String
match()method 
public function match(c:int):voidParameters
c:int
matchAny()method 
public function matchAny():void
matchRange()method 
public function matchRange(a:int, b:int):voidParameters
a:int
 
b:int
matchString()method 
public function matchString(s:String):voidParameters
s:String
mTokens()method 
public function mTokens():void

This is the lexer entry point that sets instance var 'token'

nextToken()method 
public function nextToken():Token

Return a token from this source; i.e., match a token on the char stream.

Returns
Token
recover()method 
public function recover(re:RecognitionException):RecognitionException

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.

Parameters
re:RecognitionException

Returns
RecognitionException — This method should return the exception it was provided as an argument. This differs from the Java runtime so that an exception variable does not need to be declared in the generated code, thus reducing a large number of compiler warnings in generated code.
reportError()method 
public override function reportError(e:RecognitionException):voidParameters
e:RecognitionException
reset()method 
public override function reset():void
skip()method 
public function skip():void

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()method 
public function traceIn(ruleName:String, ruleIndex:int):voidParameters
ruleName:String
 
ruleIndex:int
traceOut()method 
public function traceOut(ruleName:String, ruleIndex:int):voidParameters
ruleName:String
 
ruleIndex:int