Enhanced C#
Language of your choice: library documentation
Public fields | Public static fields | Properties | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
LeMP.Compiler Class Reference

A class that helps you invoke MacroProcessor on on a set of source files, given a set of command-line options. More...


Source file:
Inheritance diagram for LeMP.Compiler:
LeMP.TestCompiler Loyc.LLParserGenerator.LlpgGeneralTestsBase.TestCompiler

Remarks

A class that helps you invoke MacroProcessor on on a set of source files, given a set of command-line options.

This class helps you process command-line options (see ProcessArguments(IList<string>, bool, bool, IList<string>)), complete InputOutput objects based on those options (see CompleteInputOutputOptions), and add macros from Assemblies (AddMacros and AddStdMacros).

Public fields

List< InputOutputFiles
 
bool Parallel = true
 
string IndentString = "\t"
 
string NewlineString = "\n"
 
MacroProcessor MacroProcessor
 
IParsingService InLang
 
bool PreserveComments = true
 
ParsingMode ParsingMode = ParsingMode.File
 
ILNodePrinter OutLang
 
LNodePrinterOptions OutOptions = new LNodePrinterOptions { IndentString = "\t", NewlineString = "\n" }
 
string OutExt
 
bool ForceInLang
 

Public static fields

static InvertibleSet< string > TwoArgOptions = new InvertibleSet<string>(new[] { "macros" })
 
static Dictionary< char, string > ShortOptions
 
static MMap< string, Pair< string, string > > KnownOptions
 

Properties

IMessageSink Sink [get, set]
 
int MaxExpansions [get, set]
 
TimeSpan AbortTimeout [get, set]
 
bool Verbose [get]
 

Public Member Functions

 Compiler (IMessageSink sink, Type prelude=null, bool registerEcsAndLes=true)
 
 Compiler (IMessageSink sink, Type prelude, IEnumerable< InputOutput > sourceFiles)
 
BMultiMap< string, string > ProcessArguments (IList< string > args, bool warnAboutUnknownOptions, bool autoOpenInputFiles, IList< string > inputFiles=null)
 Processes command-line arguments to build a BMultiMap and sends those options to the other overload of this method. More...
 
bool ProcessArguments (BMultiMap< string, string > options, bool warnAboutUnknownOptions, IList< string > inputFiles=null)
 Processes all standard command-line arguments from KnownOptions, except –help. More...
 
void AddStdMacros ()
 Adds standard macros from LeMP.StdMacros.dll, and adds the namespaces LeMP and LeMP.Prelude to the pre-opened namespace list. More...
 
void CompleteInputOutputOptions ()
 Fills in all fields of Files that are still null, based on the command-line options. Calling this is optional, since Run() calls it anyway. More...
 
void CompleteInputOutputOptions (InputOutput file)
 
bool AddMacros (Assembly assembly)
 
void Run ()
 Runs the MacroProcessor on all input Files. More...
 

Static Public Member Functions

static void Main (string[] args)
 
static void WarnAboutUnknownOptions (BMultiMap< string, string > options, IMessageSink sink, IDictionary< string, Pair< string, string >> knownOptions)
 
static bool MaybeShowHelp (ICollection< KeyValuePair< string, string >> options, ICollection< KeyValuePair< string, Pair< string, string >>> knownOptions, TextWriter @out=null)
 
static void ShowHelp (IEnumerable< KeyValuePair< string, Pair< string, string >>> knownOptions, TextWriter @out=null, bool includeUsageLine=true)
 
static List< InputOutputOpenSourceFiles (IMessageSink sink, IEnumerable< string > fileNames)
 Opens a set of source files by file name, and creates a text file for each. More...
 

Protected Member Functions

virtual void WriteOutput (InputOutput io)
 

Member Function Documentation

void LeMP.Compiler.AddStdMacros ( )
inline
void LeMP.Compiler.CompleteInputOutputOptions ( )
inline

Fills in all fields of Files that are still null, based on the command-line options. Calling this is optional, since Run() calls it anyway.

References Loyc.Syntax.ParsingService.Current, Loyc.Syntax.ParsingService.GetServiceForFileName(), and Loyc.Syntax.LNode.Printer.

Referenced by LeMP.Compiler.Run().

static List<InputOutput> LeMP.Compiler.OpenSourceFiles ( IMessageSink  sink,
IEnumerable< string >  fileNames 
)
inlinestatic

Opens a set of source files by file name, and creates a text file for each.

Parameters
sink
fileNames
Returns

Referenced by LeMP.Compiler.ProcessArguments().

BMultiMap<string, string> LeMP.Compiler.ProcessArguments ( IList< string >  args,
bool  warnAboutUnknownOptions,
bool  autoOpenInputFiles,
IList< string >  inputFiles = null 
)
inline

Processes command-line arguments to build a BMultiMap and sends those options to the other overload of this method.

Parameters
argsArg list from which to extract options. NOTE: discovered options are removed from the list. This parameter cannot be an array.
warnAboutUnknownOptionsWhether this method should call WarnAboutUnknownOptions for you.
autoOpenInputFilesWhether to open input files for you by calling OpenSourceFiles(IMessageSink, IEnumerable<string>).
inputFilesA list of input files to open if autoOpenInputFiles is true. If this is null, The input files are assumed to be those command-line arguments left over after the options are removed.
Returns
The map of options (key-value pairs and, for options that don't have a value, key-null pairs).

Note: If you get your command-line arguments as a single string, use G.SplitCommandLineArguments(string) first to split it into an array.

This method doesn't check for –help. To implement –help, call MaybeShowHelp on the return value.

References Loyc.Utilities.UG.ProcessCommandLineArguments().

bool LeMP.Compiler.ProcessArguments ( BMultiMap< string, string >  options,
bool  warnAboutUnknownOptions,
IList< string >  inputFiles = null 
)
inline

Processes all standard command-line arguments from KnownOptions, except –help.

Parameters
optionsA set of options, presumably derived from command- line options using UG.ProcessCommandLineArguments
warnAboutUnknownOptionsWhether to warn (to Sink) about options not listed in KnownOptions.
inputFilesFiles to open with OpenSourceFiles
Returns
true, unless inputFiles != null and all input files failed to open.

This method calls AddStdMacros() unless options includes "nostdmacros".

References LeMP.Compiler.AddStdMacros(), Loyc.Syntax.ParsingService.GetServiceForFileName(), LeMP.Compiler.OpenSourceFiles(), and Loyc.Collections.BMultiMap< K, V >.TryGetValue().

void LeMP.Compiler.Run ( )
inline

Member Data Documentation

MMap<string, Pair<string, string> > LeMP.Compiler.KnownOptions
static
Initial value:
= new MMap<string, Pair<string, string>>()
{
{ "help", Pair.Create("", "show this screen") },
{ "macros", Pair.Create("filename.dll", "load macros from given assembly") },
{ "max-expand",Pair.Create("N", "stop expanding macros after N nested or iterated expansions.") },
{ "verbose", Pair.Create("", "Print extra status messages (e.g. discovered Types, list output files).") },
{ "parallel", Pair.Create("", "Process all files in parallel (this is the default)") },
{ "noparallel",Pair.Create("", "Process all files in sequence") },
{ "inlang", Pair.Create("name", "Set input language: --inlang=ecs for Enhanced C#, --inlang=les for LES") },
{ "outext", Pair.Create("name", "Set output extension and optional suffix:\n .ecs (Enhanced C#), .cs (C#), .les (LES)\n"+
"This can include a suffix before the extension, e.g. --outext=.output.cs\n"+
"If --outlang is not used, output language is chosen by file extension.") },
{ "outlang", Pair.Create("name", "Set output language independently of file extension") },
{ "forcelang", Pair.Create("", "Specifies that --inlang overrides the input file extension.\n"+
"Without this option, known file extensions override --inlang.") },
{ "timeout", Pair.Create("N", "Aborts the processing thread(s) after this many seconds (0=never)") },
{ "nostdmacros", Pair.Create("", "Don't scan LeMP.StdMacros.dll or pre-import LeMP and LeMP.Prelude") },
{ "set", Pair.Create("key=literal", "Associate a value with a key (use #get(key) to read it back)") },
{ "snippet", Pair.Create("key=code", "Associate code with a key (use #get(key) to read it back)") },
{ "preserve-comments", Pair.Create("bool", "Preserve comments and newlines (where supported)\n Default value: true") },
{ "o-indent-spaces", Pair.Create("count", "Sets number of spaces per indentation level (0 for tabs)") },
{ "o-allow-change-parens", Pair.Create("bool", "Sets ILNodePrintingOptions.AllowChangeParentheses") },
{ "o-omit-comments", Pair.Create("bool", "Sets ILNodePrintingOptions.OmitComments") },
{ "o-omit-unknown-trivia", Pair.Create("bool", "Sets ILNodePrintingOptions.OmitUnknownTrivia") },
{ "o-explicit-trivia", Pair.Create("bool", "Sets ILNodePrintingOptions.PrintTriviaExplicitly") },
{ "o-compatibility-mode", Pair.Create("bool", "Sets ILNodePrintingOptions.CompatibilityMode") },
{ "o-compact-mode", Pair.Create("bool", "Sets ILNodePrintingOptions.CompactMode") },
}
Dictionary<char, string> LeMP.Compiler.ShortOptions
static
Initial value:
= new Dictionary<char,string>()
{ {'o',"out"}, {'m',"macros"}, {'p',"preserve-comments"}, {'e',"editor"} }