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); }
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); }
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); }
protected abstract void Visit(IndentationNode node);
protected override void Visit(IndentationNode node) { this.Nodes.Add(node); }
protected override void Visit(IndentationNode node) { Add(node); }