Beispiel #1
0
        public object Capture(AstNode node)
        {
            if(node == null)
                throw new ArgumentNullException("node");

            return Capture(() => Visit(node));
        }
Beispiel #2
0
        public virtual void Visit(AstNode node)
        {
            if(node == null)
                return;

            if (node is ChildrenNode)
                Visit((ChildrenNode)node);
            else if (node is TextNode)
                Visit((TextNode)node);
            else if (node is TagNode)
                Visit((TagNode)node);
            else if (node is FilterNode)
                Visit((FilterNode)node);
            else if (node is CommentNode)
                Visit((CommentNode)node);
            else if (node is AttributeNode)
                Visit((AttributeNode)node);
            else if (node is DocTypeNode)
                Visit((DocTypeNode)node);
            else if (node is CodeNode)
                Visit((CodeNode)node);
            else if (node is CodeBlockNode)
                Visit((CodeBlockNode)node);
            else if (node is TextChunk)
                Visit((TextChunk)node);
            else if (node is CodeChunk)
                Visit((CodeChunk)node);
            else if (node is LateBindingNode)
                Visit((LateBindingNode)node);
            else if (node is MetaNode)
                Visit((MetaNode)node);
            else
                throw new InvalidOperationException("unknown node");
        }
Beispiel #3
0
 public AstNode ParseLines(int baseIdentation, AstNode currentChild)
 {
     return ParseChildren(baseIdentation, currentChild, ParseMultiLineText);
 }
Beispiel #4
0
 public AstNode ParseChildren(int baseIdentation, AstNode currentChild)
 {
     return ParseChildren(baseIdentation, currentChild, ParseNode);
 }
Beispiel #5
0
        private AstNode ParseChildren(int baseIdentation, AstNode currentChild, ParseActionDelegate parser)
        {
            var nodes = new List<AstNode>();

            while(Read())
            {
                var node = parser();

                if(node != null)
                    nodes.Add(node);

                if (Input.NextLine != null && Input.NextLine.Indent <= baseIdentation)
                    break;
            }

            if(nodes.Count > 0)
            {
                if(currentChild != null)
                    nodes.Insert(0, currentChild);

                return new ChildrenNode(nodes);
            }

            return currentChild;
        }
Beispiel #6
0
        protected void VisitAndIdentOnlyWithMoreChilds(AstNode node)
        {
            if(node == null)
                return;

            if(node is ChildrenNode)
            {
                var children = ( (ChildrenNode)node );
                if(children.Count > 1)
                    VisitAndIdentAlways(node);
                else
                    foreach(var child in children)
                        node = child;
            }

            Visit(node);
        }
Beispiel #7
0
 protected void VisitAndIdentAlways(AstNode node)
 {
     VisitAndIdentAlways(node, false);
 }
Beispiel #8
0
        protected void VisitAndIdentAlways(AstNode node, bool codeblockcaller)
        {
            if (node == null)
                return;

            if (!codeblockcaller)
                WriteText(System.Environment.NewLine);

            if (node is ChildrenNode)
                foreach (var childrenNode in (ChildrenNode)node)
                {
                    if (!(childrenNode is CodeBlockNode) && !(childrenNode is MetaNode))
                    {
                        WriteIndent();
                    }
                    Visit(childrenNode);
                    if (!(childrenNode is CodeBlockNode) && !(childrenNode is MetaNode))
                    {
                        WriteText(System.Environment.NewLine);
                    }
                }
            else
            {
                if (!codeblockcaller)
                {
                    WriteIndent();
                }
                Visit(node);
                if (!codeblockcaller)
                {
                    WriteText(System.Environment.NewLine);
                }
            }
        }