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