Enhanced C#
Language of your choice: library documentation
Public fields | Properties | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected fields | List of all members
Loyc.Ecs.Parser.EcsLexer Class Reference

Lexer for EC# source code (see ILexer<Token>). More...


Source files:
Inheritance diagram for Loyc.Ecs.Parser.EcsLexer:
Loyc.Syntax.Lexing.BaseLexer< CharSrc > Loyc.Syntax.Lexing.ILexer< Token > Loyc.Syntax.IIndexToLine Loyc.Syntax.IHasFileName Loyc.Syntax.IIndexToLine Loyc.Syntax.IHasFileName Loyc.Syntax.IHasFileName

Remarks

Lexer for EC# source code (see ILexer<Token>).

See also
TokensToTree

Public fields

bool AllowNestedComments = false
 
int SpacesPerTab = 4
 

Properties

new ISourceFile SourceFile [get]
 
int IndentLevel [get]
 
UString IndentString [get]
 
- Properties inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
IMessageSink?? ErrorSink [get, set]
 Gets or sets the object to which error messages are sent. The default object is LogExceptionErrorSink, which throws an exception if an error occurs. More...
 
int LA0 [get]
 
CharSrc CharSource [get]
 
string FileName [get]
 
int InputPosition [get, protected set]
 
LexerSourceFile< CharSrc > SourceFile [get]
 
int LineNumber [get]
 Current line number. Starts at 1 for the first line, unless derived class changes it. More...
 
int LineStartAt [get]
 Index at which the current line started. More...
 
- Properties inherited from Loyc.Syntax.IHasFileName
string FileName [get]
 
- Properties inherited from Loyc.Syntax.Lexing.ILexer< Token >
ISourceFile SourceFile [get]
 The file being lexed. More...
 
IMessageSink ErrorSink [get, set]
 Event handler for errors. More...
 
int IndentLevel [get]
 Indentation level of the current line. This is updated after scanning the first whitespaces on a new line, and may be reset to zero when NextToken() returns a newline. More...
 
UString IndentString [get]
 Gets a string slice that holds the spaces or tabs that were used to indent the current line. More...
 
int LineNumber [get]
 Current line number (1 for the first line). More...
 
int InputPosition [get]
 Current input position (an index into SourceFile.Text). More...
 

Public Member Functions

 EcsLexer (string text, IMessageSink sink)
 
 EcsLexer (ICharSource text, string fileName, IMessageSink sink, int startPosition=0)
 
void Reset (ICharSource source, string fileName="", int inputPosition=0)
 
Maybe< TokenNextToken ()
 Scans the next token and returns information about it. More...
 
void Restart ()
 
- Public Member Functions inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
 BaseLexer (CharSrc chars, string fileName="", int inputPosition=0, bool newSourceFile=true)
 Initializes BaseLexer. More...
 
virtual void Reset (CharSrc chars, string fileName="", int inputPosition=0, bool newSourceFile=true)
 Reinitializes the object. This method is called by the constructor. More...
 
LineColumnFile IndexToLine (int charIndex)
 Returns the position in a source file of the specified index. More...
 

Static Public Member Functions

static int MeasureIndent (UString indent, int spacesPerTab)
 

Protected Member Functions

override void Error (int lookaheadIndex, string message)
 This method is called to handle errors that occur during lexing. More...
 
new int LA (int i)
 
- Protected Member Functions inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
void Reset ()
 
int LA (int i)
 
void Skip ()
 Increments InputPosition. Called by LLLPG when prediction already verified the input (and caller doesn't save LA(0)) More...
 
virtual void AfterNewline ()
 The lexer must call this method exactly once after it advances past each newline, even inside comments and strings. This method keeps the LineNumber and LineStartAt properties updated. More...
 
 BaseLexer (ICharSource source, string fileName="", int inputPosition=0, bool newSourceFile=true)
 
void Newline ()
 Default newline parser that matches '
' or '\r' unconditionally. More...
 
void Spaces ()
 Skips past any spaces at the current position. Equivalent to rule Spaces @[ (' '|'\t')* ] in LLLPG. More...
 
int MatchAny ()
 
int Match (HashSet< int > set)
 
int Match (int a)
 
int Match (int a, int b)
 
int Match (int a, int b, int c)
 
int Match (int a, int b, int c, int d)
 
int MatchRange (int aLo, int aHi)
 
int MatchRange (int aLo, int aHi, int bLo, int bHi)
 
int MatchExcept ()
 
int MatchExcept (HashSet< int > set)
 
int MatchExcept (int a)
 
int MatchExcept (int a, int b)
 
int MatchExcept (int a, int b, int c)
 
int MatchExcept (int a, int b, int c, int d)
 
int MatchExceptRange (int aLo, int aHi)
 
int MatchExceptRange (int aLo, int aHi, int bLo, int bHi)
 
bool TryMatch (HashSet< int > set)
 
bool TryMatch (int a)
 
bool TryMatch (int a, int b)
 
bool TryMatch (int a, int b, int c)
 
bool TryMatch (int a, int b, int c, int d)
 
bool TryMatchRange (int aLo, int aHi)
 
bool TryMatchRange (int aLo, int aHi, int bLo, int bHi)
 
bool TryMatchExcept ()
 
bool TryMatchExcept (HashSet< int > set)
 
bool TryMatchExcept (int a)
 
bool TryMatchExcept (int a, int b)
 
bool TryMatchExcept (int a, int b, int c)
 
bool TryMatchExcept (int a, int b, int c, int d)
 
bool TryMatchExceptRange (int aLo, int aHi)
 
bool TryMatchExceptRange (int aLo, int aHi, int bLo, int bHi)
 
virtual void Check (bool expectation, string expectedDescr="")
 
virtual void Error (int lookaheadIndex, string format, params object[] args)
 This method is called to format and handle errors that occur during lexing. The default implementation sends errors to ErrorSink, which, by default, throws a FormatException. More...
 
virtual object IndexToPositionObject (int charIndex)
 
virtual void MatchError (bool inverted, params int[] ranges)
 
virtual void MatchError (bool inverted, IList< int > ranges)
 Handles an error that occurs during Match(), MatchExcept(), MatchRange() or MatchExceptRange() More...
 
virtual void Error (bool inverted, HashSet< int > set)
 
string RangesToString (IList< int > ranges)
 Converts a list of character ranges to a string, e.g. for input list {'*','*','a','z'}, the output is "'*' 'a'..'z'". More...
 
void PrintChar (int c, StringBuilder sb)
 Prints a character as a string, e.g. 'a' -> "'a'", with the special value -1 representing EOF, so PrintChar(-1, ...) == "EOF". More...
 

Protected fields

Dictionary< UString, object > _idCache = new Dictionary<UString, object>()
 
- Protected fields inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
int CachedBlockSize = 512
 
int _lineStartAt
 
int _lineNumber = 1
 

Additional Inherited Members

- Public static fields inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
static readonly IMessageSink LogExceptionErrorSink
 Throws LogException when it receives an error. Non-errors are sent to MessageSink.Default. More...
 
static readonly IMessageSink FormatExceptionErrorSink
 
- Static Protected Member Functions inherited from Loyc.Syntax.Lexing.BaseLexer< CharSrc >
static HashSet< int > NewSet (params int[] items)
 
static HashSet< int > NewSetOfRanges (params int[] ranges)
 

Member Function Documentation

◆ Error()

override void Loyc.Ecs.Parser.EcsLexer.Error ( int  lookaheadIndex,
string  message 
)
inlineprotectedvirtual

This method is called to handle errors that occur during lexing.

Parameters
lookaheadIndexIndex where the error occurred, relative to the current InputPosition (i.e. InputPosition + lookaheadIndex is the position of the error).
messageAn error message, not including the error location.

Reimplemented from Loyc.Syntax.Lexing.BaseLexer< CharSrc >.

References Loyc.Syntax.Lexing.BaseLexer< CharSrc >.ErrorSink.

◆ NextToken()

Maybe<Token> Loyc.Ecs.Parser.EcsLexer.NextToken ( )
inline

Scans the next token and returns information about it.

Returns
The next token, or null at the end of the source file.

Implements Loyc.Syntax.Lexing.ILexer< Token >.