Ejemplo n.º 1
0
 public void ParseWithoutIncludes(Tokeniser tokeniser)
 {
     Parse(null, tokeniser, false);
 }
Ejemplo n.º 2
0
        void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes, bool isImport)
        {
            bool skip = false;
            bool 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))
                                {
                                    segments.Add(directive);
                                }
                            }
                            else
                            {
                                attName = tokeniser.Value;
                            }
                            break;

                        case State.DirectiveValue:
                            if (attName != null && directive != null)
                            {
                                directive.Attributes[attName] = tokeniser.Value;
                            }
                            else
                            {
                                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))
                    {
                        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)
                    {
                        importedHelperSegments.Add(seg);
                    }
                    else
                    {
                        segments.Add(seg);
                    }
                }
            }
            if (!isImport)
            {
                AppendAnyImportedHelperSegments();
            }
        }
Ejemplo n.º 3
0
 public void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser)
 {
     Parse(host, tokeniser, true);
 }
Ejemplo n.º 4
0
 void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes)
 {
     Parse(host, tokeniser, parseIncludes, false);
 }