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 | Public Member Functions | List of all members
Loyc.Syntax.IParsingService Interface Reference

An interface that encapsulates the lexer, parser, and printer of a programming language, or a non-programming language that can be represented by Loyc trees. More...


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

Remarks

An interface that encapsulates the lexer, parser, and printer of a programming language, or a non-programming language that can be represented by Loyc trees.

The simplest way to parse code is with the extension method Parse(string, IMessageSink msgs = null, Symbol inputType = null). The simplest way to print is with Print(LNode, IMessageSink)

The ToString() method should return a string that indicates the programming language represented by this object, e.g. "LES 1.0 parser".

Properties

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...
 
LNodePrinter Printer [get]
 Gets a printer delegate that you can use with LNode.Printer and LNode.PushPrinter, or null if there is no corresponding printer available for the parser reresented by this object. More...
 

Public Member Functions

ILexer< TokenTokenize (ICharSource file, string fileName, IMessageSink msgs)
 Returns a lexer that is configured to begin reading the specified file. More...
 
IListSource< LNodeParse (ICharSource file, string fileName, IMessageSink msgs, Symbol inputType=null)
 Parses a source file into one or more Loyc trees. More...
 
IListSource< LNodeParse (ILexer< Token > input, IMessageSink msgs, Symbol inputType=null)
 If HasTokenizer is true, this method accepts a lexer returned by Tokenize() and begins parsing. More...
 
IListSource< LNodeParse (IListSource< Token > tokens, ISourceFile file, IMessageSink msgs, Symbol inputType)
 Parses a token tree, such as one that came from a token literal. More...
 
string Print (LNode node, IMessageSink msgs=null, object mode=null, string indentString="\t", string lineSeparator="\n")
 Converts the specified syntax tree to a string. More...
 

Member Function Documentation

IListSource<LNode> Loyc.Syntax.IParsingService.Parse ( ICharSource  file,
string  fileName,
IMessageSink  msgs,
Symbol  inputType = null 
)

Parses a source file into one or more Loyc trees.

Parameters
fileinput file or string.
msgsoutput sink for error and warning messages.
inputTypeIndicates the kind of input: Exprs (one or more expressions, typically seprated by commas but this is language- defined), Stmts (a series of statements), or File (an entire source file). null is a synonym for File.

Implemented in Loyc.Ecs.EcsLanguageService, and Loyc.Syntax.Les.LesLanguageService.

IListSource<LNode> Loyc.Syntax.IParsingService.Parse ( ILexer< Token input,
IMessageSink  msgs,
Symbol  inputType = null 
)

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

Parameters
msgsoutput sink for error and warning messages.
inputTypeIndicates how the input should be interpreted: ParsingService.File, ParsingService.Exprs or ParsingService.Stmts. The default input type should be File.
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.

Implemented in Loyc.Ecs.EcsLanguageService, and Loyc.Syntax.Les.LesLanguageService.

IListSource<LNode> Loyc.Syntax.IParsingService.Parse ( IListSource< Token tokens,
ISourceFile  file,
IMessageSink  msgs,
Symbol  inputType 
)

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

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.

Implemented in Loyc.Ecs.EcsLanguageService, and Loyc.Syntax.Les.LesLanguageService.

string Loyc.Syntax.IParsingService.Print ( LNode  node,
IMessageSink  msgs = null,
object  mode = null,
string  indentString = "\t",
string  lineSeparator = "\n" 
)

Converts the specified syntax tree to a string.

Parameters
nodeA syntax tree to print.
msgsIf errors or warnings occur during printing, they are sent here. If this is null, messages shall be sent to MessageSink.Current.
modeLanguage-defined configuration. It is suggested that the printing service should accept ParsingService.Exprs, ParsingService.Stmts and ParsingService.File as possible printing modes.
indentStringIndent character for multi-line nodes
lineSeparatorNewline string for multi-line nodes

Implemented in Loyc.Ecs.EcsLanguageService, and Loyc.Syntax.Les.LesLanguageService.

ILexer<Token> Loyc.Syntax.IParsingService.Tokenize ( ICharSource  file,
string  fileName,
IMessageSink  msgs 
)

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

Parameters
fileText 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, and it should not remove comments, although it may skip spaces and perhaps newlines. If there is a preprocessor, it should not run.

Implemented in Loyc.Ecs.EcsLanguageService, and Loyc.Syntax.Les.LesLanguageService.

Property Documentation

IEnumerable<string> Loyc.Syntax.IParsingService.FileExtensions
get

Standard file extensions for this language, without leading dots, with the first one being the most common.

bool Loyc.Syntax.IParsingService.HasTokenizer
get

Returns true if the Tokenize() method is available.

LNodePrinter Loyc.Syntax.IParsingService.Printer
get

Gets a printer delegate that you can use with LNode.Printer and LNode.PushPrinter, or null if there is no corresponding printer available for the parser reresented by this object.