-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvariables.go
97 lines (87 loc) · 2.03 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
/*
* Copyright (c) Cherri
*/
package main
import "fmt"
var variables map[string]variableValue
type variableValue struct {
variableType string
valueType tokenType
value any
getAs string
coerce string
constant bool
repeatItem bool
}
var globals = map[string]variableValue{
"ShortcutInput": {
variableType: "ExtensionInput",
valueType: String,
value: "ShortcutInput",
},
"CurrentDate": {
variableType: "CurrentDate",
valueType: Date,
value: "CurrentDate",
},
"Clipboard": {
variableType: "Clipboard",
valueType: String,
value: "Clipboard",
},
"Device": {
variableType: "DeviceDetails",
valueType: String,
value: "DeviceDetails",
},
"Ask": {
variableType: "Ask",
valueType: String,
value: "Ask",
},
"RepeatItem": {
variableType: "Variable",
valueType: String,
value: "Repeat Item",
},
"RepeatIndex": {
variableType: "Variable",
valueType: String,
value: "Repeat Index",
},
}
func availableIdentifier(identifier *string) {
if v, found := variables[*identifier]; found {
if v.constant {
parserError(fmt.Sprintf("Cannot redefine constant '%s'.", *identifier))
}
if v.repeatItem {
parserError(fmt.Sprintf("Cannot redefine repeat item '%s'.", *identifier))
}
}
if _, found := globals[*identifier]; found {
parserError(fmt.Sprintf("Cannot redefine global variable '%s'.", *identifier))
}
if _, found := questions[*identifier]; found {
parserError(fmt.Sprintf("Variable conflicts with defined import question '%s'.", *identifier))
}
}
func validReference(identifier string) bool {
if _, found := globals[identifier]; found {
isInputVariable(identifier)
return true
}
if _, found := variables[identifier]; found {
return true
}
return false
}
func getVariableValue(identifier string) (*variableValue, bool) {
if value, found := globals[identifier]; found {
return &value, true
}
if value, found := variables[identifier]; found {
return &value, true
}
return nil, false
}