mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
interpreter_tree first iteration
This commit is contained in:
parent
7f4cd5ee9a
commit
1ba132bb06
15 changed files with 1829 additions and 1 deletions
64
include/parse_tree.hpp
Normal file
64
include/parse_tree.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// for clangd
|
||||
#include "tree_sitter/api.h"
|
||||
|
||||
|
||||
namespace parser {
|
||||
|
||||
class ParseTree {
|
||||
public:
|
||||
class Node {
|
||||
public:
|
||||
Node() = delete;
|
||||
|
||||
std::string GetType();
|
||||
std::pair<size_t, size_t> GetStartPoint();
|
||||
std::pair<size_t, size_t> GetEndPoint();
|
||||
std::string GetAsSExpression();
|
||||
|
||||
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 ChildByName(const std::string& name);
|
||||
|
||||
// ?? use field id instaed of name ??
|
||||
// ?? node equality check needed ??
|
||||
private:
|
||||
TSNode node_;
|
||||
};
|
||||
class Cursor {
|
||||
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();
|
||||
private:
|
||||
TSTree* tree_;
|
||||
};
|
||||
|
||||
} // namespace parser
|
||||
Loading…
Add table
Add a link
Reference in a new issue