Skip to content

Commit 4ba4c90

Browse files
committed
Added - for implicit object.
1 parent cf0a0f3 commit 4ba4c90

File tree

9 files changed

+187
-50
lines changed

9 files changed

+187
-50
lines changed

doc/docs/doc/README.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ Yue (月) is the name of moon in Chinese and it's pronounced as [jyɛ].
1616
### An Overview of YueScript
1717
```moonscript
1818
-- import syntax
19-
import "yue" as :p, :to_lua
19+
import p, to_lua from "yue"
2020
2121
-- object literals
2222
inventory =
2323
equipment:
24-
* "sword"
25-
* "shield"
24+
- "sword"
25+
- "shield"
2626
items:
27-
* name: "potion"
27+
- name: "potion"
2828
count: 10
29-
* name: "bread"
29+
- name: "bread"
3030
count: 3
3131
3232
-- list comprehension
@@ -61,17 +61,17 @@ export 🌛 = "月之脚本"
6161
<YueDisplay>
6262
<pre>
6363
-- import syntax
64-
import "yue" as :p, :to_lua
64+
import p, to_lua from "yue"
6565

6666
-- object literals
6767
inventory =
6868
equipment:
69-
* "sword"
70-
* "shield"
69+
- "sword"
70+
- "shield"
7171
items:
72-
* name: "potion"
72+
- name: "potion"
7373
count: 10
74-
* name: "bread"
74+
- name: "bread"
7575
count: 3
7676

7777
-- list comprehension
@@ -752,67 +752,88 @@ a ??= false
752752

753753
### Implicit Object
754754

755-
You can write a list of implicit structures that starts with the symbol **\*** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent.
755+
You can write a list of implicit structures that starts with the symbol **\*** or **-** inside a table block. If you are creating implicit object, the fields of the object must be with the same indent.
756+
756757
```moonscript
758+
-- assignment with implicit object
757759
list =
758760
* 1
759761
* 2
760762
* 3
761763
764+
-- function call with implicit object
762765
func
763766
* 1
764767
* 2
765768
* 3
766769
770+
-- return with implicit object
771+
f = ->
772+
return
773+
* 1
774+
* 2
775+
* 3
776+
777+
-- table with implicit object
767778
tb =
768779
name: "abc"
769780
770781
values:
771-
* "a"
772-
* "b"
773-
* "c"
782+
- "a"
783+
- "b"
784+
- "c"
774785
775786
objects:
776-
* name: "a"
787+
- name: "a"
777788
value: 1
778789
func: => @value + 1
779790
tb:
780791
fieldA: 1
781792
782-
* name: "b"
793+
- name: "b"
783794
value: 2
784795
func: => @value + 2
785796
tb: { }
786797
787798
```
788799
<YueDisplay>
789800
<pre>
801+
-- assignment with implicit object
790802
list =
791803
* 1
792804
* 2
793805
* 3
794806

807+
-- function call with implicit object
795808
func
796809
* 1
797810
* 2
798811
* 3
799812

813+
-- return with implicit object
814+
f = ->
815+
return
816+
* 1
817+
* 2
818+
* 3
819+
820+
-- table with implicit object
800821
tb =
801822
name: "abc"
802823

803824
values:
804-
* "a"
805-
* "b"
806-
* "c"
825+
- "a"
826+
- "b"
827+
- "c"
807828

808829
objects:
809-
* name: "a"
830+
- name: "a"
810831
value: 1
811832
func: => @value + 1
812833
tb:
813834
fieldA: 1
814835

815-
* name: "b"
836+
- name: "b"
816837
value: 2
817838
func: => @value + 2
818839
tb: { }

doc/docs/zh/doc/README.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ Yue(月)是中文中“月亮”的名称。
1616
### 月之脚本概览
1717
```moonscript
1818
-- 导入语法
19-
import "yue" as :p, :to_lua
19+
import p, to_lua from "yue"
2020
2121
-- 隐式对象
2222
inventory =
2323
equipment:
24-
* "sword"
25-
* "shield"
24+
- "sword"
25+
- "shield"
2626
items:
27-
* name: "potion"
27+
- name: "potion"
2828
count: 10
29-
* name: "bread"
29+
- name: "bread"
3030
count: 3
3131
3232
-- 列表推导
@@ -61,17 +61,17 @@ export 🌛 = "月之脚本"
6161
<YueDisplay>
6262
<pre>
6363
-- 导入语法
64-
import "yue" as :p, :to_lua
64+
import p, to_lua from "yue"
6565

6666
-- 隐式对象
6767
inventory =
6868
equipment:
69-
* "sword"
70-
* "shield"
69+
- "sword"
70+
- "shield"
7171
items:
72-
* name: "potion"
72+
- name: "potion"
7373
count: 10
74-
* name: "bread"
74+
- name: "bread"
7575
count: 3
7676

7777
-- 列表推导
@@ -751,67 +751,87 @@ a ??= false
751751

752752
### 隐式对象
753753

754-
你可以在表格块内使用符号 **\*** 开始编写一系列隐式结构。如果你正在创建隐式对象,对象的字段必须具有相同的缩进。
754+
你可以在表格块内使用符号 **\*** 或是 **-** 开始编写一系列隐式结构。如果你正在创建隐式对象,对象的字段必须具有相同的缩进。
755+
755756
```moonscript
757+
-- 赋值时使用隐式对象
756758
list =
757759
* 1
758760
* 2
759761
* 3
760762
763+
-- 函数调用时使用隐式对象
761764
func
762765
* 1
763766
* 2
764767
* 3
765768
769+
-- 返回时使用隐式对象
770+
f = ->
771+
return
772+
* 1
773+
* 2
774+
* 3
775+
776+
-- 表格时使用隐式对象
766777
tb =
767778
name: "abc"
768779
769780
values:
770-
* "a"
771-
* "b"
772-
* "c"
781+
- "a"
782+
- "b"
783+
- "c"
773784
774785
objects:
775-
* name: "a"
786+
- name: "a"
776787
value: 1
777788
func: => @value + 1
778789
tb:
779790
fieldA: 1
780791
781-
* name: "b"
792+
- name: "b"
782793
value: 2
783794
func: => @value + 2
784795
tb: { }
785-
786796
```
787797
<YueDisplay>
788798
<pre>
799+
-- 赋值时使用隐式对象
789800
list =
790801
* 1
791802
* 2
792803
* 3
793804

805+
-- 函数调用时使用隐式对象
794806
func
795807
* 1
796808
* 2
797809
* 3
798810

811+
-- 返回时使用隐式对象
812+
f = ->
813+
return
814+
* 1
815+
* 2
816+
* 3
817+
818+
-- 表格时使用隐式对象
799819
tb =
800820
name: "abc"
801821

802822
values:
803-
* "a"
804-
* "b"
805-
* "c"
823+
- "a"
824+
- "b"
825+
- "c"
806826

807827
objects:
808-
* name: "a"
828+
- name: "a"
809829
value: 1
810830
func: => @value + 1
811831
tb:
812832
fieldA: 1
813833

814-
* name: "b"
834+
- name: "b"
815835
value: 2
816836
func: => @value + 2
817837
tb: { }

spec/inputs/tables.yue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,24 @@ menus =
245245
click: ->
246246
}
247247

248+
_ =
249+
boolean:
250+
- true
251+
- false
252+
float:
253+
- 3.14
254+
- -6.8523015e+5
255+
int:
256+
- 123
257+
- -0b1010_0111_0100_1010_1110
258+
null:
259+
nodeName: 'node'
260+
parent: nil
261+
string:
262+
- 'Hello world'
263+
- "newline
264+
newline2"
265+
248266
tb = {...other}
249267

250268
tbMix = {

spec/inputs/with.yue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,8 @@ do
161161
if .v
162162
break .a
163163

164+
a = while true
165+
break with? tb
166+
break 1
167+
164168
nil

spec/outputs/codes_from_doc.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ func({
339339
2,
340340
3
341341
})
342+
local f
343+
f = function()
344+
return {
345+
1,
346+
2,
347+
3
348+
}
349+
end
342350
local tb = {
343351
name = "abc",
344352
values = {
@@ -2548,6 +2556,14 @@ func({
25482556
2,
25492557
3
25502558
})
2559+
local f
2560+
f = function()
2561+
return {
2562+
1,
2563+
2,
2564+
3
2565+
}
2566+
end
25512567
local tb = {
25522568
name = "abc",
25532569
values = {

spec/outputs/codes_from_doc_zh.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ func({
339339
2,
340340
3
341341
})
342+
local f
343+
f = function()
344+
return {
345+
1,
346+
2,
347+
3
348+
}
349+
end
342350
local tb = {
343351
name = "abc",
344352
values = {
@@ -2542,6 +2550,14 @@ func({
25422550
2,
25432551
3
25442552
})
2553+
local f
2554+
f = function()
2555+
return {
2556+
1,
2557+
2,
2558+
3
2559+
}
2560+
end
25452561
local tb = {
25462562
name = "abc",
25472563
values = {

0 commit comments

Comments
 (0)