public ParseNode GetAndMove(ParseNodeTag tag) { ParseNode node = Items[_index++]; if (node.Tag != tag) { throw new SyntaxException("Unexpected parse node: {0} (expected: {1})", node.Tag, tag); } return(node); }
private Func <ParseNode> GetFlattenLeftRecurtion( ParseNodeTag nodeTag, Func <ParseNode> childFactory, Func <bool> continueCondition) { return(() => { var root = new ParseNode(nodeTag); do { root.AddChild(childFactory()); }while (continueCondition()); return root; }); }
private Func <ParseNode> GetBinaryOperation( ParseNodeTag nodeTag, Func <ParseNode> childFactory, Func <bool> breakCondition) { Func <ParseNode, ParseNode, ParseNode> nodeFactory = (leftOp, rightOp) => { return(new ParseNode(nodeTag) .AddChild(leftOp) .AddChild(rightOp.Children.GetAndMove()) .AddChild(rightOp.Children.GetAndMove())); }; Func <ParseNode> rightChildFactory = () => { return(new ParseNode(nodeTag) .AddChild(Terminal()) .AddChild(childFactory())); }; return(GetLeftRecurtion(nodeFactory, childFactory, rightChildFactory, breakCondition)); }
public ParseNode Wrap(ParseNodeTag tag) { return(new ParseNode(tag, this)); }
public ParseNode(ParseNodeTag tag, Token terminal, IEnumerable <ParseNode> children) { Tag = tag; Token = terminal; Children = new ParseNodeCollection(children); }
public ParseNode(ParseNodeTag tag, params ParseNode[] children) : this(tag, default(Token), children) { }
public bool Check(ParseNodeTag tag) { return((_index >= 0 && _index < Items.Count) && Items[_index].Tag == tag); }