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
|
|
@ -139,13 +139,6 @@ struct ReferenceExpression;
|
|||
|
||||
struct FunctionCallExpression;
|
||||
|
||||
//
|
||||
struct TypeExpression;
|
||||
using FunctionArgument = std::variant<
|
||||
SubExpressionToken,
|
||||
std::unique_ptr<TypeExpression>>;
|
||||
//
|
||||
|
||||
struct TupleExpression;
|
||||
struct VariantExpression;
|
||||
struct ReturnExpression;
|
||||
|
|
@ -212,6 +205,12 @@ using TypeSubExpression = std::variant<
|
|||
std::unique_ptr<AnyTypeIdentifier>,
|
||||
std::unique_ptr<ParametrizedType>>;
|
||||
|
||||
//
|
||||
|
||||
using FunctionArgument = std::variant<
|
||||
SubExpressionToken,
|
||||
TypeSubExpression>;
|
||||
|
||||
// Comments [IGNORE] -----------------
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
|
|
@ -233,7 +232,7 @@ using Literal = std::variant<
|
|||
//
|
||||
|
||||
using NameSubExpression = std::variant<
|
||||
std::unique_ptr<NameIdentifier>,
|
||||
std::unique_ptr<ExtendedName>,
|
||||
std::unique_ptr<Literal>,
|
||||
std::unique_ptr<SuperExpression>>;
|
||||
|
||||
|
|
@ -295,6 +294,7 @@ struct AliasDefinitionStatement {
|
|||
|
||||
struct VariableDefinitionStatement {
|
||||
enum { Var, Const } modifier;
|
||||
enum { Move, Assign } assignment_modifier;
|
||||
AnyName name;
|
||||
SuperExpression value;
|
||||
};
|
||||
|
|
@ -306,6 +306,7 @@ struct FunctionDeclaration {
|
|||
};
|
||||
|
||||
struct FunctionDefinitionStatement {
|
||||
bool is_inline;
|
||||
std::unique_ptr<FunctionDefinition> definition;
|
||||
SuperExpression value;
|
||||
};
|
||||
|
|
@ -437,8 +438,9 @@ struct ReturnExpression {
|
|||
};
|
||||
|
||||
struct TypeConstructor {
|
||||
enum AssignmentModifier { Move, Assign };
|
||||
std::unique_ptr<ParametrizedType> type;
|
||||
std::vector<std::pair<ExtendedName, SubExpression>> parameters;
|
||||
std::vector<std::tuple<ExtendedName, AssignmentModifier, SubExpression>> parameters;
|
||||
};
|
||||
|
||||
struct LambdaFunction {
|
||||
|
|
@ -502,7 +504,7 @@ struct ParametrizedType {
|
|||
struct TypeExpression {
|
||||
std::vector<TypeSubExpression> namespaces;
|
||||
AnyTypeIdentifier type;
|
||||
std::optional<size_t> ArraySize; // if array; 0 - dynamic size
|
||||
std::optional<size_t> array_size; // if array; 0 - dynamic size
|
||||
};
|
||||
|
||||
struct ExtendedScopedAnyType {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ private:
|
|||
|
||||
void Visit(ExtendedName* node) override;
|
||||
|
||||
void Visit(AnyIdentifier* node) override; // std::string
|
||||
void Visit(std::string* node) override; // std::string
|
||||
|
||||
void Visit(FloatNumberLiteral* node) override;
|
||||
void Visit(NumberLiteral* node) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue