public PsiAST(PsiAST parent, string val, NodeType lab) { Parent = parent; Value = val; Type = lab; Children = new List<PsiAST>(); }
public void VisitPsiAST(PsiAST tree) { // Fa bejárása }
public PsiAST Clone() { PsiAST c = new PsiAST(Parent, Value, Type); if(Children.Count != 0) foreach (PsiAST t in Children) c.Add(t.Clone()); return c; }
public void Visit(PsiAST node) { // Switch NodeType alapján // Hogy illeszkedik ide a a rekurzív bejárás ... }
public void AddSibling(PsiAST sibling) { if (Parent == null) throw new PsiASTException("Cannot add sibling to the root element of a tree, because root has no parent."); Parent.Add(sibling); }
public void AddClone(PsiAST child) { if (!Children.Contains(child)) { PsiAST c = child.Clone(); c.Parent = this; Children.Add(c); } }
public void Add(PsiAST child) { if (!Children.Contains(child)) { child.Parent = this; Children.Add(child); } }
public static TreeNode FromPsiASTToTreeNode(PsiAST tree, ViewMode vm) { if (tree != null) { // ViewMode string text = ""; switch (vm) { case ViewMode.All: text = tree.ToString(); break; case ViewMode.Values: text = tree.Value; break; case ViewMode.Hibrid: if (tree.Value == "") text = tree.Type.ToString(); else text = tree.Value; break; default: // Can't Be break; } if (tree.Children != null) { TreeNode[] children = new TreeNode[tree.Children.Count]; for (int i = 0; i < tree.Children.Count; i++) children[i] = FromPsiASTToTreeNode(tree.Children[i],vm); return new TreeNode(text, children); } return new TreeNode(text); } return new TreeNode("#"); }
public static PsiAST FromCommonTreeToPsiAST(CommonTree tree) { PsiAST root = null; if (tree != null) { // Itt megkell még határozni, hogy miylen típusú legyen. (Type.ASTLabel1) // Egy esetszétválasztás kell. // ... switch (tree.Type) { case Psimulex: break; default: break; } root = new PsiAST(null, tree.Text, NodeType.X); if (tree.Children != null) foreach (CommonTree child in tree.Children) root.Add(FromCommonTreeToPsiAST(child)); } return root; }