summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md34
-rw-r--r--README.md2
-rwxr-xr-xdoc/docs/doc/README.md80
3 files changed, 109 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b60bf8a..1c87ff7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
2 2
3The 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. 3The 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.8.2 5## v0.8.5
6 6
7### Fixed Issues 7### Fixed Issues
8 8
@@ -11,6 +11,38 @@ The implementation for the original Moonscript language 0.5.0 can be found in th
11 11
12### Added Features 12### Added Features
13 13
14* Nil coalescing operator.
15```moonscript
16local a, b, c, d
17a = b ?? c ?? d
18func a ?? {}
19
20a ??= false
21```
22Compiles to:
23```lua
24local a, b, c, d
25if b ~= nil then
26 a = b
27else
28 if c ~= nil then
29 a = c
30 else
31 a = d
32 end
33end
34func((function()
35 if a ~= nil then
36 return a
37 else
38 return { }
39 end
40end)())
41if a == nil then
42 a = false
43end
44```
45
14* New metatable syntax. 46* New metatable syntax.
15 ```moonscript 47 ```moonscript
16 #: mt = tb 48 #: mt = tb
diff --git a/README.md b/README.md
index 479c232..0eaa557 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ].
21* Support most of the features from Moonscript language. Generate Lua codes in the same way like the original compiler. 21* Support most of the features from Moonscript language. Generate Lua codes in the same way like the original compiler.
22* Reserve line numbers from source file in the compiled Lua codes to help debugging. 22* Reserve line numbers from source file in the compiled Lua codes to help debugging.
23* More features like macro, existential operator, pipe operator, Javascript-like export syntax and etc. 23* More features like macro, existential operator, pipe operator, Javascript-like export syntax and etc.
24* See other details in the [changelog](./CHANGELOG.md). Find document from [here](http://yuescript.org). 24* See other details in the [changelog](./CHANGELOG.md). Find document [here](http://yuescript.org).
25 25
26 26
27 27
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 138d035..b4ae85f 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -38,7 +38,7 @@ inventory =
38apple = 38apple =
39 size: 15 39 size: 15
40 index#: {color: 0x00ffff} 40 index#: {color: 0x00ffff}
41p apple.color, apple.#?, apple.index# 41p apple.color, apple.index# if apple.#?
42 42
43-- js-like export syntax 43-- js-like export syntax
44export yuescript = "月之脚本" 44export yuescript = "月之脚本"
@@ -70,7 +70,7 @@ inventory =
70apple = 70apple =
71 size: 15 71 size: 15
72 index#: {color: 0x00ffff} 72 index#: {color: 0x00ffff}
73p apple.color, apple.#?, apple.index# 73p apple.color, apple.index# if apple.#?
74 74
75-- js-like export syntax 75-- js-like export syntax
76export yuescript = "月之脚本" 76export yuescript = "月之脚本"
@@ -160,9 +160,11 @@ Usage: yue [options|files|directories] ...
160  Execute raw codes: **yue -e 'print 123'** 160  Execute raw codes: **yue -e 'print 123'**
161  Execute a Yuescript file: **yue -e main.yue** 161  Execute a Yuescript file: **yue -e main.yue**
162 162
163
163## Macro 164## Macro
164 165
165### Common Usage 166### Common Usage
167
166Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation. 168Macro function is used for evaluating a string in the compile time and insert the generated codes into final compilation.
167 169
168```moonscript 170```moonscript
@@ -298,7 +300,6 @@ export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
298export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]" 300export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
299export macro foreach = (items, action)-> "for _ in *#{items} 301export macro foreach = (items, action)-> "for _ in *#{items}
300 #{action}" 302 #{action}"
301
302-- file main.yue 303-- file main.yue
303-- import function is not available in browser, try it in a real environment 304-- import function is not available in browser, try it in a real environment
304--[[ 305--[[
@@ -311,9 +312,21 @@ import "utils" as {
311</pre> 312</pre>
312</YueDisplay> 313</YueDisplay>
313 314
315
314## Operator 316## Operator
315 317
316All of Lua’s binary and unary operators are available. Additionally **!=** is as an alias for **~=**. And Yuescipt offers some special operator to write more expressive codes. 318All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes.
319
320```moonscript
321tb\func! if tb ~= nil
322tb::func! if tb != nil
323```
324<YueDisplay>
325<pre>
326tb\func! if tb ~= nil
327tb::func! if tb != nil
328</pre>
329</YueDisplay>
317 330
318### Metatable 331### Metatable
319 332
@@ -373,7 +386,6 @@ print tb.item
373tb = ["value"]#: 123 386tb = ["value"]#: 123
374tb.index# = tb.# 387tb.index# = tb.#
375print tb.value 388print tb.value
376
377tb.# = __index: {item: "hello"} 389tb.# = __index: {item: "hello"}
378print tb.item 390print tb.item
379</pre> 391</pre>
@@ -460,6 +472,27 @@ readFile "example.txt"
460</pre> 472</pre>
461</YueDisplay> 473</YueDisplay>
462 474
475### Nil Coalescing
476
477The nil-coalescing operator **??** returns the value of its left-hand operand if it isn't **nil**; otherwise, it evaluates the right-hand operand and returns its result. The **??** operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-nil.
478```moonscript
479local a, b, c, d
480a = b ?? c ?? d
481func a ?? {}
482
483a ??= false
484```
485<YueDisplay>
486<pre>
487local a, b, c, d
488a = b ?? c ?? d
489func a ?? {}
490
491a ??= false
492</pre>
493</YueDisplay>
494
495
463## Module 496## Module
464 497
465### Import 498### Import
@@ -593,10 +626,33 @@ export default ->
593</pre> 626</pre>
594</YueDisplay> 627</YueDisplay>
595 628
629
596## Whitespace 630## Whitespace
597 631
598Yuescript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs. 632Yuescript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs.
599 633
634### Multiline Chaining
635
636You can write multi-line chaining function calls with a same indent.
637```moonscript
638Rx.Observable
639 .fromRange 1, 8
640 \filter (x)-> x % 2 == 0
641 \concat Rx.Observable.of 'who do we appreciate'
642 \map (value)-> value .. '!'
643 \subscribe print
644```
645<YueDisplay>
646<pre>
647Rx.Observable
648 .fromRange 1, 8
649 \filter (x)-> x % 2 == 0
650 \concat Rx.Observable.of 'who do we appreciate'
651 \map (value)-> value .. '!'
652 \subscribe print
653</pre>
654</YueDisplay>
655
600## Assignment 656## Assignment
601 657
602The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement. 658The variable is dynamic typed and is defined as local by default. But you can change the scope of declaration by **local** and **global** statement.
@@ -617,6 +673,7 @@ s ..= "world"
617arg or= "default value" 673arg or= "default value"
618``` 674```
619<YueDisplay> 675<YueDisplay>
676
620<pre> 677<pre>
621hello = "world" 678hello = "world"
622a, b, c = 1, 2, 3 679a, b, c = 1, 2, 3
@@ -649,6 +706,7 @@ do
649 B = 2 706 B = 2
650``` 707```
651<YueDisplay> 708<YueDisplay>
709
652<pre> 710<pre>
653do 711do
654 local * 712 local *
@@ -2458,6 +2516,18 @@ This is effectively the same as import, but we can rename fields we want to extr
2458</pre> 2516</pre>
2459</YueDisplay> 2517</YueDisplay>
2460 2518
2519You can write default values while doing destructuring like:
2520
2521```moonscript
2522{:name = "nameless", :job = "jobless"} = person
2523```
2524<YueDisplay>
2525<pre>
2526{:name = "nameless", :job = "jobless"} = person
2527</pre>
2528</YueDisplay>
2529
2530
2461### Destructuring In Other Places 2531### Destructuring In Other Places
2462 2532
2463Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: 2533Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: