Enhanced C#
Language of your choice: library documentation
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, IParsingServiceRegisteredLanguages [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< IParsingServiceSetDefault (IParsingService newValue)
 
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

◆ GetServiceForFileName()

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.

References Loyc.Syntax.ParsingService.RegisteredLanguages.

Referenced by LeMP.Compiler.ProcessArguments().

◆ Parse() [1/3]

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.

References Loyc.Syntax.IParsingService.Parse().

◆ Parse() [2/3]

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.

References Loyc.Syntax.IParsingService.Parse().

◆ Parse() [3/3]

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

◆ ParseFile()

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, and Loyc.Syntax.ParsingService.Parse().

◆ ParseSingle() [1/2]

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.

References Loyc.Syntax.IParsingService.Parse().

◆ ParseSingle() [2/2]

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.

References Loyc.Syntax.ParsingService.Parse().

◆ PushCurrent()

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;");

◆ Register()

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.

References Loyc.Collections.Map< K, V >.With().

◆ Tokenize() [1/3]

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

◆ Tokenize() [2/3]

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

Parses a Stream.

References Loyc.Syntax.IParsingService.Tokenize().

◆ Tokenize() [3/3]

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

◆ TokenizeFile()

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

Opens the specified file and tokenizes it.

References Loyc.Syntax.ParsingService.Tokenize().

◆ Unregister()

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.

References Loyc.Syntax.IParsingService.FileExtensions, and Loyc.Collections.Map< K, V >.Without().

Property Documentation

◆ Default

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.

◆ RegisteredLanguages

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)

Referenced by Loyc.Syntax.ParsingService.GetServiceForFileName().