コード例 #1
0
        void Parse(ITextTemplatingEngineHost host, Tokeniser tokeniser, bool parseIncludes)
        {
            bool skip = 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:
                    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.ToLower(), tokeniser.Location);
                                directive.TagStartLocation = tokeniser.TagStartLocation;
                                if (!parseIncludes || directive.Name != "include")
                                {
                                    segments.Add(directive);
                                }
                            }
                            else
                            {
                                attName = tokeniser.Value;
                            }
                            break;

                        case State.DirectiveValue:
                            if (attName != null && directive != null)
                            {
                                directive.Attributes[attName.ToLower()] = 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.Name == "include")
                    {
                        Import(host, directive, Path.GetDirectoryName(tokeniser.Location.FileName));
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }
                if (seg != null)
                {
                    seg.TagStartLocation = tokeniser.TagStartLocation;
                    seg.EndLocation      = tokeniser.TagEndLocation;
                    segments.Add(seg);
                }
            }
        }
コード例 #2
0
ファイル: TemplateSettings.cs プロジェクト: faster-games/t4
 public CustomDirective(string processorName, Directive directive)
 {
     ProcessorName = processorName;
     Directive     = directive;
 }
コード例 #3
0
 public CustomDirective(string processorName, Directive directive)
 {
     this.ProcessorName = processorName;
     this.Directive     = directive;
 }
コード例 #4
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)
                                {
                                    TagStartLocation = tokeniser.TagStartLocation
                                };
                                if (!parseIncludes || !string.Equals(directive.Name, "include", StringComparison.OrdinalIgnoreCase))
                                {
                                    RawSegments.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
                    {
                        RawSegments.Add(seg);
                    }
                }
            }
            if (!isImport)
            {
                AppendAnyImportedHelperSegments();
            }
        }