Fix population of subgraph nodes when analyzing queries

This commit is contained in:
Max Brunsfeld 2020-06-25 15:05:44 -07:00
parent 9fb39b8954
commit 891de051e2
2 changed files with 16 additions and 8 deletions

View file

@ -2083,6 +2083,14 @@ fn test_query_is_definite() {
}
let rows = &[
Row {
language: get_language("python"),
pattern: r#"(expression_statement (string))"#,
results_by_step_index: &[
(0, false),
(1, false), // string
],
},
Row {
language: get_language("javascript"),
pattern: r#"(object "{" "}")"#,

View file

@ -748,10 +748,9 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *impossible_index
for (unsigned i = 0; i < count; i++) {
const TSParseAction *action = &actions[i];
if (action->type == TSParseActionTypeReduce) {
unsigned exists;
array_search_sorted_by(
&subgraphs,
subgraph_index,
0,
.symbol,
action->params.reduce.symbol,
&subgraph_index,
@ -759,13 +758,14 @@ static bool ts_query__analyze_patterns(TSQuery *self, unsigned *impossible_index
);
if (exists) {
SymbolSubgraph *subgraph = &subgraphs.contents[subgraph_index];
SubgraphNode node = {
.state = state,
.production_id = action->params.reduce.production_id,
.child_index = action->params.reduce.child_count,
.done = true,
};
if (subgraph->nodes.size == 0 || array_back(&subgraph->nodes)->state != state) {
array_push(&subgraph->nodes, ((SubgraphNode) {
.state = state,
.production_id = action->params.reduce.production_id,
.child_index = action->params.reduce.child_count,
.done = true,
}));
array_push(&subgraph->nodes, node);
}
}
} else if (