public override TexlNode Clone(ref int idNext, Span ts) { var left = Left.Clone(ref idNext, ts); var newNodes = new Dictionary <TexlNode, TexlNode> { { Left, left }, }; var rightNode = RightNode?.Clone(ref idNext, ts); if (rightNode != null) { newNodes.Add(RightNode, rightNode); } DottedNameNode clonedNode = new DottedNameNode( ref idNext, Token.Clone(ts), SourceList.Clone(ts, newNodes), left, Right.Clone(ts), rightNode); return(clonedNode); }
public DPath ToDPath() { Contracts.Assert(HasPossibleNamespaceQualifier); Stack <DName> names = new Stack <DName>(2); names.Push(Right.Name); // Traverse the DottedNameNode structure non-recursively, to account for the possibility // that it may be very deep. Accumulate all encountered names onto a stack. DottedNameNode pointer = this; bool reachedLeft = false; while (pointer != null) { TexlNode left = pointer.Left; switch (left) { case FirstNameNode firstNameNode: names.Push(firstNameNode.Ident.Name); reachedLeft = true; break; case ParentNode parentNode: names.Push(new DName(TexlLexer.KeywordParent)); reachedLeft = true; break; case SelfNode selfNode: names.Push(new DName(TexlLexer.KeywordSelf)); reachedLeft = true; break; } if (reachedLeft) { break; } pointer = left as DottedNameNode; if (pointer != null) { names.Push(pointer.Right.Name); } else { Contracts.Assert(false, "Can only do this for dotted names consisting of identifiers"); } } // For the DPath by unwinding the names stack DPath path = DPath.Root; while (names.Count > 0) { path = path.Append(names.Pop()); } return(path); }