Skip to content

Commit e944947

Browse files
committed
bring back dot/colon prefix chain
1 parent 6a057b6 commit e944947

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

moonscript/compile/value.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ return {
7171
chain = function(self, node)
7272
local callee = node[2]
7373
local callee_type = ntype(callee)
74-
if callee == -1 then
74+
local item_offset = 3
75+
if callee_type == "dot" or callee_type == "colon" then
7576
callee = self:get("scope_var")
76-
if not callee then
77+
if not (callee) then
7778
user_error("Short-dot syntax must be called within a with block")
7879
end
80+
item_offset = 2
7981
end
8082
if callee_type == "ref" and callee[2] == "super" or callee == "super" then
8183
do
@@ -112,7 +114,7 @@ return {
112114
local actions
113115
do
114116
local _with_0 = self:line()
115-
for _index_0 = 3, #node do
117+
for _index_0 = item_offset, #node do
116118
local action = node[_index_0]
117119
_with_0:append(chain_item(action))
118120
end

moonscript/compile/value.moon

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ string_chars = {
4444
chain: (node) =>
4545
callee = node[2]
4646
callee_type = ntype callee
47+
item_offset = 3
4748

48-
if callee == -1
49+
if callee_type == "dot" or callee_type == "colon"
4950
callee = @get "scope_var"
50-
if not callee then user_error "Short-dot syntax must be called within a with block"
51+
unless callee
52+
user_error "Short-dot syntax must be called within a with block"
53+
item_offset = 2
5154

5255
-- TODO: don't use string literals as ref
5356
if callee_type == "ref" and callee[2] == "super" or callee == "super"
@@ -77,7 +80,7 @@ string_chars = {
7780
callee_value = @line "(", callee_value, ")" if ntype(callee) == "exp"
7881

7982
actions = with @line!
80-
\append chain_item action for action in *node[3,]
83+
\append chain_item action for action in *node[item_offset,]
8184

8285
@line callee_value, actions
8386

moonscript/parse.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ local build_grammar = wrap_env(debug_grammar, function(root)
163163
Callable = pos(Name / mark("ref")) + SelfName + VarArg + Parens / mark("parens"),
164164
Parens = sym("(") * SpaceBreak ^ 0 * Exp * SpaceBreak ^ 0 * sym(")"),
165165
FnArgs = symx("(") * SpaceBreak ^ 0 * Ct(ExpList ^ -1) * SpaceBreak ^ 0 * sym(")") + sym("!") * -P("=") * Ct(""),
166-
Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain"),
167-
ChainItems = ChainItem ^ 1 * ColonChainItem ^ -1 + ColonChainItem,
168-
ChainItem = Invoke + symx(".") * _Name / mark("dot") + Slice + symx("[") * Exp / mark("index") * sym("]"),
169-
ColonChainItem = symx("\\") * _Name / mark("colon") * (Invoke * ChainItems ^ -1) ^ -1,
166+
Chain = (Callable + String + -S(".\\")) * ChainItems / mark("chain") + Space * (DotChainItem * ChainItems ^ -1 + ColonChain) / mark("chain"),
167+
ChainItems = ChainItem ^ 1 * ColonChain ^ -1 + ColonChain,
168+
ChainItem = Invoke + DotChainItem + Slice + symx("[") * Exp / mark("index") * sym("]"),
169+
DotChainItem = symx(".") * _Name / mark("dot"),
170+
ColonChainItem = symx("\\") * _Name / mark("colon"),
171+
ColonChain = ColonChainItem * (Invoke * ChainItems ^ -1) ^ -1,
170172
Slice = symx("[") * (SliceValue + Cc(1)) * sym(",") * (SliceValue + Cc("")) * (sym(",") * SliceValue) ^ -1 * sym("]") / mark("slice"),
171173
Invoke = FnArgs / mark("call") + SingleString / wrap_func_arg + DoubleString / wrap_func_arg + #P("[") * LuaString / wrap_func_arg,
172174
TableValue = KeyValue + Ct(Exp),

moonscript/parse.moon

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,20 @@ build_grammar = wrap_env debug_grammar, (root) ->
230230

231231
FnArgs: symx"(" * SpaceBreak^0 * Ct(ExpList^-1) * SpaceBreak^0 * sym")" + sym"!" * -P"=" * Ct""
232232

233-
-- a list of funcalls and indexes on a callable
234-
Chain: (Callable + String + -S".\\") * ChainItems / mark"chain"
233+
Chain: (Callable + String + -S".\\") * ChainItems / mark"chain" +
234+
Space * (DotChainItem * ChainItems^-1 + ColonChain) / mark"chain"
235235

236-
ChainItems: ChainItem^1 * ColonChainItem^-1 + ColonChainItem
236+
ChainItems: ChainItem^1 * ColonChain^-1 + ColonChain
237237

238238
ChainItem:
239239
Invoke +
240-
symx"." * _Name/mark"dot" +
240+
DotChainItem +
241241
Slice +
242242
symx"[" * Exp/mark"index" * sym"]"
243243

244-
ColonChainItem: symx"\\" * _Name / mark"colon" * (Invoke * ChainItems^-1)^-1
244+
DotChainItem: symx"." * _Name/mark"dot"
245+
ColonChainItem: symx"\\" * _Name / mark"colon"
246+
ColonChain: ColonChainItem * (Invoke * ChainItems^-1)^-1
245247

246248
Slice: symx"[" * (SliceValue + Cc(1)) * sym"," * (SliceValue + Cc"") *
247249
(sym"," * SliceValue)^-1 *sym"]" / mark"slice"

0 commit comments

Comments
 (0)