-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathneverscript.ns
258 lines (216 loc) · 5.25 KB
/
neverscript.ns
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
my_int = 10
my_int = -10
my_float = 0.1
my_float = -0.1
my_string = "hey"
my_pair = (1.0, 2.0)
my_pair = (-1.0, -2.0)
my_vector = (100.0, 200.0, 300.0)
my_vector = (-1.0, -2.0, -3.0)
my_array = [1, 2, 3]
my_struct = { x=1, y=2, z=3 }
my_qb_key = #deadf00d
my_qb_key = identifiers_are_qb_keys_too
my_qb_key = `identifiers between backticks can have spaces`
// single-line comment
x = 10 // single-line comment after assignment
my_struct = {
1 // one
2 // two
3 /* three */
}
/* multi-line comment */
x = 10 /* multi-line comment
after assignment */
/*big multi-line comment
script 7 2 1 1 2 3 4
"will not compile
zzzz = - ~ ¬!!()&&&^^{}{ { { (<{ / / / *
*/
/* multi-line
/* comment
/* with */
/* /* nested */ */
/* comments */ */
script TestBasicExpressions {
x = 1
x = (1)
description = "Positive ints:"
x = (1 + 2)
x = (1 - 2)
x = (1 * 3)
x = (1 / 2)
description = "Negative ints:"
x = (-1 + -2)
x = (-1 - -2)
x = (-1 * -3)
x = (-1 / -2)
description = "Positive floats:"
x = (1.0 + 2.0)
x = (1.0 - 2.0)
x = (1.0 * 3.0)
x = (1.0 / 2.0)
description = "Negative floats:"
x = (-1.0 + -2.0)
x = (-1.0 - -2.0)
x = (-1.0 * -3.0)
x = (-1.0 / -2.0)
}
script TestStringEscaping {
description = "String containing a single backslash:"
s = "\\"
description = "String containing two backslashes:"
s = "\\\\"
description = "String containing a quote:"
s = "\""
}
script TestShorthandMath {
description = "Global variables:"
Change x += 5
Change x -= 6
Change x *= 7
Change x *= 8
description = "Local variables:"
<x> += 5
<x> -= 6
<x> *= 7
<x> /= 8
}
script TestInvocations {
description = "Invocation with checksum parameters:"
NameOfScript param1 param2 param3
description = "Invocation with assigned parameters:"
NameOfScript param1=1 param2=2.0 param3="3" param4=(4.0, 0.4) param5=[5 5.0 "5" five "five"] param6={six=6}
description = "Invocation across multiple lines:"
NameOfScript param1 = 1 \
param2 = 2.0 \
param3 = "3"
description = "Invocation across multiple lines (1st param on next line):"
NameOfScript \
param1 = 1 \
param2 = 2.0 \
param3 = "3"
}
script TestIfStatements {
description = "Basic if:"
if something {}
description = "Basic if/else:"
if something {} else {}
description = "Basic if/elseif/else:"
if c1 {} else if c2 {} else {}
description = "Multi-line if/elseif/else:"
if c1 {
b1
} else if c2 {
b2
} else {
b3
}
description = "Condition with logical not:"
if ! condition {}
description = "Condition with logical and:"
if c1 and c2 {}
description = "Condition with invocation:"
if GotParam Foo {}
description = "Condition with invocation with struct parameter:"
if IsOld {name="byxor", age=23} {
MakeYounger
}
description = "Condition with logical not with invocation with struct parameter:"
if ! IsFinished {progress=10, finish=100} {
MakeProgress
}
description = "Condition with member function invocation:"
if Object:GetCollision {
PlayCollisionSound
}
description = "Condition with member function invocation with struct parameter:"
if Object:GetCollision { length=20 } {
PlayCollisionSound
}
description = "Comparisons:"
if (c1 = c2) {}
if (c1 < c2) {}
if (c1 > c2) {}
if (c1 != c2) {}
if (c1 <= c2) {}
if (c1 >= c2) {}
// TODO(brandon): Add more variations of invocations with final struct params here
// e.g. ! Object:MemberFunction {distance=15000000}
// e.g. & struct.script {distance=15000000}
}
script TestEmptyReturn {
return
}
script TestReturningMultipleParametersOnSingleLine {
return x=1 y=2 z=3 w={what="the", heckIsHeDoingHere}
}
script TestReturningMultipleParametersOnMultipleLines {
return \
x = 11 \
y = 22 \
z = 33
}
script TestWhile {
while {
Tick
Tock
}
}
script TestNestedWhile {
while {
while {
// should have different variable names when bypassing infinite loop checks.
}
}
}
script TestRandom {
random {
10 {
print "this is gonna happen 10/15 times on average"
print "yo yo"
}
5 {
print "this is gonna happen 5/15 times on average"
print "skrrrrrt"
}
}
x = random {
9 { "Hey" }
4 { "Hello" }
10 { "Yo" }
2 { "What's up?" }
}
}
script TestIdentifiersWithKeywords {
description = "Keyword prefixes:"
script_1 = ""
or_1 = ""
if_1 = ""
and_1 = ""
else_1 = ""
while_1 = ""
break_1 = ""
random_1 = ""
return_1 = ""
description = "Actual keywords (with backtick syntax):"
`script` = ""
`or` = ""
`if` = ""
`and` = ""
`else` = ""
`while` = ""
`break` = ""
`random` = ""
`return` = ""
}
/*
TODO(brandon): Add tests for this, it won't compile
script TestFloatsToVector {
return vector = (
((1.0 * <x>) * (1.0, 0.0, 0.0)) +
((1.0 * <y>) * (0.0, 1.0, 0.0)) +
((1.0 * <z>) * (0.0, 0.0, 1.0))
)
}
*/