aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/syntax.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
commit7066392d1c974065181d95d93274136dcd625d43 (patch)
treecf51eafc2c52cbc12246a306bca172d799193d30 /spec/inputs/syntax.yue
parent90cd12ad9ef465f3e435e1bd034dcfbe4e19d016 (diff)
downloadyuescript-7066392d1c974065181d95d93274136dcd625d43.tar.gz
yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.bz2
yuescript-7066392d1c974065181d95d93274136dcd625d43.zip
stop reusing variables, rename project.
Diffstat (limited to 'spec/inputs/syntax.yue')
-rw-r--r--spec/inputs/syntax.yue418
1 files changed, 418 insertions, 0 deletions
diff --git a/spec/inputs/syntax.yue b/spec/inputs/syntax.yue
new file mode 100644
index 0000000..4df5785
--- /dev/null
+++ b/spec/inputs/syntax.yue
@@ -0,0 +1,418 @@
1#!/this/is/ignored
2
3a = 1 + 2* 3 / 6
4
5a, bunch, go, here = another, world
6
7func arg1, arg2, another, arg3
8
9here, we = () ->, yeah
10the, different = () -> approach; yeah
11
12dad()
13dad(lord)
14hello(one,two)()
15(5 + 5)(world)
16
17fun(a)(b)
18
19fun(a) b
20
21fun(a) b, bad hello
22
23hello world what are you doing here
24
25
26what(the)[3243] world, yeck heck
27
28hairy[hands][are](gross) okay okay[world]
29
30_ = (get[something] + 5)[years]
31
32i,x = 200, 300
33
34yeah = (1 + 5) * 3
35yeah = ((1+5)*3)/2
36yeah = ((1+5)*3)/2 + i % 100
37
38whoa = (1+2) * (3+4) * (4+5)
39
40_ = ->
41 if something
42 return 1,2,4
43
44 print "hello"
45
46_ = ->
47 if hello
48 "heloo", "world"
49 else
50 no, way
51
52
53_ = -> 1,2,34
54
55return 5 + () -> 4 + 2
56
57return 5 + (() -> 4) + 2
58
59print 5 + () ->
60 _ = 34
61 good nads
62
63
64something 'else', "ya"
65
66something'else'
67something"else"
68
69_ = something[[hey]] * 2
70_ = something[======[hey]======] * 2
71_ = something[ [======[hey]======] ] * 2
72
73
74_ = something'else', 2
75_ = something"else", 2
76_ = something[[else]], 2
77_ = something[ [[else]] ], 2
78
79something 'else', 2
80something "else", 2
81something [[else]], 2
82
83_ = here(we)"go"[12123]
84
85split"abc xyz 123"\map"#"\printAll!
86
87_ = f""[a]
88_ = f""\b!
89_ = f"".c!
90
91f ""[a]
92f ""\b!
93f "".c!
94
95list{"abc", "xyz", "123"}\map"#"\printAll!
96
97_ = f{}[a]
98_ = f{}\b!
99_ = f{}.c!
100
101-- this runs
102something =
103 test: 12323
104 what: -> print "hello world"
105
106print something.test
107
108frick = hello: "world"
109
110argon =
111 num: 100
112 world: (self) ->
113 print self.num
114 return {
115 something: -> print "hi from something"
116 }
117 somethin: (self, str) ->
118 print "string is", str
119 return world: (a,b) -> print "sum", a + b
120
121something.what()
122argon\world().something()
123
124argon\somethin"200".world(1,2)
125
126x = -434
127
128x = -hello world one two
129
130hi = -"herfef"
131
132x = -[x for x in x]
133
134print "hello" if cool
135print "hello" unless cool
136print "hello" unless 1212 and 3434 -- hello
137print "hello" for i=1,10
138
139print "nutjob"
140
141if hello then _ = 343
142
143print "what" if cool
144
145((...)-> arg = {...})!
146
147x = (...) ->
148 dump {...}
149
150
151x = not true
152
153y = not(5+5)
154
155
156y = #"hello"
157
158x = #{#{},#{1},#{1,2}}
159
160_ = hello, world
161
162something\hello(what) a,b
163something\hello what
164something.hello\world a,b
165something.hello\world(1,2,3) a,b
166something
167 .hello
168 \world(1,2,3) a,b
169
170
171x = 1232
172x += 10 + 3
173j -= "hello"
174y *= 2
175y /= 100
176m %= 2
177hello ..= "world"
178
179@@something += 10
180@something += 10
181
182a["hello"] += 10
183a["hello#{tostring ff}"] += 10
184a[four].x += 10
185
186x = 0
187_ = (if ntype(v) == "fndef" then x += 1) for v in *values
188
189
190hello =
191 something: world
192 if: "hello"
193 else: 3434
194 function: "okay"
195 good: 230203
196
197
198div class: "cool"
199
200_ = 5 + what wack
201what whack + 5
202
203_ = 5 - what wack
204what whack - 5
205
206x = hello - world - something
207
208((something = with what
209 \cool 100) ->
210 print something)!
211
212if something
213 _ = 03589
214
215-- okay what about this
216
217else
218 _ = 3434
219
220
221if something
222 _ = yeah
223
224
225elseif "ymmm"
226
227 print "cool"
228
229else
230
231 _ = okay
232
233
234-- test names containing keywords
235x = notsomething
236y = ifsomething
237z = x and b
238z = x andb
239
240
241-- undelimited tables
242
243while 10 > something
244 something: "world"
245 print "yeah"
246
247x =
248 okay: sure
249
250yeah
251 okay: man
252 sure: sir
253
254hello "no comma"
255 yeah: dada
256 another: world
257
258hello "comma",
259 something: hello_world
260 frick: you
261
262-- creates one table
263another hello, one,
264 two, three, four, yeah: man
265 okay: yeah
266 fine: alright
267
268another hello, one,
269 two, three, four,
270 yeah: man, okay: yeah
271 * fine: alright,
272 okay: 1
273 * fine: alright,
274 okay: 2
275
276another hello, one, two, three, four,
277 yeah: man
278 okay: yeah
279
280another hello, one, two, three, four, yeah: man
281 okay: yeah
282
283ajax url,
284 (data) ->
285 process data,
286 (error) ->
287 print error
288
289--
290a += 3 - 5
291a *= 3 + 5
292a *= 3
293a >>= 3
294a <<= 3
295a /= func "cool"
296
297---
298
299x.then = "hello"
300x.while.true = "hello"
301x
302 .while
303 .true = "hello"
304
305--
306
307x or= "hello"
308x and= "hello"
309
310--
311
312z = a-b
313z = a -b
314z = a - b
315z = a- b
316
317
318-- cooool
319
320str = --[[
321This is a multi line comment.
322It's OK.
323]] strA \ -- comment 1
324 .. strB \ -- comment 2
325 .. strC
326
327func --[[port]] 3000, --[[ip]] "192.168.1.1"
328
329f = ->
330 a,b, \
331 c,d, \
332 e,f
333
334f = ->
335 a,b \
336 ,c,d \
337 ,e,f
338
339with obj
340 invoke(
341 --[[arg1]] \func!,
342 --[[arg2]] 123,
343 --[[arg3]] "abc"
344 )
345
346invokeA(
347 invokeB(
348 invokeC 123
349 )
350)
351
352123
353 |> invokeC
354 |> invokeB
355 |> invokeA
356
357v = {
358 a -1
359 a(
360-1)
361 a \
362- 1
363 a-1
364 a - 1
365 a -
3661
367 a-
3681
369 a - --[[123]]1
370
371 a ~1
372 a(
373~1)
374 a \
375~ 1
376 a~1
377 a ~ 1
378 a ~
3791
380 a~
3811
382 a ~ --[[123]]1
383}
384
385do
386 a = 1 \
387 + 2 \
388 * 3 /
389 4
390
391 _1 = f1 -1 \
392 + 2 \
393 + 3
394
395 _2 = f1 - 1 \
396 + 2 \
397 + 3
398
399 f2 = (x)-> print x \
400 +1
401
402 a = f2!
403 -1 |> f2
404
405 a = f2! \
406 - 1 |> f2
407
408 _1 \
409 ,_2 \
410 ,_3 \
411 ,_4 = 1 \
412 ,f 2 \
413 ,3 \
414 ,f 4, \
415 4
416
417nil
418