mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 06:58:46 +00:00
doc builders (no annotation check support)
This commit is contained in:
parent
696a9c3a1a
commit
6682e0beb1
5 changed files with 76 additions and 20 deletions
14
include/doc_builders.hpp
Normal file
14
include/doc_builders.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "doc_nodes.hpp"
|
||||||
|
#include "tree_sitter_wrapper.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace builders {
|
||||||
|
|
||||||
|
nodes::SymbolDocs buildSymbolDocs(
|
||||||
|
parser::ParseTree::Node description_parser_node,
|
||||||
|
const std::vector<parser::ParseTree::Node> &annotation_parser_nodes);
|
||||||
|
|
||||||
|
} // namespace builders
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "basic_nodes.hpp"
|
#include "basic_nodes.hpp"
|
||||||
#include "docs.hpp"
|
#include "doc_nodes.hpp"
|
||||||
#include "expression_nodes.hpp"
|
#include "expression_nodes.hpp"
|
||||||
#include "type_nodes.hpp"
|
#include "type_nodes.hpp"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,63 +16,69 @@ public:
|
||||||
Node(const TSNode &node, const std::string *source)
|
Node(const TSNode &node, const std::string *source)
|
||||||
: node_(node), source_(source) {}
|
: node_(node), source_(source) {}
|
||||||
|
|
||||||
std::string get_type() { return ts_node_type(node_); }
|
std::string get_type() const { return ts_node_type(node_); }
|
||||||
|
|
||||||
std::pair<size_t, size_t> get_start_point() {
|
std::pair<size_t, size_t> get_start_point() const {
|
||||||
TSPoint point = ts_node_start_point(node_);
|
TSPoint point = ts_node_start_point(node_);
|
||||||
return {point.row, point.column};
|
return {point.row, point.column};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<size_t, size_t> get_end_point() {
|
std::pair<size_t, size_t> get_end_point() const {
|
||||||
TSPoint point = ts_node_end_point(node_);
|
TSPoint point = ts_node_end_point(node_);
|
||||||
return {point.row, point.column};
|
return {point.row, point.column};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_as_sexpression() { return ts_node_string(node_); }
|
std::string get_as_sexpression() const { return ts_node_string(node_); }
|
||||||
|
|
||||||
std::string get_value() { // from source
|
std::string get_value() const { // from source
|
||||||
size_t start = ts_node_start_byte(node_);
|
size_t start = ts_node_start_byte(node_);
|
||||||
size_t end = ts_node_end_byte(node_);
|
size_t end = ts_node_end_byte(node_);
|
||||||
return source_->substr(start, end - start);
|
return source_->substr(start, end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_null() { return ts_node_is_null(node_); }
|
bool is_null() const { return ts_node_is_null(node_); }
|
||||||
|
|
||||||
bool is_named() { return ts_node_is_named(node_); }
|
bool is_named() const { return ts_node_is_named(node_); }
|
||||||
|
|
||||||
bool is_missing() { return ts_node_is_missing(node_); }
|
bool is_missing() const { return ts_node_is_missing(node_); }
|
||||||
|
|
||||||
bool is_extra() { // comments, etc.
|
bool is_extra() const { // comments, etc.
|
||||||
return ts_node_is_extra(node_);
|
return ts_node_is_extra(node_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_error() { return ts_node_has_error(node_); }
|
bool has_error() const { return ts_node_has_error(node_); }
|
||||||
|
|
||||||
Node nth_child(size_t n) { return Node(ts_node_child(node_, n), source_); }
|
Node nth_child(size_t n) const {
|
||||||
|
return Node(ts_node_child(node_, n), source_);
|
||||||
|
}
|
||||||
|
|
||||||
size_t child_count() { return ts_node_child_count(node_); }
|
size_t child_count() const { return ts_node_child_count(node_); }
|
||||||
|
|
||||||
Node nth_named_child(size_t n) {
|
Node nth_named_child(size_t n) const {
|
||||||
return Node(ts_node_named_child(node_, n), source_);
|
return Node(ts_node_named_child(node_, n), source_);
|
||||||
}
|
}
|
||||||
size_t named_child_count() { return ts_node_named_child_count(node_); }
|
size_t named_child_count() const {
|
||||||
|
return ts_node_named_child_count(node_);
|
||||||
|
}
|
||||||
|
|
||||||
Node child_by_field_name(const std::string &name) {
|
Node child_by_field_name(const std::string &name) const {
|
||||||
return Node(ts_node_child_by_field_name(node_, name.c_str(), name.size()),
|
return Node(ts_node_child_by_field_name(node_, name.c_str(), name.size()),
|
||||||
source_);
|
source_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node previous_sibling() {
|
Node previous_sibling() const {
|
||||||
return Node(ts_node_prev_sibling(node_), source_);
|
return Node(ts_node_prev_sibling(node_), source_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node previous_named_sibling() {
|
Node previous_named_sibling() const {
|
||||||
return Node(ts_node_prev_named_sibling(node_), source_);
|
return Node(ts_node_prev_named_sibling(node_), source_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node next_sibling() { return Node(ts_node_next_sibling(node_), source_); }
|
Node next_sibling() const {
|
||||||
|
return Node(ts_node_next_sibling(node_), source_);
|
||||||
|
}
|
||||||
|
|
||||||
Node next_named_dibling() {
|
Node next_named_sibling() const {
|
||||||
return Node(ts_node_next_named_sibling(node_), source_);
|
return Node(ts_node_next_named_sibling(node_), source_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
36
src/doc_builders.cpp
Normal file
36
src/doc_builders.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include "../include/doc_builders.hpp"
|
||||||
|
#include "basic_builders.hpp"
|
||||||
|
|
||||||
|
namespace builders {
|
||||||
|
|
||||||
|
// TODO: check, that all annotations are exist in function definition
|
||||||
|
nodes::SymbolDocs buildSymbolDocs(
|
||||||
|
parser::ParseTree::Node description_parser_node,
|
||||||
|
const std::vector<parser::ParseTree::Node> &annotation_parser_nodes) {
|
||||||
|
std::string description = description_parser_node.get_value();
|
||||||
|
|
||||||
|
// remove newline delimeters (": " at each new line
|
||||||
|
size_t j = 0;
|
||||||
|
for (size_t i = 0; i < description.size(); ++i, ++j) {
|
||||||
|
if (j != i) {
|
||||||
|
description[j] = description[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (description[i] == '\n') {
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
description.resize(j);
|
||||||
|
|
||||||
|
nodes::SymbolDocs docs(description);
|
||||||
|
|
||||||
|
for (auto &annotation_parser_node : annotation_parser_nodes) {
|
||||||
|
docs.add_annotation_info(
|
||||||
|
buildAnnotation(annotation_parser_node.nth_child(0)),
|
||||||
|
annotation_parser_node.nth_child(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace builders
|
||||||
Loading…
Add table
Add a link
Reference in a new issue