コード例 #1
0
 protected void Test(string input, string expected, IMessageSink sink = null, IParsingService parser = null)
 {
     using (ParsingService.PushCurrent(parser ?? LesLanguageService.Value))
         using (LNode.PushPrinter(Ecs.EcsNodePrinter.PrintPlainCSharp)) {
             var c = new TestCompiler(sink ?? _sink, new UString(input));
             c.Run();
             Assert.AreEqual(StripExtraWhitespace(expected), StripExtraWhitespace(c.Output.ToString()));
         }
 }
コード例 #2
0
 public static void Test(string input, string output, IMessageSink sink, int maxExpand = 0xFFFF)
 {
     using (LNode.PushPrinter(Ecs.EcsNodePrinter.Printer)) {
         var c = new TestCompiler(sink, new UString(input), "");
         c.MaxExpansions = maxExpand;
         c.MacroProcessor.AbortTimeout = TimeSpan.Zero;                 // never timeout (avoids spawning a new thread)
         c.Run();
         Assert.AreEqual(StripExtraWhitespace(output), StripExtraWhitespace(c.Output.ToString()));
     }
 }
コード例 #3
0
        [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));
            }
        }
コード例 #4
0
ファイル: LempDemoPanel.cs プロジェクト: lydonchandra/Loyc
            protected override void WriteOutput(InputOutput io)
            {
                RVList <LNode> results = io.Output;

                using (LNode.PushPrinter(io.OutPrinter)) {
                    Output.AppendFormat("// Generated from {1} by LeMP {2}.{0}", NewlineString,
                                        io.FileName, typeof(Compiler).Assembly.GetName().Version.ToString());
                    foreach (LNode node in results)
                    {
                        LNode.Printer(node, Output, Sink, null, IndentString, NewlineString);
                        Output.Append(NewlineString);
                    }
                }
            }
コード例 #5
0
ファイル: Program.cs プロジェクト: bel-uwa/Loyc
        public static void Main(params string[] args)
        {
            if (args.Length != 0)
            {
                BMultiMap <string, string> options = new BMultiMap <string, string>();
                IDictionary <string, Pair <string, string> > KnownOptions = LeMP.Compiler.KnownOptions;

                var argList = args.ToList();
                UG.ProcessCommandLineArguments(argList, options, "", LeMP.Compiler.ShortOptions, LeMP.Compiler.TwoArgOptions);
                if (!options.ContainsKey("nologo"))
                {
                    Console.WriteLine("LLLPG/LeMP macro compiler (alpha)");
                }

                string _;
                if (options.TryGetValue("help", out _) || options.TryGetValue("?", out _))
                {
                    LeMP.Compiler.ShowHelp(KnownOptions.OrderBy(p => p.Key));
                    return;
                }

                Severity minSeverity = Severity.Note;
                                #if DEBUG
                minSeverity = Severity.Debug;
                                #endif
                var filter = new SeverityMessageFilter(MessageSink.Console, minSeverity);

                LeMP.Compiler c = LeMP.Compiler.ProcessArguments(argList, options, filter, typeof(LeMP.Prelude.Les.Macros));
                LeMP.Compiler.WarnAboutUnknownOptions(options, MessageSink.Console, KnownOptions);
                if (c != null)
                {
                    c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude"));
                    c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("Loyc.LLParserGenerator"));
                    c.AddMacros(Assembly.GetExecutingAssembly());
                    c.AddMacros(typeof(LeMP.Prelude.Macros).Assembly);
                    using (LNode.PushPrinter(Ecs.EcsNodePrinter.PrintPlainCSharp))
                        c.Run();
                }
            }
            else
            {
                Tests();
                Ecs.Program.Main(args);                 // do EC# tests
            }
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: lydonchandra/Loyc
        public static string QuickRun(IParsingService inputLang, int maxExpand, string input, params Assembly[] macroAssemblies)
        {
            var c = new LeMP.TestCompiler(MessageSink.Trace, new UString(input));

            c.Parallel      = false;
            c.MaxExpansions = maxExpand;
            c.AddMacros(Assembly.GetExecutingAssembly());
            c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude"));
            c.MacroProcessor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude.Les"));
            c.MacroProcessor.PreOpenedNamespaces.Add(Loyc.LLPG.Macros.MacroNamespace);
            foreach (var assembly in macroAssemblies)
            {
                c.AddMacros(assembly);
            }
            using (ParsingService.PushCurrent(inputLang ?? ParsingService.Current))
                using (LNode.PushPrinter(Ecs.EcsNodePrinter.Printer))
                    c.Run();
            return(c.Output.ToString());
        }
コード例 #8
0
        [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();
            }
        }
コード例 #9
0
 protected override byte[] Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IVsGeneratorProgress progressCallback)
 {
     using (LNode.PushPrinter(Loyc.Syntax.Les.LesNodePrinter.Printer))
         return(base.Generate(inputFilePath, inputFileContents, defaultNamespace, progressCallback));
 }
コード例 #10
0
 protected override byte[] Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IVsGeneratorProgress progressCallback)
 {
     using (LNode.PushPrinter(Ecs.EcsNodePrinter.PrintPlainCSharp))
         return(base.Generate(inputFilePath, inputFileContents, defaultNamespace, progressCallback));
 }
コード例 #11
0
        [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();
            }
        }
コード例 #12
0
ファイル: LoycCustomTools.cs プロジェクト: sizzles/ecsharp
 protected override byte[] Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IVsGeneratorProgress progressCallback)
 {
     using (LNode.PushPrinter(LesLanguageService.Value))
         return(base.Generate(inputFilePath, inputFileContents, defaultNamespace, progressCallback));
 }
コード例 #13
0
 public override int Generate(string inputFilePath, string inputFileContents, string defaultNamespace, IntPtr[] outputFileContents, out uint outputSize, IVsGeneratorProgress progressCallback)
 {
     using (LNode.PushPrinter(Loyc.Syntax.Les.LesNodePrinter.Printer))
         return(base.Generate(inputFilePath, inputFileContents, defaultNamespace, outputFileContents, out outputSize, progressCallback));
 }