File: variable_access.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 (36 lines) | stat: -rw-r--r-- 612 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
26
27
28
29
30
31
32
33
34
35
36
package ast

import (
	"fmt"
)

// VariableAccess represents a variable access.
type VariableAccess struct {
	Name string
	Posx Pos
}

func (n *VariableAccess) Accept(v Visitor) Node {
	return v(n)
}

func (n *VariableAccess) Pos() Pos {
	return n.Posx
}

func (n *VariableAccess) GoString() string {
	return fmt.Sprintf("*%#v", *n)
}

func (n *VariableAccess) String() string {
	return fmt.Sprintf("Variable(%s)", n.Name)
}

func (n *VariableAccess) Type(s Scope) (Type, error) {
	v, ok := s.LookupVar(n.Name)
	if !ok {
		return TypeInvalid, fmt.Errorf("unknown variable: %s", n.Name)
	}

	return v.Type, nil
}