Example #1
0
		public void Print(LNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
		{
			if (_usePlainCsPrinter)
				EcsNodePrinter.PrintPlainCSharp(node, target, sink, mode, options);
			else
				EcsNodePrinter.PrintECSharp(node, target, sink, mode, options);
		}
Example #2
0
 public Les2PrinterOptions(ILNodePrinterOptions options)
 {
     if (options != null)
     {
         CopyFrom(options);
     }
 }
Example #3
0
        /// <summary>Prints an LNode as LESv3 with HTML syntax highlighting elements.</summary>
        /// <param name="nodes">Syntax trees to print.</param>
        /// <param name="output">Output StringBuilder for HTML code.</param>
        /// <param name="addPreCode">Whether to wrap the output in "&lt;pre class='highlight'>&lt;code>" tags.</param>
        /// <param name="options">Options to control the style for code printing.</param>
        /// <returns>The output StringBuilder</returns>
        public static StringBuilder PrintToHtml(
            IEnumerable <ILNode> nodes, StringBuilder output = null,
            bool addPreCode = true, IMessageSink sink = null,
            ILNodePrinterOptions options = null)
        {
            var pp = new Les3PrettyPrinter(sink, options);

            return(pp.PrintToHtml(nodes, output, addPreCode));
        }
Example #4
0
 public Les3PrinterOptions(ILNodePrinterOptions options)
 {
     WarnAboutUnprintableLiterals = true;
     SpaceAfterComma          = true;
     ForcedLineBreakThreshold = 120;
     if (options != null)
     {
         CopyFrom(options);
     }
 }
Example #5
0
 public void CopyFrom(ILNodePrinterOptions original)
 {
     AllowChangeParentheses = original.AllowChangeParentheses;
     OmitComments           = original.OmitComments;
     OmitUnknownTrivia      = original.OmitUnknownTrivia;
     PrintTriviaExplicitly  = original.PrintTriviaExplicitly;
     CompatibilityMode      = original.CompatibilityMode;
     CompactMode            = original.CompactMode;
     IndentString           = original.IndentString;
     NewlineString          = original.NewlineString;
 }
Example #6
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 #7
0
		public void CopyFrom(ILNodePrinterOptions original)
		{
			AllowChangeParentheses = original.AllowChangeParentheses;
			OmitComments = original.OmitComments;
			OmitUnknownTrivia = original.OmitUnknownTrivia;
			PrintTriviaExplicitly = original.PrintTriviaExplicitly;
			CompatibilityMode = original.CompatibilityMode;
			CompactMode = original.CompactMode;
			IndentString = original.IndentString;
			NewlineString = original.NewlineString;
		}
Example #8
0
 /// <summary>Creates an instance of this class, which produces plain LES
 /// augmented with control codes.</summary>
 public Les3PrettyPrinter(IMessageSink sink = null, ILNodePrinterOptions options = null) : this(null, sink, options)
 {
 }
Example #9
0
 /// <summary>Creates an instance of this class, which produces plain LES
 /// augmented with control codes.</summary>
 public Les3PrettyPrinter(StringBuilder target, IMessageSink sink, ILNodePrinterOptions options) : base(target, sink, options)
 {
 }
Example #10
0
 public void Print(ILNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
 {
     Les2Printer.Print(node, target, sink, mode, options);
 }
        public string Print(ILNode node, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
        {
            StringBuilder target = new StringBuilder();

            Print(node, target, sink, mode, options);
            return(target.ToString());
        }
Example #12
0
        public void Print(IEnumerable <ILNode> nodes, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
        {
            CheckParam.IsNotNull("target", target);
            var p = new Les3Printer(target, sink, options);

            p.Print(nodes);
        }
Example #13
0
 void ILNodePrinter.Print(LNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
 {
     Print((ILNode)node, target, sink, mode, options);
 }
Example #14
0
 public void SetOptions(ILNodePrinterOptions options)
 {
     _o = options as Les2PrinterOptions ?? new Les2PrinterOptions(options);
 }
Example #15
0
 internal Les2Printer(StringBuilder target, ILNodePrinterOptions options = null)
 {
     SetOptions(options);
     Writer = new Les2PrinterWriter(target, _o.IndentString ?? "\t", _o.NewlineString ?? "\n");
 }
Example #16
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 #17
0
 public void Print(LNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
 {
     if (_usePlainCsPrinter)
     {
         EcsNodePrinter.PrintPlainCSharp(node, target, sink, mode, options);
     }
     else
     {
         EcsNodePrinter.PrintECSharp(node, target, sink, mode, options);
     }
 }
Example #18
0
		/// <summary>Creates an instance of this class, which produces plain LES 
		/// augmented with control codes.</summary>
		public Les3PrettyPrinter(StringBuilder target, IMessageSink sink, ILNodePrinterOptions options) : base(target, sink, options)
		{
		}
Example #19
0
		/// <summary>Creates an instance of this class, which produces plain LES 
		/// augmented with control codes.</summary>
		public Les3PrettyPrinter(IMessageSink sink = null, ILNodePrinterOptions options = null) : this(null, sink, options) { }
Example #20
0
		/// <summary>Prints an LNode as LESv3 with HTML syntax highlighting elements.</summary>
		/// <param name="nodes">Syntax trees to print.</param>
		/// <param name="output">Output StringBuilder for HTML code.</param>
		/// <param name="addPreCode">Whether to wrap the output in "&lt;pre class='highlight'>&lt;code>" tags.</param>
		/// <param name="options">Options to control the style for code printing.</param>
		/// <returns>The output StringBuilder</returns>
		public static StringBuilder PrintToHtml(
				IEnumerable<ILNode> nodes, StringBuilder output = null, 
				bool addPreCode = true, IMessageSink sink = null,
				ILNodePrinterOptions options = null)
		{
			var pp = new Les3PrettyPrinter(sink, options);
			return pp.PrintToHtml(nodes, output, addPreCode);
		}
Example #21
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 #22
0
		public void Print(IEnumerable<ILNode> nodes, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
		{
			CheckParam.IsNotNull("target", target);
			var p = new Les3Printer(target, sink, options);
			p.Print(nodes);
		}
Example #23
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 #24
0
 void ILNodePrinter.Print(IEnumerable <LNode> nodes, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
 {
     Print(nodes.Upcast <ILNode, LNode>(), target, sink, mode, options);
 }
Example #25
0
 public void Print(IEnumerable <LNode> nodes, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
 {
     LNodePrinter.PrintMultiple(this, nodes, target, sink, mode, options);
 }
Example #26
0
		void ILNodePrinter.Print(LNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
		{
			Print((ILNode)node, target, sink, mode, options);
		}
Example #27
0
        internal static void Print(ILNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options = null)
        {
            var p          = _printer = _printer ?? new Les2Printer(TextWriter.Null, null);
            var oldOptions = p._o;
            var oldWriter  = p.Writer;
            var oldSink    = p.ErrorSink;

            p.ErrorSink = sink;
            p.SetOptions(options);
            p.Writer = new Les2PrinterWriter(target, p.Options.IndentString ?? "\t", p.Options.NewlineString ?? "\n");

            if (mode == ParsingMode.Expressions)
            {
                p.Print(node, StartStmt, "");
            }
            else
            {
                p.Print(node, StartStmt, ";");
            }

            p.Writer    = oldWriter;
            p._o        = oldOptions;
            p.ErrorSink = oldSink;
        }
Example #28
0
		public void Print(ILNode node, StringBuilder target, IMessageSink sink = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
		{
			Les2Printer.Print(node, target, sink, mode, options);
		}
Example #29
0
		public void Print(IEnumerable<LNode> nodes, StringBuilder target, IMessageSink msgs = null, ParsingMode mode = null, ILNodePrinterOptions options = null)
		{
			LNodePrinter.PrintMultiple(this, nodes, target, msgs, mode, options);
		}
Example #30
0
		void ILNodePrinter.Print(IEnumerable<LNode> nodes, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options)
		{
			Print(nodes.Upcast<ILNode, LNode>(), target, sink, mode, options);
		}