#pragma once #include // for clangd #include "tree_sitter/api.h" namespace parser { class ParseTree { public: class Node { public: std::string GetType(); std::pair GetStartPoint(); std::pair GetEndPoint(); std::string GetAsSExpression(); std::string GetValue(); // from source bool IsNull(); bool IsNamed(); bool IsMissing(); bool IsExtra(); // comments, etc. bool HasError(); Node NthChild(size_t n); size_t ChildCount(); Node NthNamedChild(size_t n); size_t NamedChildCount(); Node ChildByFieldName(const std::string& name); // ?? use field id instaed of name ?? // ?? node equality check needed ?? private: TSNode node_; }; class Cursor { // ?? needed ?? public: Cursor(const Node& node); void ResetTo(const Node& node); Node GetCurrentNode(); std::string GetCurrentNodeName(); bool GoToParent(); bool GoToNextSibling(); bool GoToFirstChild(); private: TSTreeCursor cursor_; }; ParseTree(const std::string& input); Node GetRoot() const; private: TSTree* tree_; std::string source; // for token value extraction }; } // namespace parser