Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Properties | Protected Member Functions | Protected fields | List of all members
Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator > Class Template Referenceabstract

An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator) and receive tokens from any IEnumerator{Token}. More...


Source file:
Inheritance diagram for Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >:
Loyc.Syntax.BaseParser< Token > Loyc.Syntax.BaseParser< Token, MatchType > Loyc.Syntax.BaseParserNoBacktracking< Token >

Remarks

An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator) and receive tokens from any IEnumerator{Token}.

This base class for LLLPG parsers simply requires an enumerator to work, and it has a small buffer to hold lookahead tokens. Old tokens are forgotten, so this base class does not support backtracking (i.e. syntactic predicates), but it can save memory. Please use BaseParserForList{Tok,La} if your input sequence comes in the form of a list.

This version of BaseParser has Enumerator as a generic parameter. Compared to using IEnumerator{Token} directly, this can increase performance in case Enumerator is a value type (e.g. List<Token>.Enumerator).

(I wrote this class by mistake... I actually forgot about backtracking!)

Type Constraints
Token :ISimpleToken 
Enumerator :IEnumerator<Token> 

Properties

sealed override Int32 LA0Int [get]
 
new int InputPosition [get, set]
 Cumulative index of the next token to be parsed. More...
 
- Properties inherited from Loyc.Syntax.BaseParser< Token, MatchType >
IMessageSink ErrorSink [get, set]
 Gets or sets the object to which error messages are sent. The default object is FormatExceptionErrorSink, which throws FormatException if an error occurs. More...
 
ISourceFile SourceFile [get]
 The ISourceFile object that was provided to the constructor, if any. More...
 
Token LT0 [get]
 Next token to parse (cached; is set to LT(0) whenever InputPosition is changed). More...
 
int InputPosition [get, set]
 Current position of the next token to be parsed. More...
 
abstract MatchType LA0Int [get]
 Returns the token type of _lt0 (normally _lt0.TypeInt) More...
 

Protected Member Functions

 BaseParserNoBacktracking (Enumerator sequence, Token eofToken, ISourceFile file, int startIndex=0)
 Initializes this object to begin parsing the specified tokens. More...
 
void Reset (Enumerator sequence, Token eofToken, ISourceFile file, int startIndex=0)
 
sealed override Int32 EofInt ()
 Returns the value used for EOF (normally 0) More...
 
sealed override Token LT (int i)
 Returns the Token at lookahead i, where 0 is the next token. This class does not support negative lookahead because old tokens from the IEnumerator are discarded. More...
 
abstract override string ToString (Int32 tokenType)
 Returns a string representation of the specified token type. These strings are used in error messages. More...
 
- Protected Member Functions inherited from Loyc.Syntax.BaseParser< Token >
 BaseParser (ISourceFile file=null, int startIndex=0)
 
- Protected Member Functions inherited from Loyc.Syntax.BaseParser< Token, MatchType >
 BaseParser (ISourceFile file=null, int startIndex=0)
 
abstract string ToString (MatchType tokenType)
 Returns a string representation of the specified token type. These strings are used in error messages. More...
 
virtual int LaIndexToCharIndex (int lookaheadIndex)
 Converts a lookahead token index to a character index (used for error reporting). More...
 
virtual object LaIndexToSourcePos (int lookaheadIndex)
 Converts a lookahead token index to a SourcePos object using LaIndexToCharIndex and SourceFile. More...
 
virtual void Error (int lookaheadIndex, string message)
 Records an error or throws an exception. More...
 
virtual void Error (int lookaheadIndex, string format, params object[] args)
 
void Skip ()
 
Token MatchAny ()
 
Token Match (HashSet< MatchType > set, bool inverted=false)
 
Token Match (MatchType a)
 
Token Match (MatchType a, MatchType b)
 
Token Match (MatchType a, MatchType b, MatchType c)
 
Token Match (MatchType a, MatchType b, MatchType c, MatchType d)
 
Token MatchExcept ()
 
Token MatchExcept (MatchType a)
 
Token MatchExcept (MatchType a, MatchType b)
 
Token MatchExcept (MatchType a, MatchType b, MatchType c)
 
Token MatchExcept (MatchType a, MatchType b, MatchType c, MatchType d)
 
Token MatchExcept (HashSet< MatchType > set)
 
bool TryMatch (HashSet< MatchType > set, bool inverted=false)
 
bool TryMatch (MatchType a)
 
bool TryMatch (MatchType a, MatchType b)
 
bool TryMatch (MatchType a, MatchType b, MatchType c)
 
bool TryMatch (MatchType a, MatchType b, MatchType c, MatchType d)
 
bool TryMatchExcept ()
 
bool TryMatchExcept (MatchType a)
 
bool TryMatchExcept (MatchType a, MatchType b)
 
bool TryMatchExcept (MatchType a, MatchType b, MatchType c)
 
bool TryMatchExcept (MatchType a, MatchType b, MatchType c, MatchType d)
 
bool TryMatchExcept (HashSet< MatchType > set)
 
void Error (bool inverted, params MatchType[] expected)
 
virtual void Error (bool inverted, IEnumerable< MatchType > expected)
 
virtual string ToString (bool inverted, IEnumerable< MatchType > expected)
 
virtual void Check (bool expectation, string expectedDescr="")
 

Protected fields

Token EofToken
 
new int _inputPosition
 
- Protected fields inherited from Loyc.Syntax.BaseParser< Token, MatchType >
ISourceFile _sourceFile
 
Token _lt0
 
int _inputPosition
 
MatchType EOF
 

Additional Inherited Members

- Public static fields inherited from Loyc.Syntax.BaseParser< Token, MatchType >
static readonly IMessageSink FormatExceptionErrorSink
 Throws FormatException when it receives an error. Non-errors are sent to MessageSink.Current. More...
 
- Static Protected Member Functions inherited from Loyc.Syntax.BaseParser< Token, MatchType >
static HashSet< MatchType > NewSet (params MatchType[] items)
 

Constructor & Destructor Documentation

Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.BaseParserNoBacktracking ( Enumerator  sequence,
Token  eofToken,
ISourceFile  file,
int  startIndex = 0 
)
inlineprotected

Initializes this object to begin parsing the specified tokens.

Parameters
sequenceA list of tokens to be parsed.
eofTokenA token value to return when the input position reaches the end of the token list.
fileA source file object that will be returned by the SourceFile property. By default, this object is used to get the file name, line number and column number shown in parser errors. If you are using BaseLexer, you can get this object from the BaseLexer{C}.SourceFile property. The SourceFile. property (in this class) will return this value. It can be null, which means that default error messages will show the character index instead of the file, line number and column number.
startIndexThe initial value of the InputPosition property. This is informational only, and has no effect on the behavior of this class.

Member Function Documentation

sealed override Int32 Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.EofInt ( )
inlineprotectedvirtual

Returns the value used for EOF (normally 0)

Implements Loyc.Syntax.BaseParser< Token, MatchType >.

sealed override Token Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.LT ( int  i)
inlineprotectedvirtual

Returns the Token at lookahead i, where 0 is the next token. This class does not support negative lookahead because old tokens from the IEnumerator are discarded.

Implements Loyc.Syntax.BaseParser< Token, MatchType >.

abstract override string Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.ToString ( Int32  tokenType)
protectedpure virtual

Returns a string representation of the specified token type. These strings are used in error messages.

Property Documentation

new int Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.InputPosition
getsetprotected

Cumulative index of the next token to be parsed.

This class doesn't care what the absolute InputPosition is, since it reads from an IEnumerator{Token}. This property is constrained to always increase, since old tokens are forgotten.