mirror of
https://github.com/leafo/moonscript.git
synced 2025-01-09 00:04:22 +00:00
added :
prefix operator for self assignment in table lits
This commit is contained in:
parent
24ae69cfdf
commit
f2ce353b4c
@ -251,6 +251,11 @@ local build_grammar = wrap(function()
|
|||||||
return #left == #right
|
return #left == #right
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- :name in table literal
|
||||||
|
local function self_assign(name)
|
||||||
|
return {name, name}
|
||||||
|
end
|
||||||
|
|
||||||
-- can't have P(false) because it causes preceding patterns not to run
|
-- can't have P(false) because it causes preceding patterns not to run
|
||||||
local Cut = P(function() return false end)
|
local Cut = P(function() return false end)
|
||||||
|
|
||||||
@ -402,7 +407,7 @@ local build_grammar = wrap(function()
|
|||||||
ClassDecl = key"class" * Name * (key"extends" * Exp + C"")^-1 * TableBlock / mark"class",
|
ClassDecl = key"class" * Name * (key"extends" * Exp + C"")^-1 * TableBlock / mark"class",
|
||||||
Export = key"export" * Ct(NameList) / mark"export",
|
Export = key"export" * Ct(NameList) / mark"export",
|
||||||
|
|
||||||
KeyValue = Ct((SimpleName + sym"[" * Exp * sym"]") * symx":" * (Exp + TableBlock)),
|
KeyValue = (sym":" * Name) / self_assign + Ct((SimpleName + sym"[" * Exp * sym"]") * symx":" * (Exp + TableBlock)),
|
||||||
KeyValueList = KeyValue * (sym"," * KeyValue)^0,
|
KeyValueList = KeyValue * (sym"," * KeyValue)^0,
|
||||||
KeyValueLine = CheckIndent * KeyValueList * sym","^-1,
|
KeyValueLine = CheckIndent * KeyValueList * sym","^-1,
|
||||||
|
|
||||||
|
@ -81,5 +81,12 @@ x =
|
|||||||
-- okay
|
-- okay
|
||||||
|
|
||||||
|
|
||||||
|
x = { :something, something: something }
|
||||||
|
|
||||||
|
y = {
|
||||||
|
:hi, :there, :how, :you
|
||||||
|
:thing
|
||||||
|
}
|
||||||
|
|
||||||
|
call_me "hello", :x, :y, :z
|
||||||
|
|
||||||
|
@ -100,4 +100,20 @@ x = {
|
|||||||
name = function(self, node)
|
name = function(self, node)
|
||||||
return self:value(node)
|
return self:value(node)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
x = {
|
||||||
|
something = something,
|
||||||
|
something = something
|
||||||
|
}
|
||||||
|
local y = {
|
||||||
|
hi = hi,
|
||||||
|
there = there,
|
||||||
|
how = how,
|
||||||
|
you = you,
|
||||||
|
thing = thing
|
||||||
|
}
|
||||||
|
call_me("hello", {
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
z = z
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user