File: stack.go

package info (click to toggle)
golang-github-hashicorp-hil 0.0~git20160711.1e86c6b-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 352 kB
  • sloc: yacc: 161; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 377 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package ast

// Stack is a stack of Node.
type Stack struct {
	stack []Node
}

func (s *Stack) Len() int {
	return len(s.stack)
}

func (s *Stack) Push(n Node) {
	s.stack = append(s.stack, n)
}

func (s *Stack) Pop() Node {
	x := s.stack[len(s.stack)-1]
	s.stack[len(s.stack)-1] = nil
	s.stack = s.stack[:len(s.stack)-1]
	return x
}

func (s *Stack) Reset() {
	s.stack = nil
}