github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemadsl/parser/nodestack.go (about)

     1  package parser
     2  
     3  type nodeStack struct {
     4  	top  *element
     5  	size int
     6  }
     7  
     8  type element struct {
     9  	value AstNode
    10  	next  *element
    11  }
    12  
    13  func (s *nodeStack) topValue() AstNode {
    14  	if s.size == 0 {
    15  		return nil
    16  	}
    17  
    18  	return s.top.value
    19  }
    20  
    21  // Push pushes a node onto the stack.
    22  func (s *nodeStack) push(value AstNode) {
    23  	s.top = &element{value, s.top}
    24  	s.size++
    25  }
    26  
    27  // Pop removes the node from the stack and returns it.
    28  func (s *nodeStack) pop() (value AstNode) {
    29  	if s.size > 0 {
    30  		value, s.top = s.top.value, s.top.next
    31  		s.size--
    32  		return
    33  	}
    34  	return nil
    35  }