Works as intended except for SEGFAULT in free, need to check vec impl
This commit is contained in:
parent
9f6b90d596
commit
efec224b6a
7 changed files with 1427 additions and 10 deletions
|
|
@ -711,6 +711,20 @@ recur:
|
|||
return ts_node__null();
|
||||
}
|
||||
|
||||
static inline TSFieldId ts_node__field_id_from_language(TSNode self, uint32_t structural_child_index)
|
||||
{
|
||||
const TSFieldMapEntry *field_map, *field_map_end;
|
||||
ts_language_field_map(self.tree->language, ts_node__subtree(self).ptr->inner.non_terminal.production_id, &field_map, &field_map_end);
|
||||
for (; field_map != field_map_end; field_map++)
|
||||
{
|
||||
if (!field_map->inherited && field_map->child_index == structural_child_index)
|
||||
{
|
||||
return field_map->field_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline const char *ts_node__field_name_from_language(TSNode self, uint32_t structural_child_index)
|
||||
{
|
||||
const TSFieldMapEntry *field_map, *field_map_end;
|
||||
|
|
@ -725,6 +739,59 @@ static inline const char *ts_node__field_name_from_language(TSNode self, uint32_
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TSFieldId ts_node_field_id_for_child(TSNode self, uint32_t child_index)
|
||||
{
|
||||
TSNode result = self;
|
||||
bool did_descend = true;
|
||||
TSFieldId inherited_field_name = 0;
|
||||
|
||||
while (did_descend)
|
||||
{
|
||||
did_descend = false;
|
||||
|
||||
TSNode child;
|
||||
uint32_t index = 0;
|
||||
NodeChildIterator iterator = ts_node_iterate_children(&result);
|
||||
while (ts_node_child_iterator_next(&iterator, &child))
|
||||
{
|
||||
if (ts_node__is_relevant(child, true))
|
||||
{
|
||||
if (index == child_index)
|
||||
{
|
||||
if (ts_node_is_extra(child))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
TSFieldId field_name = ts_node__field_id_from_language(result, iterator.structural_child_index - 1);
|
||||
if (field_name)
|
||||
return field_name;
|
||||
return inherited_field_name;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t grandchild_index = child_index - index;
|
||||
uint32_t grandchild_count = ts_node__relevant_child_count(child, true);
|
||||
if (grandchild_index < grandchild_count)
|
||||
{
|
||||
TSFieldId field_name = ts_node__field_id_from_language(result, iterator.structural_child_index - 1);
|
||||
if (field_name)
|
||||
inherited_field_name = field_name;
|
||||
|
||||
did_descend = true;
|
||||
result = child;
|
||||
child_index = grandchild_index;
|
||||
break;
|
||||
}
|
||||
index += grandchild_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *ts_node_field_name_for_child(TSNode self, uint32_t child_index)
|
||||
{
|
||||
TSNode result = self;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue