added : prefix operator for self assignment in table lits

This commit is contained in:
leaf corcoran 2011-08-28 23:40:51 -07:00
parent 24ae69cfdf
commit f2ce353b4c
3 changed files with 30 additions and 2 deletions

View File

@ -251,6 +251,11 @@ local build_grammar = wrap(function()
return #left == #right
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
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",
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,
KeyValueLine = CheckIndent * KeyValueList * sym","^-1,

View File

@ -81,5 +81,12 @@ x =
-- okay
x = { :something, something: something }
y = {
:hi, :there, :how, :you
:thing
}
call_me "hello", :x, :y, :z

View File

@ -101,3 +101,19 @@ x = {
return self:value(node)
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
})