예제 #1
0
        protected override void Visit(IndentationNode node)
        {
            EndIndentationLength(node.Whitespace.Length);

            PushFrame(Nodes, new Frame
            {
                Indentation     = node,
                ElementsStarted = new List <ElementNode>()
            });
            base.Visit(node);
        }
        protected override void Visit(IndentationNode node)
        {
            this.EndIndentationLength(node.Whitespace.Length);
            Frame frameData = new Frame {
                Indentation     = node,
                ElementsStarted = new List <ElementNode>()
            };

            base.PushFrame(this.Nodes, frameData);
            base.Visit(node);
        }
예제 #3
0
        private static IndentationNode newNode(IndentationNode node, int depth)
        {
            if (node == null)
            {
                return(new IndentationNode(null, depth));
            }

            var diff = depth - node.Depth;

            if (diff > 0)
            {
                if (diff > 1)
                {
                    throw new ArgumentException("indentation");
                }
            }
            else if (diff < 0)
            {
                while (node != null && node.Depth >= depth)
                {
                    node = node.Parent;
                }

                if (node == null)
                {
                    throw new ArgumentException("indentation");
                }
            }
            else
            {
                node = node.Parent;
            }


            if (depth - node.Depth != 1)
            {
                throw new ArgumentException("indentation");
            }

            var result = new IndentationNode(node, depth);

            node.AddChild(result);
            return(result);
        }
예제 #4
0
        public static IndentationNode Parse(IEnumerable <SyntaxToken> tokens, int step)
        {
            var lines      = readLines(tokens);
            var rootIndent = getIndentation(lines[0], step);
            var root       = new IndentationNode(null, rootIndent - 1);
            var current    = root;

            foreach (var line in lines)
            {
                if (string.IsNullOrWhiteSpace(line) || isComment(line))
                {
                    continue;
                }

                var indent = getIndentation(line, step);
                current = newNode(current, indent);
                current.SetValue(line.TrimStart());
            }

            return(root);
        }
예제 #5
0
 protected abstract void Visit(IndentationNode node);
 protected override void Visit(IndentationNode node)
 {
     this.Nodes.Add(node);
 }
예제 #7
0
 protected override void Visit(IndentationNode node)
 {
     Add(node);
 }