File: variable_access.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 (39 lines) | stat: -rw-r--r-- 682 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
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

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
}