Skip to content

Commit ea651d5

Browse files
committed
added commutativity checks also for segment matcher
1 parent 9e17a8f commit ea651d5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/matchers.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,9 @@ function matcher(segment::Segment, acSets)
9191
for i=length(data):-1:0
9292
subexpr = take_n(data, i)
9393

94-
if segment.predicate(subexpr)
95-
res = success(assoc(bindings, segment.name, subexpr), i)
96-
if res !== nothing
97-
break
98-
end
99-
end
94+
!segment.predicate(subexpr) && continue
95+
res = success(assoc(bindings, segment.name, subexpr), i)
96+
res !== nothing && break
10097
end
10198

10299
return res
@@ -174,7 +171,7 @@ function term_matcher_constructor(term, acSets)
174171
end
175172
return pow_term_matcher
176173
# if we want to do commutative checks, i.e. call matcher with different order of the arguments
177-
elseif acSets!==nothing && !isa(arguments(term)[1], Segment) && operation(term) in [+, *]
174+
elseif acSets!==nothing && operation(term) in [+, *]
178175
function commutative_term_matcher(success, data, bindings)
179176
!islist(data) && return nothing # if data is not a list, return nothing
180177
!iscall(car(data)) && return nothing # if first element is not a call, return nothing
@@ -185,11 +182,11 @@ function term_matcher_constructor(term, acSets)
185182
f = operation(car(data))
186183
data_args = arguments(car(data))
187184

188-
for inds in acSets(eachindex(data_args), length(arguments(term)))
185+
for inds in acSets(eachindex(data_args), length(data_args))
189186
candidate = Term{T}(f, @views data_args[inds])
190187

191188
result = loop(candidate, bindings, matchers)
192-
result !== nothing && length(data_args) == length(inds) && return success(result,1)
189+
result !== nothing && return success(result,1)
193190
end
194191
# if car(data) does not subtype to number, it might not be commutative
195192
else

0 commit comments

Comments
 (0)