public ProcessArguments ( IList |
||
args | IList |
Arg list from which to extract options. **NOTE**: /// discovered options are removed from the list. This parameter /// cannot be an array. |
warnAboutUnknownOptions | bool | Whether this method should
/// call |
autoOpenInputFiles | bool | Whether to open input files
/// for you by calling |
inputFiles | IList |
A 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. |
리턴 | string>.BMultiMap |
public static Compiler ProcessArguments(BMultiMap <string, string> options, SeverityMessageFilter sink, Type prelude, List <string> inputFiles) { if (inputFiles.Count == 0) { sink.Write(Severity.Error, null, "No input provided, stopping."); return(null); } Compiler c = new Compiler(sink, prelude); c.Files = new List <InputOutput>(OpenSourceFiles(sink, inputFiles)); return(c.ProcessArguments(options) ? c : null); }
[STAThread] // Required by ICSharpCode.TextEditor public static void Main(string[] args) { if (!args.Contains("--nologo")) { Console.WriteLine("LeMP macro compiler ({0})", typeof(Compiler).Assembly.GetName().Version.ToString()); } Severity minSeverity = Severity.NoteDetail; #if DEBUG minSeverity = Severity.DebugDetail; #endif var filter = new SeverityMessageFilter(ConsoleMessageSink.Value, minSeverity); Compiler c = new Compiler(filter, typeof(BuiltinMacros)); var argList = args.ToList(); var options = c.ProcessArguments(argList, false, true); if (options == null) { return; // error occurred, message should have printed already } if (!MaybeShowHelp(options, KnownOptions)) { WarnAboutUnknownOptions(options, filter, KnownOptions); if (c.Files.Count == 0) { Console.WriteLine(); filter.Error(null, "No input files provided, stopping. Add --help for usage info.".Localized()); if (!options.ContainsKey("nologo")) { // Give users a simple way to find out which copy they're using: // Windows doesn't have `which` and the dotnet tools version of // LeMP.exe is not the real one anyway (it's not a .NET module) Console.WriteLine("You're using {0}".Localized(typeof(MacroProcessor).Assembly.Location)); Console.WriteLine(" ({0})".Localized(typeof(MacroProcessor).Assembly.FullName)); } return; } else { using (LNode.SetPrinter(EcsLanguageService.WithPlainCSharpPrinter)) c.Run(); } } }
[STAThread] // Required by ICSharpCode.TextEditor public static void Main(string[] args) { if (!args.Contains("--nologo")) { Console.WriteLine("LeMP macro compiler ({0})", typeof(Compiler).Assembly.GetName().Version.ToString()); } if (args.Contains("--editor")) { Console.WriteLine("Starting editor..."); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(new TextEditor.LempDemoForm()); return; } KnownOptions["editor"] = Pair.Create("", "Show built-in text editor"); Severity minSeverity = Severity.NoteDetail; #if DEBUG minSeverity = Severity.DebugDetail; #endif var filter = new SeverityMessageFilter(ConsoleMessageSink.Value, minSeverity); Compiler c = new Compiler(filter, typeof(BuiltinMacros)); var argList = args.ToList(); var options = c.ProcessArguments(argList, false, true); if (options == null) { return; // error occurred, message should have printed already } if (argList.Count == 0) { filter.Error(null, "No input files provided, stopping."); return; } if (!MaybeShowHelp(options, KnownOptions)) { WarnAboutUnknownOptions(options, filter, KnownOptions.With("nologo", Pair.Create("", ""))); using (LNode.SetPrinter(EcsLanguageService.WithPlainCSharpPrinter)) c.Run(); } }
[STAThread] // Required by ICSharpCode.TextEditor public static void Main(string[] args) { if (!args.Contains("--nologo")) Console.WriteLine("LeMP macro compiler ({0})", typeof(Compiler).Assembly.GetName().Version.ToString()); if (args.Contains("--editor")) { Console.WriteLine("Starting editor..."); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(new TextEditor.LempDemoForm()); return; } KnownOptions["editor"] = Pair.Create("", "Show built-in text editor"); Severity minSeverity = Severity.Note; #if DEBUG minSeverity = Severity.Debug; #endif var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity); Compiler c = new Compiler(filter, typeof(BuiltinMacros)); var argList = args.ToList(); var options = c.ProcessArguments(argList, false, true); if (argList.Count == 0) { filter.Write(Severity.Error, null, "No input files provided, stopping."); return; } if (!MaybeShowHelp(options, KnownOptions)) { WarnAboutUnknownOptions(options, filter, KnownOptions.With("nologo", Pair.Create("", ""))); using (LNode.PushPrinter(EcsNodePrinter.PrintPlainCSharp)) c.Run(); } }
protected override byte[] Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IVsGeneratorProgress progressCallback) { string oldCurDir = Environment.CurrentDirectory; try { string inputFolder = Path.GetDirectoryName(inputFilePath); Environment.CurrentDirectory = inputFolder; // --macros should be relative to file being processed // Originally I wrote a conversion from IVsGeneratorProgress to // IMessageSink so that errors could be reported immediately and // directly to Visual Studio. This broke in a bizarre way when I // added processing on a separate thread (in order to be able to // abort the thread if it runs too long); I got the following // InvalidCastException: "Unable to cast COM object of type 'System.__ComObject' // to interface type 'Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress'. // This operation failed because the QueryInterface call on the COM component for // the interface with IID '{BED89B98-6EC9-43CB-B0A8-41D6E2D6669D}' failed due to // the following error: No such interface supported (Exception from HRESULT: // 0x80004002 (E_NOINTERFACE))." // // A simple solution is to store the messages rather than reporting // them immediately. I'll report the errors at the very end. MessageHolder sink = new MessageHolder(); var sourceFile = new InputOutput((UString)inputFileContents, inputFilePath); Compiler.KnownOptions["no-out-header"] = Pair.Create("", "Remove explanatory comment from output file"); Compiler.KnownOptions.Remove("parallel"); // not applicable to single file Compiler.KnownOptions.Remove("noparallel"); // not applicable to single file var c = new Compiler(sink, sourceFile) { AbortTimeout = TimeSpan.FromSeconds(10), Parallel = false // only one file, parallel doesn't help }; var argList = G.SplitCommandLineArguments(defaultNamespace); var options = c.ProcessArguments(argList, true, false); // Note: if default namespace is left blank, VS uses the namespace // from project settings. Don't show an error in that case. if (argList.Count > 1 || (argList.Count == 1 && options.Count > 0)) sink.Write(Severity.Error, "Command line", "'{0}': expected options only (try --help).", argList[0]); string _; if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _)) { var ms = new MemoryStream(); LeMP.Compiler.ShowHelp(LeMP.Compiler.KnownOptions, new StreamWriter(ms), false); return ms.GetBuffer(); } LeMP.Compiler.WarnAboutUnknownOptions(options, sink, LeMP.Compiler.KnownOptions); if (options.ContainsKey("no-out-header")) c.NoOutHeader = true; if (c.InLang == LesLanguageService.Value || inputFilePath.EndsWith(".les", StringComparison.OrdinalIgnoreCase)) c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude.Les")); Configure(c); _requestedExtension = c.OutExt; c.Run(); // Report errors foreach (var msg in sink.List) ReportErrorToVS(progressCallback, msg.Severity, msg.Context, msg.Format, msg.Args); return Encoding.UTF8.GetBytes(c.Output.ToString()); } finally { Environment.CurrentDirectory = oldCurDir; } }