File: stack.go

package info (click to toggle)
golang-github-hashicorp-hil 0.0~git20230614.4d65b41-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 516 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 447 bytes parent folder | download
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
26
27
28
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

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
}