private void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes, bool isImport) { var skip = false; var addToImportedHelpers = false; while ((skip || tokeniser.Advance()) && tokeniser.State != State.EOF) { skip = false; ISegment seg = null; switch (tokeniser.State) { case State.Block: if (!String.IsNullOrEmpty(tokeniser.Value)) { seg = new TemplateSegment(SegmentType.Block, tokeniser.Value, tokeniser.Location); } break; case State.Content: if (!String.IsNullOrEmpty(tokeniser.Value)) { seg = new TemplateSegment(SegmentType.Content, tokeniser.Value, tokeniser.Location); } break; case State.Expression: if (!String.IsNullOrEmpty(tokeniser.Value)) { seg = new TemplateSegment(SegmentType.Expression, tokeniser.Value, tokeniser.Location); } break; case State.Helper: addToImportedHelpers = isImport; if (!String.IsNullOrEmpty(tokeniser.Value)) { seg = new TemplateSegment(SegmentType.Helper, tokeniser.Value, tokeniser.Location); } break; case State.Directive: Directive directive = null; string attName = null; while (!skip && tokeniser.Advance()) { switch (tokeniser.State) { case State.DirectiveName: if (directive == null) { directive = new Directive(tokeniser.Value, tokeniser.Location); directive.TagStartLocation = tokeniser.TagStartLocation; if (!parseIncludes || !string.Equals(directive.Name, "include", StringComparison.OrdinalIgnoreCase)) { this.segments.Add(directive); } } else { attName = tokeniser.Value; } break; case State.DirectiveValue: if (attName != null && directive != null) { directive.Attributes[attName] = tokeniser.Value; } else { this.LogError("Directive value without name", tokeniser.Location); } attName = null; break; case State.Directive: if (directive != null) { directive.EndLocation = tokeniser.TagEndLocation; } break; default: skip = true; break; } } if (parseIncludes && directive != null && string.Equals(directive.Name, "include", StringComparison.OrdinalIgnoreCase)) { this.Import(host, directive, Path.GetDirectoryName(tokeniser.Location.FileName)); } break; default: throw new InvalidOperationException(); } if (seg != null) { seg.TagStartLocation = tokeniser.TagStartLocation; seg.EndLocation = tokeniser.TagEndLocation; if (addToImportedHelpers) { this.importedHelperSegments.Add(seg); } else { this.segments.Add(seg); } } } if (!isImport) { this.AppendAnyImportedHelperSegments(); } }
public void ParseWithoutIncludes(Tokeniser tokeniser) { this.Parse(null, tokeniser, false); }
private void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes) { this.Parse(host, tokeniser, parseIncludes, false); }
public void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser) { this.Parse(host, tokeniser, true); }