mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
standalone for in loop
This commit is contained in:
parent
a57efb3511
commit
1ae3e4e4cc
@ -240,7 +240,8 @@ local build_grammar = wrap(function()
|
||||
Block = Ct(Line * (Break^1 * Line)^0),
|
||||
Line = Cmt(Indent, check_indent) * Statement + _Space * Comment,
|
||||
|
||||
Statement = (Import + While + With + For + ClassDecl + Export + BreakLoop + Ct(ExpList) / flatten_or_mark"explist" * Space) * (
|
||||
Statement = (Import + While + With + For + Foreach
|
||||
+ ClassDecl + Export + BreakLoop + Ct(ExpList) / flatten_or_mark"explist" * Space) * (
|
||||
-- statement decorators
|
||||
key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
|
||||
CompInner / mark"comprehension"
|
||||
@ -270,6 +271,8 @@ local build_grammar = wrap(function()
|
||||
For = key"for" * (Name * sym"=" * Ct(Exp * sym"," * Exp * (sym"," * Exp)^-1)) *
|
||||
key"do"^-1 * Body / mark"for",
|
||||
|
||||
Foreach = key"for" * Ct(NameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) * key"do"^-1 * Body / mark"foreach",
|
||||
|
||||
Comprehension = sym"[" * Exp * CompInner * sym"]" / mark"comprehension",
|
||||
|
||||
CompInner = Ct(CompFor * CompClause^0),
|
||||
|
@ -14,4 +14,18 @@ for a=1,10
|
||||
for b = 2,43
|
||||
print a,b
|
||||
|
||||
for i in iter
|
||||
for j in yeah
|
||||
x = 343 + i + j
|
||||
print i, j
|
||||
|
||||
for x in *something
|
||||
print x
|
||||
|
||||
for k,v in pairs hello do print k,v
|
||||
|
||||
x = ->
|
||||
for x in y
|
||||
y
|
||||
|
||||
|
||||
|
@ -14,4 +14,26 @@ for a = 1, 10 do
|
||||
for b = 2, 43 do
|
||||
print(a, b)
|
||||
end
|
||||
end
|
||||
for i in iter do
|
||||
for j in yeah do
|
||||
local x = 343 + i + j
|
||||
print(i, j)
|
||||
end
|
||||
end
|
||||
do
|
||||
local _item_0 = something
|
||||
for _index_0 = 1, #_item_0 do
|
||||
local x = _item_0[_index_0]
|
||||
print(x)
|
||||
end
|
||||
end
|
||||
for k, v in pairs(hello) do
|
||||
print(k, v)
|
||||
end
|
||||
local x
|
||||
x = function()
|
||||
for x in y do
|
||||
local _ = y
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user