Antlr.Runtime.Lexer Class Reference

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

Inheritance diagram for Antlr.Runtime.Lexer:

Inheritance graph
[legend]
Collaboration diagram for Antlr.Runtime.Lexer:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Lexer ()
 Lexer (ICharStream input)
 Lexer (ICharStream input, RecognizerSharedState state)
override void Reset ()
 Reset the parser's state. Subclasses must rewind the input stream.
virtual IToken NextToken ()
 Return a token from this source; i.e., Match a token on the char stream.
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.
abstract void mTokens ()
 This is the lexer entry point that sets instance var 'token'.
virtual void Emit (IToken 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).
virtual IToken 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.
virtual void Match (string s)
virtual void MatchAny ()
virtual void Match (int c)
virtual void MatchRange (int a, int b)
virtual 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.
override void ReportError (RecognitionException e)
 Report a recognition problem.
override string GetErrorMessage (RecognitionException e, string[] tokenNames)
 What error message should be generated for the various exception types?
string GetCharErrorDisplay (int c)
virtual void TraceIn (string ruleName, int ruleIndex)
virtual void TraceOut (string ruleName, int ruleIndex)

Protected Attributes

internal ICharStream input
 Where is the lexer drawing characters from?

Properties

virtual ICharStream CharStream [get, set]
 Set the char stream and reset the lexer.
override string SourceName [get]
 For debugging and other purposes, might want the source name. Have ANTLR provide a hook for this property.
override IIntStream Input [get]
virtual int Line [get]
virtual int CharPositionInLine [get]
virtual int CharIndex [get]
 What is the index of the current character of lookahead?
virtual string Text [get, set]
 Gets or sets the 'lexeme' for the current token.

Private Attributes

const int TOKEN_dot_EOF = (int)CharStreamConstants.EOF


Detailed Description

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.

Definition at line 47 of file Lexer.cs.


Constructor & Destructor Documentation

Antlr.Runtime.Lexer.Lexer (  ) 

Definition at line 53 of file Lexer.cs.

Antlr.Runtime.Lexer.Lexer ( ICharStream  input  ) 

Definition at line 57 of file Lexer.cs.

Antlr.Runtime.Lexer.Lexer ( ICharStream  input,
RecognizerSharedState  state 
)

Definition at line 62 of file Lexer.cs.


Member Function Documentation

override void Antlr.Runtime.Lexer.Reset (  )  [virtual]

Reset the parser's state. Subclasses must rewind the input stream.

Reimplemented from Antlr.Runtime.BaseRecognizer.

Definition at line 138 of file Lexer.cs.

virtual IToken Antlr.Runtime.Lexer.NextToken (  )  [virtual]

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

Implements Antlr.Runtime.ITokenSource.

Definition at line 160 of file Lexer.cs.

void Antlr.Runtime.Lexer.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.

Definition at line 204 of file Lexer.cs.

abstract void Antlr.Runtime.Lexer.mTokens (  )  [pure virtual]

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

virtual void Antlr.Runtime.Lexer.Emit ( IToken  token  )  [virtual]

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

Definition at line 218 of file Lexer.cs.

virtual IToken Antlr.Runtime.Lexer.Emit (  )  [virtual]

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

/remarks>

Definition at line 233 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.Match ( string  s  )  [virtual]

Definition at line 243 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.MatchAny (  )  [virtual]

Definition at line 265 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.Match ( int  c  )  [virtual]

Definition at line 270 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.MatchRange ( int  a,
int  b 
) [virtual]

Definition at line 287 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.Recover ( RecognitionException  re  )  [virtual]

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.

Definition at line 310 of file Lexer.cs.

override void Antlr.Runtime.Lexer.ReportError ( RecognitionException  e  )  [virtual]

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.

Reimplemented from Antlr.Runtime.BaseRecognizer.

Definition at line 315 of file Lexer.cs.

override string Antlr.Runtime.Lexer.GetErrorMessage ( RecognitionException  e,
string[]  tokenNames 
) [virtual]

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.GetType().Fullname) and, for no viable alts, the decision description and state etc...

Override this to change the message generated for one or more exception types.

Reimplemented from Antlr.Runtime.BaseRecognizer.

Definition at line 320 of file Lexer.cs.

string Antlr.Runtime.Lexer.GetCharErrorDisplay ( int  c  ) 

Definition at line 365 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.TraceIn ( string  ruleName,
int  ruleIndex 
) [virtual]

Definition at line 390 of file Lexer.cs.

virtual void Antlr.Runtime.Lexer.TraceOut ( string  ruleName,
int  ruleIndex 
) [virtual]

Definition at line 396 of file Lexer.cs.


Member Data Documentation

const int Antlr.Runtime.Lexer.TOKEN_dot_EOF = (int)CharStreamConstants.EOF [private]

Definition at line 49 of file Lexer.cs.

internal ICharStream Antlr.Runtime.Lexer.input [protected]

Where is the lexer drawing characters from?

Definition at line 406 of file Lexer.cs.


Property Documentation

virtual ICharStream Antlr.Runtime.Lexer.CharStream [get, set]

Set the char stream and reset the lexer.

Definition at line 73 of file Lexer.cs.

override string Antlr.Runtime.Lexer.SourceName [get]

For debugging and other purposes, might want the source name. Have ANTLR provide a hook for this property.

Returns:
The source name

Reimplemented from Antlr.Runtime.BaseRecognizer.

Definition at line 83 of file Lexer.cs.

override IIntStream Antlr.Runtime.Lexer.Input [get]

Reimplemented from Antlr.Runtime.BaseRecognizer.

Definition at line 89 of file Lexer.cs.

virtual int Antlr.Runtime.Lexer.Line [get]

Definition at line 94 of file Lexer.cs.

virtual int Antlr.Runtime.Lexer.CharPositionInLine [get]

Definition at line 99 of file Lexer.cs.

virtual int Antlr.Runtime.Lexer.CharIndex [get]

What is the index of the current character of lookahead?

Definition at line 105 of file Lexer.cs.

virtual string Antlr.Runtime.Lexer.Text [get, set]

Gets or sets the 'lexeme' for the current token.

The getter returns the text matched so far for the current token or any text override.

The setter sets the complete text of this token. It overrides/wipes any previous changes to the text.

Definition at line 123 of file Lexer.cs.


The documentation for this class was generated from the following file:

Generated on Wed Oct 1 14:13:25 2008 for ANTLR API by  doxygen 1.5.5