Skip to content
Open
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
17 changes: 15 additions & 2 deletions include/cpp-tree-sitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <iterator>
#include <memory>
#include <string_view>

#include <cstdlib>
#include <tree_sitter/api.h>

// Including the API directly already pollutes the namespace, but the
Expand Down Expand Up @@ -179,7 +179,20 @@ struct Node {

[[nodiscard]] std::string_view
getFieldNameForChild(uint32_t child_position) const {
return ts_node_field_name_for_child(impl, child_position);
const auto *name = ts_node_field_name_for_child(impl, child_position);
if (!name) {
return std::string_view{};
}
return std::string_view{name};
}

[[nodiscard]] std::string_view
getFieldNameForNamedChild(uint32_t child_position) const {
const auto *name = ts_node_field_name_for_named_child(impl, child_position);
if (!name) {
return std::string_view{};
}
return std::string_view{name};
}

[[nodiscard]] Node
Expand Down