diff options
-rw-r--r-- | CHANGELOG.md | 20 | ||||
-rwxr-xr-x | doc/docs/doc/README.md | 93 |
2 files changed, 113 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b44dae..9ac9811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -2,6 +2,26 @@ | |||
2 | 2 | ||
3 | The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. | 3 | The implementation for the original Moonscript language 0.5.0 can be found in the `0.5.0` branch of Yuescript. The Moonscript with fixes and new features is in the main branch of Yuescript. Here are the changelogs for each Yuescript version. |
4 | 4 | ||
5 | ## v0.17.0 | ||
6 | |||
7 | ### Added Features | ||
8 | |||
9 | * Added In-expression syntax to do range checking. In-expression can be used in switch statement as a new clause. | ||
10 | ```moonscript | ||
11 | a = 5 | ||
12 | if a in [1, 10] or a in (20, 30) or a in {77, 88} or a not in {100, 200} | ||
13 | print "(1 <= a <= 10) or (20 < a < 30) or (a == 77 or a == 88) or not (a == 100 or a == 200)" | ||
14 | |||
15 | switch a when not in [1, 10] | ||
16 | print "not (1 <= a <= 10)" | ||
17 | ``` | ||
18 | * Added metamethod name checking for chain expression. | ||
19 | |||
20 | ### Fixed Issues | ||
21 | |||
22 | * Fixed a LuaJIT module loading issue. | ||
23 | * Fixed built-in $FILE macro does not escape backslash on Windows. | ||
24 | |||
5 | ## v0.16.4 | 25 | ## v0.16.4 |
6 | 26 | ||
7 | ### Added Features | 27 | ### Added Features |
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 3a7b1e7..2c21a37 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -2355,6 +2355,52 @@ print "You're lucky!" unless math.random! > 0.1 | |||
2355 | </pre> | 2355 | </pre> |
2356 | </YueDisplay> | 2356 | </YueDisplay> |
2357 | 2357 | ||
2358 | ### In Expression | ||
2359 | |||
2360 | You can write range checking code with an `in-expression`. | ||
2361 | |||
2362 | ```moonscript | ||
2363 | a = 5 | ||
2364 | |||
2365 | if a in [1, 10] | ||
2366 | print "a is in range from 1 to 10" | ||
2367 | |||
2368 | if a not in [1, 10] | ||
2369 | print "a is not in range from 1 to 10" | ||
2370 | |||
2371 | if a in (0, 11) | ||
2372 | print "a is between 0 and 11 with open intervals" | ||
2373 | |||
2374 | if a in {1, 3, 5, 7} | ||
2375 | print "checking equality with discrete values" | ||
2376 | ``` | ||
2377 | <YueDisplay> | ||
2378 | <pre> | ||
2379 | a = 5 | ||
2380 | |||
2381 | if a in [1, 10] | ||
2382 | print "a is in range from 1 to 10" | ||
2383 | |||
2384 | if a not in [1, 10] | ||
2385 | print "a is not in range from 1 to 10" | ||
2386 | |||
2387 | if a in (0, 11) | ||
2388 | print "a is between 0 and 11 with open intervals" | ||
2389 | |||
2390 | if a in {1, 3, 5, 7} | ||
2391 | print "checking equality with discrete values" | ||
2392 | </pre> | ||
2393 | </YueDisplay> | ||
2394 | |||
2395 | ```moonscript | ||
2396 | print "You're lucky!" unless math.random! > 0.1 | ||
2397 | ``` | ||
2398 | <YueDisplay> | ||
2399 | <pre> | ||
2400 | print "You're lucky!" unless math.random! > 0.1 | ||
2401 | </pre> | ||
2402 | </YueDisplay> | ||
2403 | |||
2358 | ## Line Decorators | 2404 | ## Line Decorators |
2359 | 2405 | ||
2360 | For convenience, the for loop and if statement can be applied to single statements at the end of the line: | 2406 | For convenience, the for loop and if statement can be applied to single statements at the end of the line: |
@@ -2525,6 +2571,53 @@ switch item | |||
2525 | </pre> | 2571 | </pre> |
2526 | </YueDisplay> | 2572 | </YueDisplay> |
2527 | 2573 | ||
2574 | ### Range Matching | ||
2575 | |||
2576 | You can do range matching in a switch when clause using `In` expressions. | ||
2577 | |||
2578 | ```moonscript | ||
2579 | value = 5 | ||
2580 | |||
2581 | switch item | ||
2582 | -- range checking with closed interval | ||
2583 | when in [1, 3] | ||
2584 | print "1 <= value <= 3" | ||
2585 | |||
2586 | -- range checking with open and closed interval | ||
2587 | when in (6, 8] | ||
2588 | print "6 < value <= 8" | ||
2589 | |||
2590 | -- not in range checking | ||
2591 | when not in [1, 10) | ||
2592 | print "not (1 < value <= 10)" | ||
2593 | |||
2594 | -- checking discrete values | ||
2595 | when in {11, 21, 99} | ||
2596 | print "value is 11, 21 or 99" | ||
2597 | ``` | ||
2598 | <YueDisplay> | ||
2599 | <pre> | ||
2600 | value = 5 | ||
2601 | |||
2602 | switch item | ||
2603 | -- range checking with closed interval | ||
2604 | when in [1, 3] | ||
2605 | print "1 <= value <= 3" | ||
2606 | |||
2607 | -- range checking with open and closed interval | ||
2608 | when in (6, 8] | ||
2609 | print "6 < value <= 8" | ||
2610 | |||
2611 | -- not in range checking | ||
2612 | when not in [1, 10) | ||
2613 | print "not (1 < value <= 10)" | ||
2614 | |||
2615 | -- checking discrete values | ||
2616 | when in {11, 21, 99} | ||
2617 | print "value is 11, 21 or 99" | ||
2618 | </pre> | ||
2619 | </YueDisplay> | ||
2620 | |||
2528 | ## Object Oriented Programming | 2621 | ## Object Oriented Programming |
2529 | 2622 | ||
2530 | In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the Yuescript code at first, then look into the Lua code if you wish to know the implementation details. | 2623 | In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the Yuescript code at first, then look into the Lua code if you wish to know the implementation details. |