mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-25 13:07:13 +00:00
grammar refactoring: build_visitor fixed & visitors tested
This commit is contained in:
parent
3c2d496a85
commit
e4802896bd
35 changed files with 118128 additions and 91770 deletions
|
|
@ -45,7 +45,7 @@ public:
|
|||
std::string GetValue() { // from source
|
||||
size_t start = ts_node_start_byte(node_);
|
||||
size_t end = ts_node_end_byte(node_);
|
||||
return source_->substr(start, end - start); // TODO check
|
||||
return source_->substr(start, end - start);
|
||||
}
|
||||
|
||||
bool IsNull() {
|
||||
|
|
@ -86,28 +86,18 @@ public:
|
|||
return Node(ts_node_child_by_field_name(node_, name.c_str(), name.size()), source_);
|
||||
}
|
||||
|
||||
// ?? use field id instaed of name ??
|
||||
// ?? node equality check needed ??
|
||||
Node NextSibling() {
|
||||
return Node(ts_node_next_sibling(node_), source_);
|
||||
}
|
||||
|
||||
Node NextNamedSibling() {
|
||||
return Node(ts_node_next_named_sibling(node_), source_);
|
||||
}
|
||||
private:
|
||||
bool uninitialized_;
|
||||
TSNode node_;
|
||||
const std::string* source_;
|
||||
};
|
||||
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& source) : source_(source) {
|
||||
TSParser* parser = ts_parser_new();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue