示例#1
0
		protected virtual MacroProcessor NewLemp(int maxExpand, IParsingService inLang)
		{
			var lemp = new MacroProcessor(MessageSink.Default, typeof(LeMP.Prelude.BuiltinMacros));
			lemp.AddMacros(typeof(LeMP.Prelude.Les.Macros));
			lemp.AddMacros(typeof(LeMP.StandardMacros).Assembly);
			lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP"));
			lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude"));
			if (inLang.FileExtensions.Any(e => e == "les"))
				lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude.Les"));
			lemp.MaxExpansions = maxExpand;
			return lemp;
		}
示例#2
0
        protected virtual MacroProcessor NewLemp(int maxExpand, IParsingService inLang)
        {
            var lemp = new MacroProcessor(MessageSink.Default, typeof(LeMP.Prelude.BuiltinMacros));

            lemp.AddMacros(typeof(LeMP.Prelude.Les.Macros));
            lemp.AddMacros(typeof(LeMP.StandardMacros).Assembly);
            lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP"));
            lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude"));
            if (inLang.FileExtensions.Any(e => e == "les"))
            {
                lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP.Prelude.Les"));
            }
            lemp.MaxExpansions = maxExpand;
            return(lemp);
        }
示例#3
0
        public static void Main(string[] args)
        {
            // Acquire a log for, well, logging purposes.
            var rawLog = TerminalLog.Acquire();

            Log = new TransformLog(
                rawLog,
                entry => DiagnosticExtractor.Transform(entry, new Text("LeMP-repl")));

            // Wrap the log in a Loyc message sink.
            Sink = new SeverityMessageFilter(
                new PixieMessageSink(Log),
                Loyc.Severity.NoteDetail);

            // Create an option parser.
            var optParser = new GnuOptionSetParser(
                Options.All,
                Options.Files,
                Options.Files.Forms[0]);

            // Parse command-line arguments.
            var parsedOptions = optParser.Parse(args, Log);

            // Optionally display help message.
            if (parsedOptions.GetValue <bool>(Options.Help))
            {
                rawLog.Log(
                    new HelpMessage(
                        "LeMP-repl is a simple interactive program that " +
                        "reads unprocessed EC#, LES v2 or LES v3 code as " +
                        "input and produces processed or unprocessed EC#, " +
                        "LES v2 or LES v3 code as output.",
                        "LeMP-repl [options]",
                        Options.All));
                return;
            }

            // Create a macro processor.
            if (!parsedOptions.GetValue <bool>(Options.DoNotProcessMacros))
            {
                Processor = new MacroProcessor(Sink);
                Processor.AddMacros(typeof(StandardMacros).Assembly, false);
                Processor.PreOpenedNamespaces.Add(GSymbol.Get("LeMP"));
            }

            Parser  = GetParser(parsedOptions);
            Printer = GetPrinter(parsedOptions);

            // Start the REPL.
            RunRepl();
        }
示例#4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                var ofd = new OpenFileDialog
                {
                    Title       = "Select markdown files with code blocks to process with LeMP",
                    Filter      = "Markdown files (*.md)|*.md|All files|*.*",
                    Multiselect = true
                };
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                args = ofd.FileNames;
            }

            Console.WriteLine("Modify files in-place? (Y/N) ");
            bool inPlace = false;

            while (true)
            {
                var k = Console.ReadKey(false);
                if ((inPlace = k.Key == ConsoleKey.Y) || k.Key == ConsoleKey.N)
                {
                    break;
                }
            }

            MP.AddMacros(typeof(LeMP.StandardMacros).Assembly);
            MP.PreOpenedNamespaces.Add((Symbol)"LeMP");
            MP.PreOpenedNamespaces.Add((Symbol)"LeMP.Prelude");

            foreach (var filename in args)
            {
                try {
                    var code = File.ReadAllLines(filename);
                    int numProcessed;
                    using (MessageSink.PushCurrent(MessageSink.Console)) {
                        MessageSink.Current.Write(Severity.Note, "", "Starting {0}", filename);
                        var output = TransformFile(MP, code, out numProcessed);
                        if (output == null)
                        {
                            Console.WriteLine("Processing failed");
                        }
                        else if (numProcessed == 0)
                        {
                            Console.WriteLine("No code blocks found marked ~~~exec.");
                        }
                        else
                        {
                            Console.WriteLine("Processed {0} code blocks.", numProcessed);
                            var outFileName = inPlace ? filename : filename + ".out";
                            Console.WriteLine(" ... Writing {0} ...", outFileName);
                            File.WriteAllText(outFileName, output);
                        }
                    }
                } catch (IOException e) {
                    Console.WriteLine(e.DescriptionAndStackTrace());
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
        }