Ejemplo n.º 1
0
        /// <summary>
        /// Pushes an indentation level.
        /// </summary>
        /// <param name="indentation">The indentation text.</param>
        public void PushIndentation(string indentation, TextFilePosition original, EntryFeatures features = EntryFeatures.None)
        {
            if (indentation == null)
            {
                throw new ArgumentNullException(nameof(indentation));
            }

            if (original == null)
            {
                throw new ArgumentNullException(nameof(original));
            }

            if (this.IsLineBlank)
            {
                var callerIndex = (this.CallerIndexStack.Count == 0) ? -1 : this.CallerIndexStack.Peek();
                this.IndentationStack.Push(new IndentationItem(indentation, original, callerIndex, features));
                this.PopIndendationStack.Push(true);
            }
            else
            {
                // Compensation for InterpolationRule Indentation in case current line isn't blank anymore.
                // Uses helper stack to track if the current indentation must be really popped.
                this.Write(indentation, original, EntryFeatures.ColumnInterpolation);
                this.PopIndendationStack.Push(false);
            }
        }
Ejemplo n.º 2
0
        public void Write(string text, TextFilePosition original, EntryFeatures features = EntryFeatures.None)
        {
            // Skip empty spans
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var index = 0;

            while (index < text.Length)
            {
                if (this.IsLineBlank)
                {
                    foreach (var indentationItem in this.IndentationStack.Reverse())
                    {
                        if (indentationItem.Indentation.Length > 0)
                        {
                            var entry = new MappingEntry(this.Position(), indentationItem.Original, indentationItem.CallerIndex, indentationItem.Features);
                            this.Mapping.Add(entry);
                            this.TextWriter.Write(indentationItem.Indentation);
                            this.Column += indentationItem.Indentation.Length;
                        }
                    }
                    this.IsLineBlank = false;
                }

                var callerIndex    = (this.CallerIndexStack.Count == 0) ? -1 : this.CallerIndexStack.Peek();
                var lineBreakIndex = text.IndexOf('\n', index);
                if (lineBreakIndex == -1)
                { // No line break found
                    var len = (text.Length - index);
                    if (original.IsValid && (len > 0))
                    {
                        var entry = new MappingEntry(this.Position(), original, callerIndex, features);
                        this.Mapping.Add(entry);
                    }
                    this.TextWriter.Write(text.Substring(index, text.Length - index));
                    Column += len;
                    index  += len;
                }
                else
                {  // Line break found
                    ++lineBreakIndex;
                    var len = (lineBreakIndex - index);
                    if (original.IsValid && (len > 0))
                    {
                        var entry = new MappingEntry(this.Position(), original, callerIndex, features);
                        this.Mapping.Add(entry);
                    }
                    this.TextWriter.Write(text.Substring(index, text.Length - lineBreakIndex));
                    index += len;
                    ++Line;
                    this.IsLineBlank = true;
                    this.Column      = 1;
                }
            }
        }
Ejemplo n.º 3
0
        public static void Write(Func <string> func, TextFilePosition source, EntryFeatures features)
        {
            if (TemplateRenderer.renderer == null)
            {
                return;
            }
            TemplateRenderer.renderer.PushCaller(source);
            string text = func();

            TemplateRenderer.renderer.PopCaller();

            TemplateRenderer.renderer.Write(text, source, features);
        }
Ejemplo n.º 4
0
        public static void Write(Action action, TextFilePosition source, EntryFeatures features)
        {
            if (TemplateRenderer.renderer == null)
            {
                return;
            }
            TemplateRenderer.renderer.PushCaller(source);
            action();
            TemplateRenderer.renderer.PopCaller();

#pragma warning disable CS1717 // Assignment made to same variable
            features = features;
#pragma warning restore CS1717 // Assignment made to same variable
        }
Ejemplo n.º 5
0
            public IndentationItem(string indentation, TextFilePosition original, int callerIndex, EntryFeatures features)
            {
                if (indentation == null)
                {
                    throw new ArgumentNullException(nameof(indentation));
                }
                this.Indentation = indentation;

                if (original == null)
                {
                    throw new ArgumentNullException(nameof(original));
                }
                this.Original = original;

                this.CallerIndex = callerIndex;
                this.Features    = features;
            }
Ejemplo n.º 6
0
        public MappingEntry(TextPosition generated, TextFilePosition original, int callerIndex, EntryFeatures features)
        {
            if (generated == null)
            {
                throw new ArgumentNullException(nameof(generated));
            }
            this.Generated = generated;

            if (original == null)
            {
                throw new ArgumentNullException(nameof(original));
            }
            this.Source = original;

            this.CallerIndex = callerIndex;
            this.Features    = features;
        }
Ejemplo n.º 7
0
 private string FeatureExpression(EntryFeatures features)
 {
     return($"_Features.{features}");
 }
Ejemplo n.º 8
0
 public static void PushIndentation(string indentation, TextFilePosition source, EntryFeatures features)
 {
     if (TemplateRenderer.renderer == null)
     {
         return;
     }
     TemplateRenderer.renderer.PushIndentation(indentation, source, features);
 }