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

The Value property provides easy access to the lexer, parser and printer for Enhanced C#. More...


Source file:
Inheritance diagram for Loyc.Ecs.EcsLanguageService:
Loyc.Syntax.IParsingService Loyc.Syntax.ILNodePrinter

Remarks

The Value property provides easy access to the lexer, parser and printer for Enhanced C#.

EC# overview: https://ecsharp.net

Public static fields

static readonly EcsLanguageService Value = new EcsLanguageService(false)
 
static readonly EcsLanguageService WithPlainCSharpPrinter = new EcsLanguageService(true)
 

Properties

IEnumerable< string > FileExtensions [get]
 
bool HasTokenizer [get]
 
bool CanPreserveComments [get]
 
- Properties inherited from Loyc.Syntax.IParsingService
IEnumerable< string > FileExtensions [get]
 Standard file extensions for this language, without leading dots, with the first one being the most common. More...
 
bool HasTokenizer [get]
 Returns true if the Tokenize method is available. More...
 
bool CanPreserveComments [get]
 Returns true if the parser supports preserving comments. More...
 

Public Member Functions

override string ToString ()
 
void Print (LNode node, StringBuilder target, IMessageSink sink=null, ParsingMode mode=null, ILNodePrinterOptions options=null)
 Serializes the specified syntax tree to a StringBuilder in the syntax supported by this object. More...
 
void Print (IEnumerable< LNode > nodes, StringBuilder target, IMessageSink sink=null, ParsingMode mode=null, ILNodePrinterOptions options=null)
 Serializes a list of syntax trees to a StringBuilder in the syntax supported by this object. More...
 
ILexer< TokenTokenize (ICharSource text, string fileName, IMessageSink msgs)
 Returns a lexer that is configured to begin reading the specified file. More...
 
IListSource< LNodeParse (ICharSource text, string fileName, IMessageSink msgs, ParsingMode inputType=null, bool preserveComments=true)
 Parses a source file into one or more Loyc trees. More...
 
IListSource< LNodeParse (ILexer< Token > input, IMessageSink msgs, ParsingMode inputType=null, bool preserveComments=true)
 If HasTokenizer is true, this method accepts a lexer returned by Tokenize() and begins parsing. More...
 
IListSource< LNodeParse (IListSource< Token > input, ISourceFile file, IMessageSink msgs, ParsingMode inputType=null)
 Parses a token tree, such as one that came from a token literal. More...
 

Member Function Documentation

IListSource<LNode> Loyc.Ecs.EcsLanguageService.Parse ( ICharSource  text,
string  fileName,
IMessageSink  msgs,
ParsingMode  mode = null,
bool  preserveComments = true 
)
inline

Parses a source file into one or more Loyc trees.

Parameters
textinput file or string.
fileNameA file name to associate with errors, warnings, and output nodes.
msgsError and warning messages are sent to this object.
modeIndicates the kind of input, e.g. File (an entire source file), FormalArguments (function parameter list), etc. null is a synonym for File.
preserveCommentsWhether to preserve comments and newlines by attaching trivia attributes to the output. If the property CanPreserveComments is false, this parameter will not work.

Implements Loyc.Syntax.IParsingService.

IListSource<LNode> Loyc.Ecs.EcsLanguageService.Parse ( ILexer< Token input,
IMessageSink  msgs,
ParsingMode  mode = null,
bool  preserveComments = true 
)
inline

If HasTokenizer is true, this method accepts a lexer returned by Tokenize() and begins parsing.

Parameters
inputA source of tokens.
msgsError and warning messages are sent to this object. If this parameter is null, messages should be sent to MessageSink.Default.
modeIndicates how the input should be parsed. null is a synonym for ParsingMode.File
preserveCommentsWhether to preserve comments and newlines by attaching trivia attributes to the output. If the property CanPreserveComments is false, this parameter will not work.
Exceptions
NotSupportedExceptionHasTokenizer is false.

This method adds any preprocessing steps to the lexer (tree-ification or token preprocessing) that are required by this language before it sends the results to the parser. If possible, the output is computed lazily.

Implements Loyc.Syntax.IParsingService.

References Loyc.Syntax.Lexing.ILexer< Token >.SourceFile.

IListSource<LNode> Loyc.Ecs.EcsLanguageService.Parse ( IListSource< Token tokens,
ISourceFile  file,
IMessageSink  msgs,
ParsingMode  inputType = null 
)
inline

Parses a token tree, such as one that came from a token literal.

Parameters
tokensList of tokens
fileA source file to associate with errors, warnings, and output nodes.
msgsError and warning messages are sent to this object. If this parameter is null, messages should be sent to MessageSink.Default.
inputTypeIndicates how the input should be parsed.

Some languages may offer token literals, which are stored as token trees that can be processed by "macros" or compiler plugins. A macro may wish to parse some of the token literal using the host language's parser (e.g. LLLPG needs to do this), so this method is provided for that purpose.

Exceptions
NotSupportedExceptionThis feature is not supported by this parsing service.

Implements Loyc.Syntax.IParsingService.

References Loyc.Syntax.ParsingMode.Expressions, Loyc.Syntax.ParsingMode.FormalArguments, Loyc.Collections.IListSource< out out T >.TryGet(), and Loyc.Syntax.ParsingMode.Types.

void Loyc.Ecs.EcsLanguageService.Print ( LNode  node,
StringBuilder  target,
IMessageSink  sink = null,
ParsingMode  mode = null,
ILNodePrinterOptions  options = null 
)
inline

Serializes the specified syntax tree to a StringBuilder in the syntax supported by this object.

Parameters
nodeA syntax tree to print.
targetAn output buffer, to which output is appended.
sinkAn object used to print warning and error messages. If this is null, messages are sent to MessageSink.Default.
modeIndicates the context in which the node(s) to be printed should be understood (e.g. is it a statement or an expression?).
optionsA set of options to control printer behavior. If null, an appropriate default set of options should be used. Some languages may support additional option interfaces beyond ILNodePrinterOptions.

Implements Loyc.Syntax.ILNodePrinter.

References Loyc.Ecs.EcsNodePrinter.PrintECSharp(), and Loyc.Ecs.EcsNodePrinter.PrintPlainCSharp().

void Loyc.Ecs.EcsLanguageService.Print ( IEnumerable< LNode nodes,
StringBuilder  target,
IMessageSink  sink = null,
ParsingMode  mode = null,
ILNodePrinterOptions  options = null 
)
inline

Serializes a list of syntax trees to a StringBuilder in the syntax supported by this object.

Parameters
nodesSyntax trees to print.
targetAn output buffer, to which output is appended.
sinkAn object used to print warning and error messages. If this is null, messages are sent to MessageSink.Default.
modeIndicates the context in which the node(s) to be printed should be understood (e.g. is it a statement or an expression?).
optionsA set of options to control printer behavior. If null, an appropriate default set of options should be used. Some languages may support additional option interfaces beyond ILNodePrinterOptions.

Some implementations can simply call LNodePrinter.PrintMultiple.

Implements Loyc.Syntax.ILNodePrinter.

References Loyc.Syntax.LNodePrinter.PrintMultiple().

ILexer<Token> Loyc.Ecs.EcsLanguageService.Tokenize ( ICharSource  text,
string  fileName,
IMessageSink  msgs 
)
inline

Returns a lexer that is configured to begin reading the specified file.

Parameters
textText to be tokenized (e.g. UString)
fileNameFile name to be associated with any errors that occur.
msgsError messages are sent to this object.

The returned lexer should be a "simple" tokenizer. If the language uses tree lexing (in which tokens are grouped by parentheses and braces), the returned lexer should NOT include the grouping process.

It is recommended that the implementation of this method filter out spaces (for best performance) but not comments or newlines. If there is a preprocessor, it should not run.

Implements Loyc.Syntax.IParsingService.