bring back dot/colon prefix chain

This commit is contained in:
leaf corcoran 2015-09-29 02:18:58 -07:00
parent 6a057b6b56
commit e94494721a
4 changed files with 24 additions and 15 deletions

View File

@ -71,11 +71,13 @@ return {
chain = function(self, node)
local callee = node[2]
local callee_type = ntype(callee)
if callee == -1 then
local item_offset = 3
if callee_type == "dot" or callee_type == "colon" then
callee = self:get("scope_var")
if not callee then
if not (callee) then
user_error("Short-dot syntax must be called within a with block")
end
item_offset = 2
end
if callee_type == "ref" and callee[2] == "super" or callee == "super" then
do
@ -112,7 +114,7 @@ return {
local actions
do
local _with_0 = self:line()
for _index_0 = 3, #node do
for _index_0 = item_offset, #node do
local action = node[_index_0]
_with_0:append(chain_item(action))
end

View File

@ -44,10 +44,13 @@ string_chars = {
chain: (node) =>
callee = node[2]
callee_type = ntype callee
item_offset = 3
if callee == -1
if callee_type == "dot" or callee_type == "colon"
callee = @get "scope_var"
if not callee then user_error "Short-dot syntax must be called within a with block"
unless callee
user_error "Short-dot syntax must be called within a with block"
item_offset = 2
-- TODO: don't use string literals as ref
if callee_type == "ref" and callee[2] == "super" or callee == "super"
@ -77,7 +80,7 @@ string_chars = {
callee_value = @line "(", callee_value, ")" if ntype(callee) == "exp"
actions = with @line!
\append chain_item action for action in *node[3,]
\append chain_item action for action in *node[item_offset,]
@line callee_value, actions

View File

@ -163,10 +163,12 @@ local build_grammar = wrap_env(debug_grammar, function(root)
Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain"),
ChainItems = ChainItem ^ 1 * ColonChainItem ^ -1 + ColonChainItem,
ChainItem = Invoke + symx(".") * _Name / mark("dot") + Slice + symx("[") * Exp / mark("index") * sym("]"),
ColonChainItem = symx("\\") * _Name / mark("colon") * (Invoke * ChainItems ^ -1) ^ -1,
Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain") + Space * (DotChainItem * ChainItems ^ -1 + ColonChain) / mark("chain"),
ChainItems = ChainItem ^ 1 * ColonChain ^ -1 + ColonChain,
ChainItem = Invoke + DotChainItem + Slice + symx("[") * Exp / mark("index") * sym("]"),
DotChainItem = symx(".") * _Name / mark("dot"),
ColonChainItem = symx("\\") * _Name / mark("colon"),
ColonChain = ColonChainItem * (Invoke * ChainItems ^ -1) ^ -1,
Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"),
Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + #P("[") * LuaString / wrap_func_arg,
TableValue = KeyValue + Ct(Exp),

View File

@ -230,18 +230,20 @@ build_grammar = wrap_env debug_grammar, (root) ->
FnArgs: symx"(" * SpaceBreak^0 * Ct(ExpList^-1) * SpaceBreak^0 * sym")" + sym"!" * -P"=" * Ct""
-- a list of funcalls and indexes on a callable
Chain: (Callable + String + -S".\\") * ChainItems / mark"chain"
Chain: (Callable + String + -S".\\") * ChainItems / mark"chain" +
Space * (DotChainItem * ChainItems^-1 + ColonChain) / mark"chain"
ChainItems: ChainItem^1 * ColonChainItem^-1 + ColonChainItem
ChainItems: ChainItem^1 * ColonChain^-1 + ColonChain
ChainItem:
Invoke +
symx"." * _Name/mark"dot" +
DotChainItem +
Slice +
symx"[" * Exp/mark"index" * sym"]"
ColonChainItem: symx"\\" * _Name / mark"colon" * (Invoke * ChainItems^-1)^-1
DotChainItem: symx"." * _Name/mark"dot"
ColonChainItem: symx"\\" * _Name / mark"colon"
ColonChain: ColonChainItem * (Invoke * ChainItems^-1)^-1
Slice: symx"[" * (SliceValue + Cc(1)) * sym"," * (SliceValue + Cc"") *
(sym"," * SliceValue)^-1 *sym"]" / mark"slice"