Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public static fields | Properties | Public Member Functions | Protected Member Functions | Protected fields | List of all members
Loyc.Syntax.Les.Les2Parser Class Reference

Parses LES (Loyc Expression Syntax) code into a sequence of Loyc trees (LNode), one per top-level statement. More...


Source files:
Inheritance diagram for Loyc.Syntax.Les.Les2Parser:
Loyc.Syntax.BaseParserForList< Token, MatchType > Loyc.Syntax.BaseParserForList< Token, MatchType, List > Loyc.Syntax.BaseParser< Token, MatchType >

Remarks

Parses LES (Loyc Expression Syntax) code into a sequence of Loyc trees (LNode), one per top-level statement.

You can use Les2LanguageService.Value with ParsingService.Parse to easily parse a text string (holding zero or more LES statements) into a Loyc tree.

This class expects to receive tokens from Les2Lexer that have been preprocessed by TokensToTree, with whitespace tokens filtered out.

Public static fields

static readonly Precedence StartStmt = Precedence.MinValue
 
- Public static fields inherited from Loyc.Syntax.BaseParser< Token, MatchType >
static readonly IMessageSink LogExceptionErrorSink
 Throws LogException when it receives an error. Non-errors are sent to MessageSink.Default. More...
 
static readonly IMessageSink FormatExceptionErrorSink
 

Properties

new IMessageSink ErrorSink [get, set]
 
- Properties inherited from Loyc.Syntax.BaseParserForList< Token, MatchType, List >
Token EofToken [get]
 
List TokenList [get]
 The IList{Token} that was provided to the constructor, if any. More...
 
sealed override MatchType LA0Int [get]
 
MatchType LA0 [get]
 
new int InputPosition [get, set]
 
- 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 LogExceptionErrorSink, which throws an exception 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...
 

Public Member Functions

 Les2Parser (IListAndListSource< Token > tokens, ISourceFile file, IMessageSink messageSink)
 
 Les2Parser (IListSource< Token > tokens, ISourceFile file, IMessageSink messageSink)
 
 Les2Parser (IList< Token > tokens, ISourceFile file, IMessageSink messageSink, int startIndex=0)
 
void Reset (IList< Token > list, ISourceFile file, int startIndex=0)
 
IEnumerable< LNodeStart (Holder< TokenType > separator)
 Top-level rule: expects a sequence of statements followed by EOF More...
 
LNodeList ExprList (LNodeList list=default(LNodeList))
 
LNodeList StmtList ()
 
virtual LNodeList ExprList (ref TokenType endMarker, LNodeList list=default(LNodeList))
 
virtual IEnumerable< LNodeExprListLazy (Holder< TokenType > endMarker)
 

Protected Member Functions

override void Reset (IList< Token > list, Func< Token, Token > getEofToken, int eof, ISourceFile file, int startIndex=0)
 
override string ToString (int type)
 
LNode MissingExpr (Token tok)
 
Symbol ToSuffixOpName (object symbol)
 
Precedence PrefixPrecedenceOf (Token t)
 
Precedence SuffixPrecedenceOf (Token t)
 
Precedence InfixPrecedenceOf (Token t)
 
virtual LNode MarkSpecial (LNode n)
 
virtual LNode MarkCall (LNode n)
 
override void MatchError (bool inverted, IEnumerable< int > expected_)
 
LNode TopExpr ()
 
- Protected Member Functions inherited from Loyc.Syntax.BaseParserForList< Token, MatchType >
 BaseParserForList (IList< Token > list, Token getEofToken, ISourceFile file, int startIndex=0)
 <inheridoc>
 
 BaseParserForList (IList< Token > list, Func< Token, Token > getEofToken, MatchType eof, ISourceFile file, int startIndex=0)
 <inheridoc>
 
 BaseParserForList (IListAndListSource< Token > list, Token eofToken, ISourceFile file, int startIndex=0)
 
 BaseParserForList (IListSource< Token > list, Token eofToken, ISourceFile file, int startIndex=0)
 
 BaseParserForList (IEnumerable< Token > list, Token getEofToken, ISourceFile file, int startIndex=0)
 <inheridoc>
 
 BaseParserForList (IEnumerable< Token > list, Func< Token, Token > getEofToken, MatchType eof, ISourceFile file, int startIndex=0)
 <inheridoc>
 
 BaseParserForList (IEnumerator< Token > list, Token getEofToken, ISourceFile file, int startIndex=0)
 <inheridoc>
 
- Protected Member Functions inherited from Loyc.Syntax.BaseParserForList< Token, MatchType, List >
 BaseParserForList (List list, Func< Token, Token > getEofToken, MatchType eof, ISourceFile file, int startIndex=0)
 Initializes this object to begin parsing the specified tokens. More...
 
 BaseParserForList (List list, Token getEofToken, ISourceFile file, int startIndex=0)
 
virtual void Reset (List list, Token eofToken, ISourceFile file, int startIndex=0)
 Reinitializes the object. This method is called by the constructor. More...
 
virtual void Reset (List list, Func< Token, Token > getEofToken, MatchType eof, ISourceFile file, int startIndex=0)
 Reinitializes the object. This method is called by the constructor. More...
 
void Reset ()
 
sealed override MatchType EofInt ()
 Returns the value used for EOF (normally 0) More...
 
sealed override 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...
 
MatchType LA (int i)
 
abstract override string ToString (MatchType tokenType)
 Returns a string representation of the specified token type. These strings are used in error messages. More...
 
bool Down (List children)
 Switches to parsing the specified token list at position zero (typically the value of Loyc.Syntax.Lexing.Token.Children in a token tree produced by TokensToTree.) The original token list and the original InputPosition are placed on a stack, so you can restore the old list by calling Up(). More...
 
void Up ()
 Returns to the old token list saved by Down. More...
 
Up< T > (T value)
 Calls Up() and returns value. More...
 
- Protected Member Functions inherited from Loyc.Syntax.BaseParser< Token, MatchType >
 BaseParser (ISourceFile?file=null, int startIndex=0)
 Initializes the base class. More...
 
virtual int LaIndexToCharIndex (int lookaheadIndex)
 Converts a lookahead token index to a character index (used for error reporting). More...
 
virtual object LaIndexToMsgContext (int lookaheadIndex)
 Converts a lookahead token index to a SourceRange (or to a string if SourceFile was initialized to null.) 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 MatchError (bool inverted, params MatchType[] expected)
 
virtual void MatchError (bool inverted, IEnumerable< MatchType > expected)
 Handles an error that occurs during Match() or MatchExcept() More...
 
virtual string ToString (bool inverted, IEnumerable< MatchType > expected)
 
virtual void Check (bool expectation, string expectedDescr="")
 

Protected fields

LNodeFactory F = null!
 
Les2PrecedenceMap _prec = Les2PrecedenceMap.Default
 
- Protected fields inherited from Loyc.Syntax.BaseParserForList< Token, MatchType, List >
Func< Token, Token_getEofToken
 
List _tokenList
 
- Protected fields inherited from Loyc.Syntax.BaseParser< Token, MatchType >
ISourceFile _sourceFile
 
Token _lt0 = default!
 
int _inputPosition
 
MatchType EOF
 

Additional Inherited Members

- Static Protected Member Functions inherited from Loyc.Syntax.BaseParser< Token, MatchType >
static HashSet< MatchType > NewSet (params MatchType[] items)
 

Member Function Documentation

IEnumerable<LNode> Loyc.Syntax.Les.Les2Parser.Start ( Holder< TokenType >  separator)
inline

Top-level rule: expects a sequence of statements followed by EOF