mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
unless line decorator
This commit is contained in:
parent
bf416dbb1c
commit
16f4c956bf
@ -179,7 +179,7 @@ local function flatten_func(callee, args)
|
||||
return {"chain", callee, args}
|
||||
end
|
||||
|
||||
-- wraps a statement that has a line decorator
|
||||
-- transforms a statement that has a line decorator
|
||||
local function wrap_decorator(stm, dec)
|
||||
if not dec then return stm end
|
||||
|
||||
@ -189,6 +189,12 @@ local function wrap_decorator(stm, dec)
|
||||
local _, cond, fail = unpack(dec)
|
||||
if fail then fail = {"else", {fail}} end
|
||||
stm = {"if", cond, {stm}, fail}
|
||||
elseif dec[1] == "unless" then
|
||||
stm = {
|
||||
"if",
|
||||
{"not", {"parens", dec[2]}},
|
||||
{stm}
|
||||
}
|
||||
elseif dec[1] == "comprehension" then
|
||||
local _, clauses = unpack(dec)
|
||||
stm = {"comprehension", stm, clauses}
|
||||
@ -288,6 +294,7 @@ local build_grammar = wrap_env(function()
|
||||
) * Space * ((
|
||||
-- statement decorators
|
||||
key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" +
|
||||
key"unless" * Exp / mark"unless" +
|
||||
CompInner / mark"comprehension"
|
||||
) * Space)^-1 / wrap_decorator,
|
||||
|
||||
|
@ -102,6 +102,8 @@ hi = -"herfef"
|
||||
x = -[x for x in x]
|
||||
|
||||
print "hello" if cool
|
||||
print "hello" unless cool
|
||||
print "hello" unless 1212 and 3434 -- hello
|
||||
|
||||
print "nutjob"
|
||||
|
||||
|
@ -101,6 +101,12 @@ end)()
|
||||
if cool then
|
||||
print("hello")
|
||||
end
|
||||
if not (cool) then
|
||||
print("hello")
|
||||
end
|
||||
if not (1212 and 3434) then
|
||||
print("hello")
|
||||
end
|
||||
print("nutjob")
|
||||
if hello then
|
||||
_ = 343
|
||||
|
Loading…
Reference in New Issue
Block a user