3 local function get_special(words
, list
)
4 local head
= list
[1] and list
[1].text
5 return head
and (words
[head
] or words
[0] and words
[0]:match(head
))
8 function M
.adjust_bracket_p(self
, indices
, nodes
, range
)
9 local parent
= nodes
[#nodes
- 1]
10 if not parent
then return true end
11 local nth
= indices
[#indices
]
13 local _
, nxt
= parent
.find_after(range
, function() return true end)
14 nth
= nxt
or #parent
+ 1
16 local sexp
= parent
[nth
] or parent
[#parent
]
17 local distance
= nth
- (sexp
and range
.start
== sexp
.finish
+ 1 and 0 or 1)
18 local rule
= get_special(self
.squarewords
, parent
)
19 if type(rule
) == "number" then
21 return -rule
> distance
23 -- XXX: the "[" check is because in Fennel fn has optional name
24 return rule
< distance
or sexp
.d
== "["
27 local grandparent
, pnth
= nodes
[#nodes
- 2], indices
[#indices
- 1]
28 if not grandparent
then return true end
29 rule
= get_special(self
.squarewords
, grandparent
)
30 if not rule
or type(rule
) ~= "table" then return true end
31 local _
, first_list_arg
= grandparent
.find_after(grandparent
[1], function(t
) return t
.is_list
end)
32 local first_nonlist_uncle
= first_list_arg
- 1
33 -- TODO: handle negative rule[1] and rule[2] (just for consistency with the scalar rules)
34 -- first_nonlist_uncle is checked so we can handle both let and named let:
35 if (not rule
[1] or first_nonlist_uncle
+ rule
[1] >= pnth
) then
36 if (not rule
[2] or rule
[2] >= distance
+ 1) then
37 if parent
[distance
] then
38 -- allows mixing [clauses] with #:when conditions in Racket for loops:
39 if parent
[distance
].is_list
then
51 function M
.last_distinguished(self
, list
)
52 return get_special(self
.lispwords
, list
)