Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Nested classes | Properties | Static Public Member Functions | List of all members
Loyc.Syntax.ParsingService Class Reference

Standard extension methods for IParsingService. More...


Source file:

Remarks

Standard extension methods for IParsingService.

Nested classes

struct  PushedCurrent
 Returned by PushCurrent(IParsingService). More...
 

Properties

static IParsingService Default [get, set]
 Gets or sets the default language service on this thread. If no service has been assigned on this thread, returns Les2LanguageService.Value. More...
 
static IParsingService Current [get, set]
 
static IReadOnlyDictionary
< string, IParsingService
RegisteredLanguages [get]
 Dictionary of registered parsing services, keyed by file extension (without leading dots). The default dictionary contains one pair: ("les", LesLanguageService.Value) More...
 

Static Public Member Functions

static SavedValue
< IParsingService
SetDefault (IParsingService newValue)
 Sets the current language service, returning a value suitable for use in a C# using statement, which will restore the old service. More...
 
static int Register (IParsingService service, IEnumerable< string >?fileExtensions=null)
 Registers a parsing service. More...
 
static int Unregister (IParsingService service, IEnumerable< string >?fileExtensions=null)
 Unregisters a language service. More...
 
static IParsingService GetServiceForFileName (string filename)
 Finds the language service associated with the longest matching registered file extension. More...
 
static PushedCurrent PushCurrent (IParsingService newValue)
 Sets the current language service, returning a value suitable for use in a C# using statement, which will restore the old service. More...
 
static ILexer< TokenTokenize (this IParsingService parser, UString input, IMessageSink?msgs=null)
 Parses a string by invoking IParsingService.Tokenize(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name. More...
 
static ILexer< TokenTokenize (this IParsingService parser, ICharSource text, string fileName, IMessageSink?msgs=null)
 Parses a string by invoking IParsingService.Tokenize(ICharSource, string, IMessageSink, IParsingOptions) using default options. More...
 
static IListSource< LNodeParse (this IParsingService parser, UString input, IMessageSink?msgs=null, ParsingMode?inputType=null, bool preserveComments=true)
 Parses a string by invoking IParsingService.Parse(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name. More...
 
static IListSource< LNodeParse (this IParsingService parser, UString input, IMessageSink?msgs, IParsingOptions?options)
 Parses a string by invoking IParsingService.Parse(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name. More...
 
static IListSource< LNodeParse (this IParsingService parser, ICharSource text, string fileName, IMessageSink?msgs=null, ParsingMode?inputType=null, bool preserveComments=true)
 
static IListSource< LNodeParse (this IParsingService parser, ILexer< Token > input, IMessageSink?msgs=null, ParsingMode?mode=null, bool preserveComments=true)
 
static IListSource< LNodeParse (this IParsingService parser, IListSource< Token > tokens, ISourceFile file, IMessageSink?msgs, ParsingMode?inputType=null)
 
static LNode ParseSingle (this IParsingService parser, UString expr, IMessageSink?msgs=null, ParsingMode?inputType=null, bool preserveComments=true)
 
static LNode ParseSingle (this IParsingService parser, UString expr, IMessageSink?msgs, IParsingOptions?options)
 Parses a string and expects exactly one output. More...
 
static LNode ParseSingle (this IParsingService parser, ICharSource text, string fileName, IMessageSink?msgs=null, ParsingMode?inputType=null, bool preserveComments=true)
 
static LNode ParseSingle (this IParsingService parser, ICharSource text, string fileName, IMessageSink?msgs=null, IParsingOptions?options=null)
 Parses a string and expects exactly one output. More...
 
static IListSource< LNodeParse (this IParsingService parser, Stream stream, string fileName, ParsingMode?inputType=null, IMessageSink?msgs=null, bool preserveComments=true)
 Parses a Stream. More...
 
static ILexer< TokenTokenize (this IParsingService parser, Stream stream, string fileName, IMessageSink?msgs=null)
 Parses a Stream. More...
 
static IListSource< LNodeParseFile (this IParsingService parser, string fileName, IMessageSink?msgs=null, ParsingMode?inputType=null, bool preserveComments=true)
 Opens the specified file, parses the entire file, and closes the file. More...
 
static ILexer< TokenTokenizeFile (this IParsingService parser, string fileName, IMessageSink?msgs=null)
 Opens the specified file and tokenizes it. More...
 

Member Function Documentation

static IParsingService Loyc.Syntax.ParsingService.GetServiceForFileName ( string  filename)
inlinestatic

Finds the language service associated with the longest matching registered file extension.

Returns null if there is no registered language service for the filename's extension.

static IListSource<LNode> Loyc.Syntax.ParsingService.Parse ( this IParsingService  parser,
UString  input,
IMessageSink msgs = null,
ParsingMode inputType = null,
bool  preserveComments = true 
)
inlinestatic

Parses a string by invoking IParsingService.Parse(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name.

static IListSource<LNode> Loyc.Syntax.ParsingService.Parse ( this IParsingService  parser,
UString  input,
IMessageSink msgs,
IParsingOptions options 
)
inlinestatic

Parses a string by invoking IParsingService.Parse(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name.

static IListSource<LNode> Loyc.Syntax.ParsingService.Parse ( this IParsingService  parser,
Stream  stream,
string  fileName,
ParsingMode inputType = null,
IMessageSink msgs = null,
bool  preserveComments = true 
)
inlinestatic

Parses a Stream.

static IListSource<LNode> Loyc.Syntax.ParsingService.ParseFile ( this IParsingService  parser,
string  fileName,
IMessageSink msgs = null,
ParsingMode inputType = null,
bool  preserveComments = true 
)
inlinestatic

Opens the specified file, parses the entire file, and closes the file.

References Loyc.Syntax.ParsingMode.File.

static LNode Loyc.Syntax.ParsingService.ParseSingle ( this IParsingService  parser,
UString  expr,
IMessageSink msgs,
IParsingOptions options 
)
inlinestatic

Parses a string and expects exactly one output.

Exceptions
InvalidOperationExceptionThe output list was empty or contained multiple nodes.
static LNode Loyc.Syntax.ParsingService.ParseSingle ( this IParsingService  parser,
ICharSource  text,
string  fileName,
IMessageSink msgs = null,
IParsingOptions options = null 
)
inlinestatic

Parses a string and expects exactly one output.

Exceptions
InvalidOperationExceptionThe output list was empty or contained multiple nodes.
static PushedCurrent Loyc.Syntax.ParsingService.PushCurrent ( IParsingService  newValue)
inlinestatic

Sets the current language service, returning a value suitable for use in a C# using statement, which will restore the old service.

Parameters
newValuenew value of Current

LNode code; using (var old = ParsingService.PushCurrent(LesLanguageService.Value)) code = ParsingService.Current.ParseSingle("This `is` LES_code;");

static int Loyc.Syntax.ParsingService.Register ( IParsingService  service,
IEnumerable< string >?  fileExtensions = null 
)
inlinestatic

Registers a parsing service.

Parameters
serviceService to register.
fileExtensionsFile extensions affected (null to use the service's own list)
Returns
The number of new file extensions registered, or 0 if none.

This method does not replace existing registrations.

static SavedValue<IParsingService> Loyc.Syntax.ParsingService.SetDefault ( IParsingService  newValue)
inlinestatic

Sets the current language service, returning a value suitable for use in a C# using statement, which will restore the old service.

Parameters
newValuenew value of Default

LNode code; using (ParsingService.SetDefault(LesLanguageService.Value)) code = ParsingService.Default.ParseSingle("This `is` LES_code;");

static ILexer<Token> Loyc.Syntax.ParsingService.Tokenize ( this IParsingService  parser,
UString  input,
IMessageSink msgs = null 
)
inlinestatic

Parses a string by invoking IParsingService.Tokenize(ICharSource, string, IMessageSink, IParsingOptions) using an empty string as the file name.

static ILexer<Token> Loyc.Syntax.ParsingService.Tokenize ( this IParsingService  parser,
ICharSource  text,
string  fileName,
IMessageSink msgs = null 
)
inlinestatic

Parses a string by invoking IParsingService.Tokenize(ICharSource, string, IMessageSink, IParsingOptions) using default options.

static ILexer<Token> Loyc.Syntax.ParsingService.Tokenize ( this IParsingService  parser,
Stream  stream,
string  fileName,
IMessageSink msgs = null 
)
inlinestatic

Parses a Stream.

static ILexer<Token> Loyc.Syntax.ParsingService.TokenizeFile ( this IParsingService  parser,
string  fileName,
IMessageSink msgs = null 
)
inlinestatic

Opens the specified file and tokenizes it.

static int Loyc.Syntax.ParsingService.Unregister ( IParsingService  service,
IEnumerable< string >?  fileExtensions = null 
)
inlinestatic

Unregisters a language service.

Parameters
serviceService to unregister
fileExtensionsFile extensions affected (null to use the service's own list)
Returns
The number of file extensions unregistered, or 0 if none.

The service for a file extension is not removed unless the given service reference is equal to the registered service.

Property Documentation

IParsingService Loyc.Syntax.ParsingService.Default
staticgetset

Gets or sets the default language service on this thread. If no service has been assigned on this thread, returns Les2LanguageService.Value.

IReadOnlyDictionary<string, IParsingService> Loyc.Syntax.ParsingService.RegisteredLanguages
staticget

Dictionary of registered parsing services, keyed by file extension (without leading dots). The default dictionary contains one pair: ("les", LesLanguageService.Value)