Enhanced C#
Language of your choice: library documentation
|
An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator). Note: this is the old (harder to use) base class design. You should use BaseParserForList{Token,MatchType} instead. More...
An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator). Note: this is the old (harder to use) base class design. You should use BaseParserForList{Token,MatchType} instead.
MatchType | : | IEquatable<MatchType> |
Nested classes | |
struct | SavePosition |
A helper class used by LLLPG for backtracking. More... | |
Public static fields | |
static readonly IMessageSink | FormatExceptionErrorSink |
Throws FormatException when it receives an error. Non-errors are sent to MessageSink.Current. More... | |
Properties | |
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 | |
BaseParser (ISourceFile file=null, int startIndex=0) | |
abstract MatchType | EofInt () |
Returns the value used for EOF (normally 0) More... | |
abstract Token | LT (int i) |
Returns the token at lookahead i (e.g. Source[InputPosition + i] if the tokens come from a list called Source) More... | |
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="") |
Static Protected Member Functions | |
static HashSet< MatchType > | NewSet (params MatchType[] items) |
Protected fields | |
ISourceFile | _sourceFile |
Token | _lt0 |
int | _inputPosition |
MatchType | EOF |
|
protectedpure virtual |
Returns the value used for EOF (normally 0)
Implemented in Loyc.Ecs.Parser.EcsParser, Loyc.Syntax.BaseParserForList< Token, MatchType, List >, and Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >.
|
inlineprotectedvirtual |
Records an error or throws an exception.
lookaheadIndex | Location of the error relative to the current InputPosition . When called by BaseParser, lookaheadIndex is always equal to 0. |
The default implementation throws a FormatException. When overriding this method, you can convert the lookaheadIndex to a SourcePos using the expression SourceFile.IndexToLine(LT(lookaheadIndex).StartIndex)
. This only works if an ISourceFile
object was provided to the constructor of this class, and Token
implements ISimpleToken.
Reimplemented in Loyc.Ecs.Parser.EcsParser.
|
inlineprotectedvirtual |
Converts a lookahead token index to a character index (used for error reporting).
The default implementation does this by trying to cast LT(lookaheadIndex)
to ISimpleToken{MatchType}
. Returns -1 on failure.
The StartIndex
reported by an EOF token is assumed not to be trustworthy: this method will ensure that the character index returned for EOF is at least as large as SourceFile.Text.Count
if a SourceFile was provided, or, otherwise, at least as large as the last token in the file, by scanning backward to find the last token in the file.
|
inlineprotectedvirtual |
Converts a lookahead token index to a SourcePos object using LaIndexToCharIndex and SourceFile.
If the derived class initialized SourceFile
to null, returns "At index {0}" where {0} is the character index.
Returns the token at lookahead i (e.g. Source[InputPosition + i]
if the tokens come from a list called Source)
Implemented in Loyc.Ecs.Parser.EcsParser, Loyc.Syntax.BaseParserForList< Token, MatchType, List >, Loyc.Syntax.BaseParserNoBacktracking< Token, Enumerator >, and Loyc.Syntax.ParserSource< Token, MatchType, List >.
|
protectedpure virtual |
Returns a string representation of the specified token type. These strings are used in error messages.
Implemented in Loyc.Syntax.BaseParserForList< Token, MatchType, List >, and Loyc.Syntax.ParserSource< Token, MatchType, List >.
|
static |
Throws FormatException when it receives an error. Non-errors are sent to MessageSink.Current.
|
getset |
Gets or sets the object to which error messages are sent. The default object is FormatExceptionErrorSink, which throws FormatException if an error occurs.
|
getsetprotected |
Current position of the next token to be parsed.
|
getprotected |
Returns the token type of _lt0 (normally _lt0.TypeInt)
Next token to parse (cached; is set to LT(0) whenever InputPosition is changed).
|
getprotected |
The ISourceFile object that was provided to the constructor, if any.