Skip to content

Commit

Permalink
fix(query): correct matching logic for any-of
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jan 8, 2025
1 parent 984db5c commit 34422a2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tree_sitter/binding/query_predicates.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,25 @@ static inline bool satisfies_anyof(ModuleState *state, QueryPredicateAnyOf *pred
PyObject *nodes = nodes_for_capture_index(state, predicate->capture_id, match, tree);
for (size_t i = 0, l = (size_t)PyList_Size(nodes); i < l; ++i) {
Node *node = (Node *)PyList_GetItem(nodes, i);
PyObject *text1 = node_get_text(node, NULL), *text2;
PyObject *text1 = node_get_text(node, NULL);
bool found_match = false;

for (size_t j = 0, k = (size_t)PyList_Size(predicate->values); j < k; ++j) {
text2 = PyList_GetItem(predicate->values, j);
if (PREDICATE_CMP(text1, text2, predicate) != 1) {
Py_DECREF(text1);
Py_DECREF(nodes);
return false;
PyObject *text2 = PyList_GetItem(predicate->values, j);
if (PREDICATE_CMP(text1, text2, predicate) == 1) {
found_match = true;
break;
}
}

Py_DECREF(text1);

if (!found_match) {
Py_DECREF(nodes);
return false;
}
}

Py_DECREF(nodes);
return true;
}
Expand Down

0 comments on commit 34422a2

Please sign in to comment.