private ParserNode BuildGraphInternal(RuleExpression rootExpression) { _currContext = GraphContext.ForRoot(rootExpression); _recursiveNodes.Clear(); do { var ctx = _currContext; if (ctx.expression != null) { ctx.expression.Visit(_expressionsVisitor); } else { throw new NotImplementedException(); // should never happen } if (_currContext == ctx) { throw new InvalidOperationException(string.Format("Missing transition for expression [{0}] of rule [{1}] was not created!", _currContext.expression, _currContext.rule)); } if (_currContext == null) { throw new InvalidOperationException(string.Format("Invalid handler for expression [{0}] of rule [{1}]!", _currContext.expression, _currContext.rule)); } //if (_currContext.prevContext != ctx) // throw new InvalidOperationException(string.Format("Invalid previos context was set from handler for expression [{0}] of rule [{1}] was not created!", _currContext.expression, _currContext.rule)); } while (_currContext.parentContext != null); if (_currContext.childEntries == null || _currContext.childEntries.prev != null) { throw new InvalidOperationException(); } foreach (var item in _recursiveNodes) { ParserNode target = null; for (var n = item.Parent; n != null; n = n.Parent) { if (n.Rule == item.Rule && n.Parent.Rule != item.Rule && n.Parent is ParserNode.RuleCall) // && item.TargetCallExpr.ToString() && ) { target = n.Parent; break; } } if (target == null) { throw new InvalidOperationException(string.Format("Filed to find recursive rule call target for rule [{0}] from rule [{1}]!", item.Rule, item.Parent.Rule)); } item.SetTarget(target); } return(_currContext.childEntries.node); }