Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any-of fixes #326

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tree_sitter/binding/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ PyObject *query_new(PyTypeObject *cls, PyObject *args, PyObject *Py_UNUSED(kwarg

QueryPredicateAnyOf *predicate =
PyObject_New(QueryPredicateAnyOf, state->query_predicate_anyof_type);
predicate->capture_id = (predicate_step + 1)->value_id;
predicate->is_positive = is_positive;
predicate->values = values;
PyObject *predicate_obj =
Expand Down
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
Loading