github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/ast/tree.go (about)

     1  package ast
     2  
     3  type (
     4  	// Tree is the AST
     5  	Tree struct {
     6  		Name string
     7  		Root *BlockNode // top-level root of the tree.
     8  	}
     9  )
    10  
    11  // NewTree creates a new AST tree
    12  func NewTree(name string) *Tree {
    13  	return &Tree{
    14  		Name: name,
    15  	}
    16  }
    17  
    18  func (t *Tree) IsEqual(other *Tree) bool {
    19  	if t == other {
    20  		return true
    21  	}
    22  
    23  	return t.Root.IsEqual(other.Root)
    24  }
    25  
    26  func (tree *Tree) String() string {
    27  	if tree.Root == nil {
    28  		return ""
    29  	}
    30  
    31  	if len(tree.Root.Nodes) == 0 {
    32  		return ""
    33  	}
    34  
    35  	return tree.Root.String()
    36  }