Example #1
0
        /// <summary>Serializes a list of syntax trees to a string in the
        /// syntax supported by the specified <see cref="ILNodePrinter"/>.</summary>
        public static string Print(this ILNodePrinter printer, IEnumerable <LNode> nodes, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
        {
            StringBuilder target = new StringBuilder();

            printer.Print(nodes, target, sink, mode, options);
            return(target.ToString());
        }
Example #2
0
 public InputOutput(ICharSource text, string fileName, IParsingService input = null, ILNodePrinter outPrinter = null, string outFileName = null)
 {
     Text                = text;
     FileName            = fileName ?? "";
     InputLang           = input;
     OutPrinter          = outPrinter;
     OutFileName         = outFileName;
     PreOpenedNamespaces = AutoPreOpenedNamespaces(FileName);
 }
Example #3
0
        //int _alternator;

        public void Test(string input, string output, int maxExpand = 0xFFFF, ILNodePrinter printer = null)
        {
            using (LNode.SetPrinter(printer ?? EcsLanguageService.Value))
                using (ParsingService.SetDefault(Les3LanguageService.Value))
                    TestCompiler.Test(input, output, _sink, maxExpand, "LeMP.les3.to.ecs");
            // LeMP.Prelude.Les3 is set up as an alias; both namespaces should work,
            // but we're not using this logic as of 2021/01 because we don't have a
            // way to turn off annoying deprecation warnings
            //(++_alternator & 1) != 0 ? "LeMP.les3.to.ecs" : "LeMP.Prelude.Les3");
        }
Example #4
0
		/// <summary>Converts a sequences of LNodes to strings, adding a line separator between each.</summary>
		/// <param name="printer">Printer to be used for each single LNode.</param>
		/// <remarks>The newline between two nodes is suppressed if the second 
		/// node has a <c>#trivia_appendStatement</c> attribute.</remarks>
		public static StringBuilder PrintMultiple(ILNodePrinter printer, IEnumerable<LNode> nodes, StringBuilder sb, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
		{
			sb = sb ?? new StringBuilder();
			var lineSeparator = (options != null ? options.NewlineString : null) ?? "\n";
			bool first = true;
			foreach (LNode node in nodes) {
				if (!first)
					sb.Append(node.AttrNamed(CodeSymbols.TriviaAppendStatement) == null ? lineSeparator : " ");
				printer.Print(node, sb, sink, mode, options);
				first = false;
			}
			return sb;
		}
Example #5
0
        public static void Test(string input, string output, IMessageSink sink, int maxExpand = 0xFFFF, bool plainCS = true)
        {
            ILNodePrinter printer = plainCS ? EcsLanguageService.WithPlainCSharpPrinter : EcsLanguageService.Value;

            using (LNode.SetPrinter(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()));
            }
        }
Example #6
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();
        }
Example #7
0
        /// <summary>Converts a sequences of LNodes to strings, adding a line separator between each.</summary>
        /// <param name="printer">Printer to be used for each single LNode.</param>
        /// <remarks>The newline between two nodes is suppressed if the second
        /// node has a <c>%appendStatement</c> attribute.</remarks>
        public static StringBuilder PrintMultiple(ILNodePrinter printer, IEnumerable <LNode> nodes, StringBuilder sb, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
        {
            sb = sb ?? new StringBuilder();
            var  lineSeparator = (options != null ? options.NewlineString : null) ?? "\n";
            bool first         = true;

            foreach (LNode node in nodes)
            {
                if (!first)
                {
                    sb.Append(node.AttrNamed(CodeSymbols.TriviaAppendStatement) == null ? lineSeparator : " ");
                }
                printer.Print(node, sb, sink, mode, options);
                first = false;
            }
            return(sb);
        }
Example #8
0
 private void Test(string input, string output, int maxExpand = 0xFFFF, IParsingService parser = null, ILNodePrinter printer = null, IMessageSink sink = null)
 {
     using (ParsingService.SetDefault(parser ?? Les2LanguageService.Value))
         using (LNode.SetPrinter(printer ?? EcsLanguageService.WithPlainCSharpPrinter))
             TestCompiler.Test(input, output, sink ?? _sink, maxExpand, "LeMP.les2.to.ecs");
 }
Example #9
0
		public InputOutput(ICharSource text, string fileName, IParsingService input = null, ILNodePrinter outPrinter = null, string outFileName = null)
		{
			Text = text; FileName = fileName ?? ""; InputLang = input; OutPrinter = outPrinter; OutFileName = outFileName;
		}