forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.go
152 lines (128 loc) · 2.45 KB
/
node.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package otto
import (
"fmt"
"reflect"
"sort"
"strings"
)
type _node interface {
Type() _nodeType
String() string
setPosition(int)
position() int
}
type _nodeType int
func (self _nodeType) Type() _nodeType {
return self
}
type _node_ struct {
_nodeType
Line int // Line in the source
}
func (self *_node_) setPosition(Line int) {
self.Line = Line
}
func (self *_node_) position() int {
return self.Line
}
const (
nodeEmpty _nodeType = iota
nodeCall
nodeBlock
nodeFunction
nodeCatch
nodeProgram
nodeSwitch
nodeCase
nodeTryCatch
nodeWhile
nodeDoWhile
nodeString
nodeBoolean
nodeNull
nodeAssignment
nodeUnaryOperation
nodeBinaryOperation
nodeBreak
nodeContinue
nodeComparison
nodeIdentifier
nodeReturn
nodeIf
nodeNumber
nodeThrow
nodeVariableDeclaration
nodeVariableDeclarationList
nodeWith
nodeFor
nodeForIn
nodeDotMember
nodeBracketMember
nodeObject
nodeObjectProperty
nodeArray
nodeRegExp
nodeNew
nodeValue
nodeThis
nodeComma
)
// _labelSet
type _labelSet map[string]bool
func (self _labelSet) label(target string) string {
tmp := []string{}
for label, _ := range self {
if len(label) == 0 {
continue
}
tmp = append(tmp, label)
}
sort.Strings(tmp)
tmp = append([]string{target}, tmp...)
return strings.Join(tmp, ":")
}
// _declaration
type _declaration struct {
Name string
Definition _node
}
// _node*String
func _fmtNodeSliceString(input interface{}) string {
result := []string{}
inputValue := reflect.ValueOf(input)
for i := 0; i < inputValue.Len(); i++ {
result = append(result, fmt.Sprintf("%v", inputValue.Index(i).Interface()))
}
if len(result) == 0 {
return "_"
}
return strings.Join(result, " ")
}
func fmtNodeString(argument0 interface{}, arguments ...interface{}) string {
if _, yes := argument0.(string); yes {
return _fmtNodeString(argument0.(string), arguments...)
}
result := ""
if argument0 != nil {
result = fmt.Sprintf("%v", argument0)
} else if len(arguments) > 0 {
result = fmt.Sprintf("%v", arguments[0])
}
return result
}
func _fmtNodeString(head string, arguments ...interface{}) string {
tail := []interface{}{}
for _, argument := range arguments {
value := argument
if reflect.ValueOf(argument).Kind() == reflect.Slice {
tail = append(tail, _fmtNodeSliceString(value))
} else {
tail = append(tail, value)
}
}
result := fmt.Sprintf(head, tail...)
if false && result != "{}" {
result = fmt.Sprintf("{ %s }", result)
}
return result
}