[STAThread] // Required by ICSharpCode.TextEditor public static void Main(string[] args) { BMultiMap <string, string> options = new BMultiMap <string, string>(); var argList = args.ToList(); UG.ProcessCommandLineArguments(argList, options, "", ShortOptions, TwoArgOptions); if (!options.ContainsKey("nologo")) { Console.WriteLine("LeMP macro compiler (beta)"); } string _; if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _)) { ShowHelp(KnownOptions.OrderBy(p => p.Key)); return; } if (options.ContainsKey("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; } Severity minSeverity = Severity.Note; #if DEBUG minSeverity = Severity.Debug; #endif var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity); Compiler c = ProcessArguments(options, filter, typeof(BuiltinMacros), argList); Compiler.WarnAboutUnknownOptions(options, MessageSink.Console, KnownOptions); if (c != null) { c.AddMacros(typeof(global::LeMP.StandardMacros).Assembly); c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude")); c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP")); using (LNode.PushPrinter(EcsNodePrinter.PrintPlainCSharp)) c.Run(); } else if (args.Length == 0) { ShowHelp(KnownOptions.OrderBy(p => p.Key)); } }
[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(); } }
public static void Main(string[] args) { BMultiMap <string, string> options = new BMultiMap <string, string>(); var argList = args.ToList(); UG.ProcessCommandLineArguments(argList, options, "", ShortOptions, TwoArgOptions); if (!options.ContainsKey("nologo")) { Console.WriteLine("LeMP macro compiler (pre-alpha)"); } string _; if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _)) { ShowHelp(KnownOptions.OrderBy(p => p.Key)); return; } Severity minSeverity = Severity.Note; #if DEBUG minSeverity = Severity.Debug; #endif var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity); Compiler c = ProcessArguments(argList, options, filter, typeof(Macros)); Compiler.WarnAboutUnknownOptions(options, MessageSink.Console, KnownOptions); if (c != null) { c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude")); using (LNode.PushPrinter(Ecs.EcsNodePrinter.PrintPlainCSharp)) c.Run(); } else if (args.Length == 0) { Console.WriteLine("Running unit tests..."); RunTests.Run(new Loyc.Syntax.Les.LesLexerTests()); RunTests.Run(new Loyc.Syntax.Les.LesParserTests()); RunLeMPTests(); Ecs.Program.RunEcsTests(); } }
[STAThread] // Required by ICSharpCode.TextEditor public static void Main(string[] args) { BMultiMap <string, string> options = new BMultiMap <string, string>(); var argList = args.ToList(); UG.ProcessCommandLineArguments(argList, options, "", ShortOptions, TwoArgOptions); if (!options.ContainsKey("nologo")) { Console.WriteLine("LeMP macro compiler (pre-alpha)"); } string _; if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _)) { ShowHelp(KnownOptions.OrderBy(p => p.Key)); return; } if (options.ContainsKey("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; } Severity minSeverity = Severity.Note; #if DEBUG minSeverity = Severity.Debug; #endif var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity); Compiler c = ProcessArguments(options, filter, typeof(Macros), argList); Compiler.WarnAboutUnknownOptions(options, MessageSink.Console, KnownOptions); if (c != null) { c.AddMacros(typeof(global::LeMP.StandardMacros).Assembly); c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude")); c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP")); using (LNode.PushPrinter(Ecs.EcsNodePrinter.PrintPlainCSharp)) c.Run(); } else if (args.Length == 0) { ShowHelp(KnownOptions.OrderBy(p => p.Key)); Console.WriteLine(); Console.WriteLine("LeMP started without arguments. Starting editor (--editor)"); var thread = new ThreadEx(() => { System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.Run(new TextEditor.LempDemoForm()); }); thread.Thread.SetApartmentState(ApartmentState.STA); thread.Start(); Console.WriteLine("Press Enter to run unit tests. Using the editor? Keep the terminal open."); Console.ReadLine(); RunTests.Run(new Loyc.Syntax.Lexing.TokenTests()); RunTests.Run(new Loyc.Syntax.Les.LesLexerTests()); RunTests.Run(new Loyc.Syntax.Les.LesParserTests()); RunTests.Run(new Loyc.Syntax.Les.LesPrinterTests()); RunLeMPTests(); Ecs.Program.RunEcsTests(); } }
[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; } }
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 var options = new BMultiMap<string, string>(); var argList = G.SplitCommandLineArguments(defaultNamespace); UG.ProcessCommandLineArguments(argList, options, "", LeMP.Compiler.ShortOptions, LeMP.Compiler.TwoArgOptions); string _; var KnownOptions = LeMP.Compiler.KnownOptions; if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _)) LeMP.Compiler.ShowHelp(KnownOptions); // 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, Path.GetFileName(inputFilePath)); var c = new Compiler(sink, sourceFile) { AbortTimeout = TimeSpan.FromSeconds(10), Parallel = false // only one file, parallel doesn't help }; if (LeMP.Compiler.ProcessArguments(c, options)) { if (options.ContainsKey("no-out-header")) { options.Remove("no-out-header", 1); c.NoOutHeader = true; } LeMP.Compiler.WarnAboutUnknownOptions(options, sink, KnownOptions); if (c != null) { if (inputFilePath.EndsWith(".les", StringComparison.OrdinalIgnoreCase)) c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude.Les")); Configure(c); 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()); } } return null; } finally { Environment.CurrentDirectory = oldCurDir; } }