当前位置: 首页>>代码示例>>C#>>正文


C# NodeVisitors.SpecialNodeInspector类代码示例

本文整理汇总了C#中Spark.Compiler.NodeVisitors.SpecialNodeInspector的典型用法代码示例。如果您正苦于以下问题:C# SpecialNodeInspector类的具体用法?C# SpecialNodeInspector怎么用?C# SpecialNodeInspector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpecialNodeInspector类属于Spark.Compiler.NodeVisitors命名空间,在下文中一共展示了SpecialNodeInspector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitVar

        private void VisitVar(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            Frame frame = null;
            if (!specialNode.Element.IsEmptyElement)
            {
                var scope = new ScopeChunk { Position = Locate(specialNode.Element) };
                Chunks.Add(scope);
                frame = new Frame(this, scope.Body);
            }

            var typeAttr = inspector.TakeAttribute("type");
            var type = typeAttr != null ? AsCode(typeAttr) : (Snippets)"var";

            foreach (var attr in inspector.Attributes)
            {
                Chunks.Add(new LocalVariableChunk { Type = type, Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
            }

            Accept(specialNode.Body);

            if (frame != null)
                frame.Dispose();
        }
开发者ID:otac0n,项目名称:spark,代码行数:23,代码来源:ChunkBuilderVisitor.cs

示例2: VisitViewdata

        private void VisitViewdata(SpecialNodeInspector inspector)
        {
            var defaultAttr = inspector.TakeAttribute("default");
            Snippets defaultValue = null;
            if (defaultAttr != null)
                defaultValue = AsCode(defaultAttr);

            var modelAttr = inspector.TakeAttribute("model");
            if (modelAttr != null)
            {
                var typeInspector = new TypeInspector(AsCode(modelAttr));
                AddUnordered(new ViewDataModelChunk { TModel = typeInspector.Type, TModelAlias = typeInspector.Name });
            }

            foreach (var attr in inspector.Attributes)
            {
                var typeInspector = new TypeInspector(AsCode(attr));
                AddUnordered(new ViewDataChunk
                                 {
                                     Type = typeInspector.Type,
                                     Name = typeInspector.Name ?? attr.Name,
                                     Key = attr.Name,
                                     Default = defaultValue,
                                     Position = Locate(attr)
                                 });
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:27,代码来源:ChunkBuilderVisitor.cs

示例3: VisitSet

 private void VisitSet(SpecialNodeInspector inspector)
 {
     foreach (var attr in inspector.Attributes)
     {
         Chunks.Add(new AssignVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
     }
 }
开发者ID:otac0n,项目名称:spark,代码行数:7,代码来源:ChunkBuilderVisitor.cs

示例4: VisitUse

        private void VisitUse(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var file = inspector.TakeAttribute("file");
            if (file != null)
            {
                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var useFileChunk = new RenderPartialChunk { Name = file.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(useFileChunk);
                    using (new Frame(this, useFileChunk.Body, useFileChunk.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var contentAttr = inspector.TakeAttribute("content");
                var namespaceAttr = inspector.TakeAttribute("namespace");
                var assemblyAttr = inspector.TakeAttribute("assembly");
                var importAttr = inspector.TakeAttribute("import");
                var masterAttr = inspector.TakeAttribute("master");
                var pageBaseTypeAttr = inspector.TakeAttribute("pageBaseType");

                if (contentAttr != null)
                {
                    var useContentChunk = new UseContentChunk { Name = contentAttr.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(useContentChunk);
                    using (new Frame(this, useContentChunk.Default))
                    {
                        Accept(specialNode.Body);
                    }
                }
                else if (namespaceAttr != null || assemblyAttr != null)
                {
                    if (namespaceAttr != null)
                    {
                        var useNamespaceChunk = new UseNamespaceChunk { Namespace = AsCode(namespaceAttr) };
                        AddUnordered(useNamespaceChunk);
                    }

                    if (assemblyAttr != null)
                    {
                        var useAssemblyChunk = new UseAssemblyChunk { Assembly = assemblyAttr.Value };
                        AddUnordered(useAssemblyChunk);
                    }
                }
                else if (importAttr != null)
                {
                    var useImportChunk = new UseImportChunk { Name = importAttr.Value };
                    AddUnordered(useImportChunk);
                }
                else if (masterAttr != null)
                {
                    var useMasterChunk = new UseMasterChunk { Name = masterAttr.Value };
                    AddUnordered(useMasterChunk);
                }
                else if (pageBaseTypeAttr != null)
                {
                    var usePageBaseTypeChunk = new PageBaseTypeChunk { BaseClass = AsCode(pageBaseTypeAttr) };
                    AddUnordered(usePageBaseTypeChunk);
                }
                else
                {
                    throw new CompilerException("Special node use had no understandable attributes");
                }
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:75,代码来源:ChunkBuilderVisitor.cs

示例5: VisitRender

        private void VisitRender(SpecialNode node, SpecialNodeInspector inspector)
        {
            var partial = inspector.TakeAttribute("partial");

            if (partial != null)
            {
                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var renderPartial = new RenderPartialChunk { Name = partial.Value, Position = Locate(inspector.OriginalNode) };
                    Chunks.Add(renderPartial);

                    using (new Frame(this, renderPartial.Body, renderPartial.Sections))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
            else
            {
                var sectionAttr = inspector.TakeAttribute("section");

                string sectionName = null;
                if (sectionAttr != null)
                    sectionName = sectionAttr.Value;

                var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
                Chunks.Add(scope);
                using (new Frame(this, scope.Body))
                {
                    foreach (var attr in inspector.Attributes)
                    {
                        Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                    }

                    var render = new RenderSectionChunk { Name = sectionName };
                    Chunks.Add(render);
                    using (new Frame(this, render.Default))
                    {
                        Accept(inspector.Body);
                    }
                }
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:50,代码来源:ChunkBuilderVisitor.cs

示例6: VisitSection

        private void VisitSection(SpecialNode node, SpecialNodeInspector inspector)
        {
            if (SectionChunks == null)
                throw new CompilerException("Section cannot be used at this location", Locate(node.Element));

            var name = inspector.TakeAttribute("name");
            if (name == null)
                throw new CompilerException("Section element must have a name attribute", Locate(node.Element));

            IList<Chunk> sectionChunks;
            if (!SectionChunks.TryGetValue(name.Value, out sectionChunks))
            {
                sectionChunks = new List<Chunk>();
                SectionChunks.Add(name.Value, sectionChunks);
            }

            var scope = new ScopeChunk { Position = Locate(inspector.OriginalNode) };
            sectionChunks.Add(scope);
            using (new Frame(this, scope.Body))
            {
                foreach (var attr in inspector.Attributes)
                {
                    Chunks.Add(new LocalVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                }

                Accept(inspector.Body);
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:28,代码来源:ChunkBuilderVisitor.cs

示例7: VisitMacro

        private void VisitMacro(SpecialNodeInspector inspector)
        {
            var name = inspector.TakeAttribute("name");
            var macro = new MacroChunk { Name = name.Value, Position = Locate(inspector.OriginalNode) };
            foreach (var attr in inspector.Attributes)
            {
                macro.Parameters.Add(new MacroParameter { Name = attr.Name, Type = AsCode(attr) });
            }

            AddUnordered(macro);
            using (new Frame(this, macro.Body))
            {
                Accept(inspector.Body);
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:15,代码来源:ChunkBuilderVisitor.cs

示例8: VisitMarkdown

        private void VisitMarkdown(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var markdownChunk = new MarkdownChunk();

            Chunks.Add(markdownChunk);
            using (new Frame(this, markdownChunk.Body))
            {
                Accept(inspector.Body);
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:10,代码来源:ChunkBuilderVisitor.cs

示例9: VisitFor

        private void VisitFor(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var eachAttr = inspector.TakeAttribute("each");

            var forEachChunk = new ForEachChunk { Code = AsCode(eachAttr), Position = Locate(specialNode.Element) };
            Chunks.Add(forEachChunk);
            using (new Frame(this, forEachChunk.Body))
            {
                foreach (var attr in inspector.Attributes)
                {
                    Chunks.Add(new AssignVariableChunk { Name = attr.Name, Value = AsCode(attr), Position = Locate(attr) });
                }

                Accept(specialNode.Body);
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:16,代码来源:ChunkBuilderVisitor.cs

示例10: VisitIf

        private void VisitIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("if");

            var onceAttr = inspector.TakeAttribute("once");

            if (conditionAttr == null && onceAttr == null)
            {
                throw new CompilerException("Element must contain an if, condition, or once attribute");
            }

            Frame ifFrame = null;
            if (conditionAttr != null)
            {
                var ifChunk = new ConditionalChunk { Type = ConditionalType.If, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
                Chunks.Add(ifChunk);
                ifFrame = new Frame(this, ifChunk.Body);
            }

            Frame onceFrame = null;
            if (onceAttr != null)
            {
                var onceChunk = new ConditionalChunk { Type = ConditionalType.Once, Condition = onceAttr.AsCodeInverted(), Position = Locate(inspector.OriginalNode) };
                Chunks.Add(onceChunk);
                onceFrame = new Frame(this, onceChunk.Body);
            }

            Accept(specialNode.Body);

            if (onceFrame != null)
                onceFrame.Dispose();

            if (ifFrame != null)
                ifFrame.Dispose();
        }
开发者ID:otac0n,项目名称:spark,代码行数:35,代码来源:ChunkBuilderVisitor.cs

示例11: VisitElseIf

        private void VisitElseIf(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            if (!SatisfyElsePrecondition())
                throw new CompilerException("An 'elseif' may only follow an 'if' or 'elseif'.");

            var conditionAttr = inspector.TakeAttribute("condition");
            var elseIfChunk = new ConditionalChunk { Type = ConditionalType.ElseIf, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
            Chunks.Add(elseIfChunk);
            using (new Frame(this, elseIfChunk.Body))
                Accept(specialNode.Body);
        }
开发者ID:otac0n,项目名称:spark,代码行数:11,代码来源:ChunkBuilderVisitor.cs

示例12: VisitContent

        private void VisitContent(SpecialNodeInspector inspector)
        {
            var nameAttr = inspector.TakeAttribute("name");
            var varAttr = inspector.TakeAttribute("var");
            var defAttr = inspector.TakeAttribute("def");
            var setAttr = inspector.TakeAttribute("set");

            if (nameAttr != null)
            {
                var contentChunk = new ContentChunk { Name = nameAttr.Value, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentChunk);
                using (new Frame(this, contentChunk.Body))
                    Accept(inspector.Body);
            }
            else if (varAttr != null || defAttr != null)
            {
                var variableChunk = new LocalVariableChunk { Name = AsCode(varAttr ?? defAttr), Type = "string" };
                Chunks.Add(variableChunk);

                var contentSetChunk = new ContentSetChunk { Variable = variableChunk.Name, Position = Locate(inspector.OriginalNode) };
                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else if (setAttr != null)
            {
                var addAttr = inspector.TakeAttribute("add");

                var contentSetChunk = new ContentSetChunk { Variable = AsCode(setAttr), Position = Locate(inspector.OriginalNode) };

                if (addAttr != null)
                {
                    if (addAttr.Value == "before")
                        contentSetChunk.AddType = ContentAddType.InsertBefore;
                    else if (addAttr.Value == "after")
                        contentSetChunk.AddType = ContentAddType.AppendAfter;
                    else if (addAttr.Value == "replace")
                        contentSetChunk.AddType = ContentAddType.Replace;
                    else
                        throw new CompilerException("add attribute must be 'before', 'after', or 'replace");
                }

                Chunks.Add(contentSetChunk);
                using (new Frame(this, contentSetChunk.Body))
                    Accept(inspector.Body);
            }
            else
            {
                throw new CompilerException("content element must have name, var, def, or set attribute");
            }
        }
开发者ID:otac0n,项目名称:spark,代码行数:51,代码来源:ChunkBuilderVisitor.cs

示例13: VisitCache

        private void VisitCache(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var keyAttr = inspector.TakeAttribute("key");
            var expiresAttr = inspector.TakeAttribute("expires");
            var signalAttr = inspector.TakeAttribute("signal");

            var chunk = new CacheChunk { Position = Locate(specialNode.Element) };

            if (keyAttr != null)
                chunk.Key = AsCode(keyAttr);
            else
                chunk.Key = "\"\"";

            if (expiresAttr != null)
                chunk.Expires = AsCode(expiresAttr);
            else
                chunk.Expires = "";

            if (signalAttr != null)
                chunk.Signal = AsCode(signalAttr);
            else
                chunk.Signal = "";

            Chunks.Add(chunk);
            using (new Frame(this, chunk.Body))
                Accept(inspector.Body);
        }
开发者ID:otac0n,项目名称:spark,代码行数:27,代码来源:ChunkBuilderVisitor.cs

示例14: VisitIgnore

 private void VisitIgnore(SpecialNode specialNode, SpecialNodeInspector inspector)
 {
     Accept(specialNode.Body);
 }
开发者ID:emiaj,项目名称:spark,代码行数:4,代码来源:ChunkBuilderVisitor.cs

示例15: VisitUnless

        private void VisitUnless(SpecialNode specialNode, SpecialNodeInspector inspector)
        {
            var conditionAttr = inspector.TakeAttribute("condition") ?? inspector.TakeAttribute("unless");

            var unlessChunk = new ConditionalChunk { Type = ConditionalType.Unless, Condition = AsCode(conditionAttr), Position = Locate(inspector.OriginalNode) };
            Chunks.Add(unlessChunk);
            using (new Frame(this, unlessChunk.Body))
                Accept(specialNode.Body);
        }
开发者ID:pr0nin,项目名称:spark,代码行数:9,代码来源:ChunkBuilderVisitor.cs


注:本文中的Spark.Compiler.NodeVisitors.SpecialNodeInspector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。