mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-05 22:48:42 +00:00
apart of build_visitor done
This commit is contained in:
parent
36eb3390aa
commit
622b86f6c6
8 changed files with 987 additions and 312 deletions
|
|
@ -16,7 +16,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void Visit(Node* node) override;
|
||||
// // void Visit(Node* node) override;
|
||||
|
||||
// Sources -----------------
|
||||
|
||||
|
|
@ -56,6 +56,7 @@ private:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void Visit(MatchCase* node) override;
|
||||
void Visit(Match* node) override;
|
||||
void Visit(Condition* node) override;
|
||||
void Visit(DoWhileLoop* node) override;
|
||||
|
|
@ -130,7 +131,7 @@ private:
|
|||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
||||
void Visit(AnyIdentifier* node) override; // std::string
|
||||
// // void Visit(AnyIdentifier* node) override; // std::string
|
||||
|
||||
void Visit(FloatNumberLiteral* node) override;
|
||||
void Visit(NumberLiteral* node) override;
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ struct VariableDefinition : public Node {
|
|||
};
|
||||
|
||||
struct FunctionDeclaration : public Node {
|
||||
NameIdentifier name;
|
||||
NameOrOperatorIdentifier name;
|
||||
std::vector<std::unique_ptr<DefinitionParameter>> parameters;
|
||||
std::vector<FunctionDeclarationType> argument_types;
|
||||
};
|
||||
|
|
@ -324,17 +324,18 @@ struct FunctionDefinition : public Node {
|
|||
};
|
||||
|
||||
struct AliasTypeDefinition : public Node {
|
||||
std::unique_ptr<DefinedType> name;
|
||||
std::unique_ptr<DefinedType> type;
|
||||
std::unique_ptr<ParametrizedType> value;
|
||||
};
|
||||
|
||||
struct TypeDefinition : public Node {
|
||||
std::unique_ptr<DefinedType> name;
|
||||
bool is_class; // class vs struct
|
||||
std::unique_ptr<DefinedType> type;
|
||||
AnyType value;
|
||||
};
|
||||
|
||||
struct TypeclassDefinition : public Node {
|
||||
std::unique_ptr<DefinedTypeclass> name;
|
||||
std::unique_ptr<DefinedTypeclass> typeclass;
|
||||
std::vector<std::unique_ptr<FunctionDeclaration>> requirements;
|
||||
};
|
||||
|
||||
|
|
@ -497,7 +498,7 @@ struct VariantName : public Node {
|
|||
|
||||
struct AnnotatedName : public Node {
|
||||
NameIdentifier name;
|
||||
std::unique_ptr<ParametrizedType> type; // optional
|
||||
std::optional<std::unique_ptr<ParametrizedType>> type; // optional
|
||||
};
|
||||
|
||||
// TODO ?? mark all optional fields ??
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ const std::string Sources = "sources";
|
|||
// Namespaces, partittions -----------------
|
||||
|
||||
const std::string Partition = "partition";
|
||||
const std::string Namespace = "namespace";
|
||||
|
||||
// Definitions -----------------
|
||||
|
||||
|
|
@ -57,11 +58,11 @@ const std::string FlowControl = "flow_control";
|
|||
const std::string Block = "block";
|
||||
const std::string ScopedStatement = "scoped_statement";
|
||||
|
||||
const std::string LoopExpressionToken = "loop_expression_token";
|
||||
const std::string LoopControlExpression = "loop_control_expression";
|
||||
|
||||
const std::string SubExpreessionToken = "subexpression_token";
|
||||
const std::string SubExpressionToken = "subexpression_token";
|
||||
const std::string SubExpression = "subexpression";
|
||||
const std::string PrefixedExprerssion = "prefixed_expression";
|
||||
const std::string PrefixedExpression = "prefixed_expression";
|
||||
const std::string Expression = "expression";
|
||||
const std::string SuperExpression = "super_expression";
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ const std::string UnaryOperatorExpression = "unary_operator_expression";
|
|||
|
||||
const std::string FunctionCallExpression = "function_call_expression";
|
||||
const std::string TupleExpression = "tuple_expression";
|
||||
const std::string VarinatExpression = "variant_expression";
|
||||
const std::string VariantExpression = "variant_expression";
|
||||
const std::string ReturnExpression = "return_expression";
|
||||
|
||||
const std::string FunctionArgument = "function_argument";
|
||||
|
|
@ -112,7 +113,7 @@ const std::string TypeParameter = "type_parameter";
|
|||
// Typeclass
|
||||
|
||||
const std::string AnnotatedTypeclass = "annotated_typeclass";
|
||||
const std::string ParamatrizedTypeclass = "parametrized_typeclass";
|
||||
const std::string ParametrizedTypeclass = "parametrized_typeclass";
|
||||
const std::string TypeclassExpression = "typeclass_expression";
|
||||
|
||||
// Identifiers, constants, etc. -----------------
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ private:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void Visit(MatchCase* node) override;
|
||||
void Visit(Match* node) override;
|
||||
void Visit(Condition* node) override;
|
||||
void Visit(DoWhileLoop* node) override;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public:
|
|||
Visit(source_file);
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
virtual void Visit(Node* node) {}
|
||||
|
||||
// Sources -----------------
|
||||
|
|
@ -54,6 +54,7 @@ private:
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
virtual void Visit(MatchCase* node) {}
|
||||
virtual void Visit(Match* node) {}
|
||||
virtual void Visit(Condition* node) {}
|
||||
virtual void Visit(DoWhileLoop* node) {}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
namespace interpreter {
|
||||
|
||||
void Node::Accept(Visitor* visitor) {
|
||||
/*void Node::Accept(Visitor* visitor) {
|
||||
visitor->Visit(this);
|
||||
}
|
||||
}*/
|
||||
|
||||
} // namespace interpreter
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ void PrintVisitor::Visit(FunctionDefinition* node) {
|
|||
|
||||
void PrintVisitor::Visit(AliasTypeDefinition* node) {
|
||||
out_ << "<AliasType> ";
|
||||
Visit(node->name.get());
|
||||
Visit(node->type.get());
|
||||
out_ << " = ";
|
||||
Visit(node->value.get());
|
||||
out_ << "</AliasType>\n";
|
||||
|
|
@ -148,7 +148,7 @@ void PrintVisitor::Visit(AliasTypeDefinition* node) {
|
|||
|
||||
void PrintVisitor::Visit(TypeDefinition* node) {
|
||||
out_ << "<Type> ";
|
||||
Visit(node->name.get());
|
||||
Visit(node->type.get());
|
||||
out_ << " = ";
|
||||
Visitor::Visit(node->value);
|
||||
out_ << "</Type>\n";
|
||||
|
|
@ -156,7 +156,7 @@ void PrintVisitor::Visit(TypeDefinition* node) {
|
|||
|
||||
void PrintVisitor::Visit(TypeclassDefinition* node) {
|
||||
out_ << "<Typeclass> ";
|
||||
Visit(node->name.get());
|
||||
Visit(node->typeclass.get());
|
||||
if (node->requirements.size() > 0) {
|
||||
out_ << " : \n";
|
||||
}
|
||||
|
|
@ -259,22 +259,26 @@ void PrintVisitor::Visit(DefinitionArgument* node) {
|
|||
|
||||
// Flow control -----------------
|
||||
|
||||
void PrintVisitor::Visit(MatchCase* node) {
|
||||
out_ << "<MatchCase> | ";
|
||||
Visitor::Visit(node->value);
|
||||
if (node->condition.has_value()) {
|
||||
out_ << " ? ";
|
||||
Visitor::Visit(node->condition.value());
|
||||
}
|
||||
if (node->statement.has_value()) {
|
||||
out_ << " -> ";
|
||||
Visitor::Visit(node->statement.value());
|
||||
}
|
||||
out_ << "</MatchCase>\n";
|
||||
}
|
||||
|
||||
void PrintVisitor::Visit(Match* node) {
|
||||
out_ << "<Match> ";
|
||||
Visitor::Visit(node->value);
|
||||
out_ << " with\n";
|
||||
for (auto& match_case : node->matches) {
|
||||
out_ << "| ";
|
||||
Visitor::Visit(match_case.value);
|
||||
if (match_case.condition.has_value()) {
|
||||
out_ << " ? ";
|
||||
Visitor::Visit(match_case.condition.value());
|
||||
}
|
||||
if (match_case.statement.has_value()) {
|
||||
out_ << " -> ";
|
||||
Visitor::Visit(match_case.statement.value());
|
||||
}
|
||||
out_ << '\n';
|
||||
Visit(&match_case);
|
||||
}
|
||||
out_ << "</Match>\n";
|
||||
}
|
||||
|
|
@ -488,8 +492,10 @@ void PrintVisitor::Visit(VariantName* node) {
|
|||
void PrintVisitor::Visit(AnnotatedName* node) {
|
||||
out_ << "<AnnotatedName> ";
|
||||
Visit(&node->name);
|
||||
out_ << ' ';
|
||||
Visit(node->type.get());
|
||||
if (node->type.has_value()) {
|
||||
out_ << " : ";
|
||||
Visit(node->type.value().get());
|
||||
}
|
||||
out_ << " </AnnotatedName>";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue