add ref value type

This commit is contained in:
leaf corcoran 2013-12-26 23:07:24 -08:00
parent ec35fc03d2
commit 09f4cea638
5 changed files with 19 additions and 12 deletions

View File

@ -293,6 +293,9 @@ local value_compilers = {
self_class_colon = function(self, node)
return "self.__class:" .. self:value(node[2])
end,
ref = function(self, value)
return tostring(value[2])
end,
raw_value = function(self, value)
local sup = self:get("super")
if value == "super" and sup then

View File

@ -183,6 +183,10 @@ value_compilers =
self_class_colon: (node) =>
"self.__class:"..@value node[2]
-- a variable reference
ref: (value) =>
tostring value[2]
-- catch all pure string values
raw_value: (value) =>
sup = @get"super"

View File

@ -175,7 +175,7 @@ local _chain_assignable = { index = true, dot = true, slice = true }
local function is_assignable(node)
local t = ntype(node)
return t == "self" or t == "value" or t == "self_class" or
return t == "ref" or t == "self" or t == "value" or t == "self_class" or
t == "chain" and _chain_assignable[ntype(node[#node])] or
t == "table"
end
@ -511,7 +511,7 @@ local build_grammar = wrap_env(function()
LuaStringOpen = sym"[" * P"="^0 * "[" / trim,
LuaStringClose = "]" * P"="^0 * "]",
Callable = Name + Parens / mark"parens",
Callable = Name / mark"ref" + Parens / mark"parens",
Parens = sym"(" * Exp * sym")",
FnArgs = symx"(" * Ct(ExpList^-1) * sym")" + sym"!" * -P"=" * Ct"",

View File

@ -100,13 +100,13 @@ extract_assign_names = function(name, accum, prefix)
suffix = join(prefix, {
suffix
})
local t = ntype(value)
if t == "value" or t == "chain" or t == "self" then
local _exp_0 = ntype(value)
if "value" == _exp_0 or "ref" == _exp_0 or "chain" == _exp_0 or "self" == _exp_0 then
insert(accum, {
value,
suffix
})
elseif t == "table" then
elseif "table" == _exp_0 then
extract_assign_names(value, accum, suffix)
else
user_error("Can't destructure value of type: " .. tostring(ntype(value)))

View File

@ -43,13 +43,13 @@ extract_assign_names = (name, accum={}, prefix={}) ->
suffix = join prefix, {suffix}
t = ntype value
if t == "value" or t == "chain" or t == "self"
insert accum, {value, suffix}
elseif t == "table"
extract_assign_names value, accum, suffix
else
user_error "Can't destructure value of type: #{ntype value}"
switch ntype value
when "value", "ref", "chain", "self"
insert accum, {value, suffix}
when "table"
extract_assign_names value, accum, suffix
else
user_error "Can't destructure value of type: #{ntype value}"
accum