Skip to content

Commit ccfe66f

Browse files
committed
Made ; work as statements separator.
1 parent 8a01e9c commit ccfe66f

18 files changed

Lines changed: 248 additions & 154 deletions

doc/docs/doc/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,19 @@ print ok, count, first
15881588

15891589
YueScript 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.
15901590

1591+
### Statement Separator
1592+
1593+
A statement normally ends at a line break. You can also use a semicolon `;` to explicitly terminate a statement, which allows writing multiple statements on the same line:
1594+
1595+
```moonscript
1596+
a = 1; b = 2; print a + b
1597+
```
1598+
<YueDisplay>
1599+
<pre>
1600+
a = 1; b = 2; print a + b
1601+
</pre>
1602+
</YueDisplay>
1603+
15911604
### Multiline Chaining
15921605

15931606
You can write multi-line chaining function calls with a same indent.

doc/docs/zh/doc/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,19 @@ print ok, count, first
15861586

15871587
月之脚本是一个对空白敏感的语言。你必须在相同的缩进中使用空格 **' '** 或制表符 **'\t'** 来编写一些代码块,如函数体、值列表和一些控制块。包含不同空白的表达式可能意味着不同的事情。制表符被视为4个空格,但最好不要混合使用空格和制表符。
15881588

1589+
### 语句分隔符
1590+
1591+
一条语句通常以换行结束。你也可以使用分号 `;` 显式结束一条语句,从而在同一行中编写多条语句:
1592+
1593+
```moonscript
1594+
a = 1; b = 2; print a + b
1595+
```
1596+
<YueDisplay>
1597+
<pre>
1598+
a = 1; b = 2; print a + b
1599+
</pre>
1600+
</YueDisplay>
1601+
15891602
### 多行链式调用
15901603

15911604
你可以使用相同的缩进来编写多行链式函数调用。

spec/inputs/syntax.yue

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ a, bunch, go, here = another, world, nil, nil
77
func arg1, arg2, another, arg3
88

99
here, we = () ->, yeah
10-
the, different = () -> approach; yeah
10+
the, different = (() -> approach), yeah
1111

1212
dad()
1313
dad(lord)
@@ -321,7 +321,7 @@ ajax url,
321321
(error) ->
322322
print error
323323

324-
--
324+
--
325325
a += 3 - 5
326326
a *= 3 + 5
327327
a *= 3
@@ -480,11 +480,54 @@ do
480480

481481
do
482482
return res if res ~= ""
483-
483+
484484

485485
do
486486
return res if res ~= ""
487487
--
488488

489+
do
490+
a = 1; b = 2; c = a + b
491+
print a; print b; print c
492+
493+
f = ->
494+
a = 1; b = 2; a + b
495+
496+
a = 1;
497+
b = 2;
498+
499+
success, result = try func!; print result if success
500+
501+
value = "foo"; print value; value = value .. "bar"; print value
502+
503+
do
504+
if ok then print "ok!"; return 42
505+
506+
for i=1,3
507+
print i; continue
508+
509+
n = 0
510+
while n < 2
511+
print "n=", n; n += 1
512+
513+
obj = {}
514+
obj\set 10; obj\get!; print "done"
515+
516+
with tbl
517+
\push 1; print "push"
518+
519+
a = 5
520+
if a > 3
521+
print "big"; b = a * 2; print b
522+
else
523+
print "small"; b = a
524+
525+
try
526+
x = 1; y = 2; print x + y
527+
catch err
528+
print "error:", err
529+
530+
q = 1;; w = 2;;; e = 3; print q, w, e;
531+
489532
nil
490533

spec/inputs/unicode/syntax.yue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
函数 参数1, 参数2, 另外, 参数3
88

99
这里, 我们 = () ->, 是的
10-
这个, 不同 = () -> 方法; 是的
10+
这个, 不同 = (() -> 方法), 是的
1111

1212
爸爸()
1313
爸爸(主)

spec/inputs/unicode/whitespace.yue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ v = ->
9797
变量c -- v3
9898

9999
v1, v2, \
100-
v3 = ->
101-
变量a; \-- 函数结束于v1
100+
v3 = (->
101+
变量a), \-- 函数结束于v1
102102
变量b, \-- v2
103103
变量c -- v3
104104

105105
变量a, 变量b, \
106106
变量c, 变量d, \
107107
变量e, 变量f = 1, \
108-
f2
109-
:abc; \-- 参数2
108+
(f2
109+
:abc), \-- 参数2
110110
3, \
111111
4, \
112-
函数5 abc; \-- 参数5
112+
函数5(abc), \-- 参数5
113113
6
114114

115115
for 变量a, \-- 解构1

spec/inputs/whitespace.yue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,19 @@ v = ->
128128
c -- v3
129129

130130
v1, v2, \
131-
v3 = ->
132-
a; \-- end of function for v1
131+
v3 = (->
132+
a), \-- end of function for v1
133133
b, \-- v2
134134
c -- v3
135135

136136
a, b, \
137137
c, d, \
138138
e, f = 1, \
139-
f2
140-
:abc; \-- arg2
139+
(f2
140+
:abc), \-- arg2
141141
3, \
142142
4, \
143-
f5 abc; \-- arg5
143+
f5(abc), \-- arg5
144144
6
145145

146146
for a, \-- destruct 1

spec/outputs/codes_from_doc.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ end
756756
local first = select(1, ...)
757757
return print(ok, count, first)
758758
end)(fn(true))
759+
local a = 1
760+
local b = 2
761+
print(a + b)
759762
Rx.Observable.fromRange(1, 8):filter(function(x)
760763
return x % 2 == 0
761764
end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -3283,6 +3286,9 @@ end
32833286
local first = select(1, ...)
32843287
return print(ok, count, first)
32853288
end)(fn(true))
3289+
local a = 1
3290+
local b = 2
3291+
print(a + b)
32863292
Rx.Observable.fromRange(1, 8):filter(function(x)
32873293
return x % 2 == 0
32883294
end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)

spec/outputs/codes_from_doc_zh.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ end
756756
local first = select(1, ...)
757757
return print(ok, count, first)
758758
end)(fn(true))
759+
local a = 1
760+
local b = 2
761+
print(a + b)
759762
Rx.Observable.fromRange(1, 8):filter(function(x)
760763
return x % 2 == 0
761764
end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)
@@ -3277,6 +3280,9 @@ end
32773280
local first = select(1, ...)
32783281
return print(ok, count, first)
32793282
end)(fn(true))
3283+
local a = 1
3284+
local b = 2
3285+
print(a + b)
32803286
Rx.Observable.fromRange(1, 8):filter(function(x)
32813287
return x % 2 == 0
32823288
end):concat(Rx.Observable.of('who do we appreciate')):map(function(value)

spec/outputs/syntax.lua

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ func(arg1, arg2, another, arg3)
55
local we
66
here, we = function() end, yeah
77
local the, different
8-
the, different = function()
8+
the, different = (function()
99
return approach
10-
end, yeah
10+
end), yeah
1111
dad()
1212
dad(lord)
1313
hello(one, two)();
@@ -441,4 +441,74 @@ do
441441
end
442442
end)())
443443
end
444+
do
445+
a = 1
446+
local b = 2
447+
local c = a + b
448+
print(a)
449+
print(b)
450+
print(c)
451+
f = function()
452+
a = 1
453+
b = 2
454+
return a + b
455+
end
456+
a = 1
457+
b = 2
458+
local success, result = pcall(function()
459+
return func()
460+
end)
461+
if success then
462+
print(result)
463+
end
464+
local value = "foo"
465+
print(value)
466+
value = value .. "bar"
467+
print(value)
468+
do
469+
if ok then
470+
print("ok!")
471+
end
472+
return 42
473+
end
474+
for i = 1, 3 do
475+
print(i)
476+
goto _continue_0
477+
::_continue_0::
478+
end
479+
local n = 0
480+
while n < 2 do
481+
print("n=", n)
482+
n = n + 1
483+
end
484+
local obj = { }
485+
obj:set(10)
486+
obj:get()
487+
print("done")
488+
do
489+
local _with_0 = tbl
490+
_with_0:push(1)
491+
print("push")
492+
end
493+
a = 5
494+
if a > 3 then
495+
print("big")
496+
b = a * 2
497+
print(b)
498+
else
499+
print("small")
500+
b = a
501+
end
502+
xpcall(function()
503+
x = 1
504+
y = 2
505+
return print(x + y)
506+
end, function(err)
507+
return print("error:", err)
508+
end)
509+
local q = 1
510+
local w = 2
511+
local e = 3
512+
print(q, w, e)
513+
end
444514
return nil

spec/outputs/unicode/syntax.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ _u51fd_u6570(_u53c2_u65701, _u53c2_u65702, _u53e6_u5916, _u53c2_u65703)
55
local _u6211_u4eec
66
_u8fd9_u91cc, _u6211_u4eec = function() end, _u662f_u7684
77
local _u8fd9_u4e2a, _u4e0d_u540c
8-
_u8fd9_u4e2a, _u4e0d_u540c = function()
8+
_u8fd9_u4e2a, _u4e0d_u540c = (function()
99
return _u65b9_u6cd5
10-
end, _u662f_u7684
10+
end), _u662f_u7684
1111
_u7238_u7238()
1212
_u7238_u7238(_u4e3b)
1313
_u4f60_u597d(_u4e00, _u4e8c)();

0 commit comments

Comments
 (0)