-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathvariables.go
105 lines (85 loc) · 2.28 KB
/
variables.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ast
import (
"bytes"
"strings"
)
// Variable interface represents assignable nodes in Goby, currently are Identifier, InstanceVariable and Constant
type Variable interface {
variableNode()
ReturnValue() string
Expression
}
// MultiVariableExpression is not really an expression, it's just a container that holds multiple Variables
type MultiVariableExpression struct {
*BaseNode
Variables []Expression
}
func (m *MultiVariableExpression) expressionNode() {}
// TokenLiteral returns an empty string
func (m *MultiVariableExpression) TokenLiteral() string {
return ""
}
func (m *MultiVariableExpression) String() string {
var out bytes.Buffer
var variables []string
for _, v := range m.Variables {
variables = append(variables, v.String())
}
out.WriteString(strings.Join(variables, ", "))
return out.String()
}
// Identifier represents an identifier string
type Identifier struct {
*BaseNode
Value string
}
func (i *Identifier) variableNode() {}
// ReturnValue is a polymorphic method for returning a value
func (i *Identifier) ReturnValue() string {
return i.Value
}
func (i *Identifier) expressionNode() {}
// TokenLiteral returns an empty string
func (i *Identifier) TokenLiteral() string {
return i.Token.Literal
}
func (i *Identifier) String() string {
return i.Value
}
// InstanceVariable represents an instance variables
type InstanceVariable struct {
*BaseNode
Value string
}
func (iv *InstanceVariable) variableNode() {}
// ReturnValue is a polymorphic method for returning a value
func (iv *InstanceVariable) ReturnValue() string {
return iv.Value
}
func (iv *InstanceVariable) expressionNode() {}
// TokenLiteral returns an empty string
func (iv *InstanceVariable) TokenLiteral() string {
return iv.Token.Literal
}
func (iv *InstanceVariable) String() string {
return iv.Value
}
// Constant represents a constant that may include namespace
type Constant struct {
*BaseNode
Value string
IsNamespace bool
}
func (c *Constant) variableNode() {}
// ReturnValue is a polymorphic method for returning a value
func (c *Constant) ReturnValue() string {
return c.Value
}
func (c *Constant) expressionNode() {}
// TokenLiteral returns an empty string
func (c *Constant) TokenLiteral() string {
return c.Token.Literal
}
func (c *Constant) String() string {
return c.Value
}