grammar refactoring: build_visitor fixed & visitors tested

This commit is contained in:
ProgramSnail 2023-04-11 13:49:22 +03:00
parent 3c2d496a85
commit e4802896bd
35 changed files with 118128 additions and 91770 deletions

View file

@ -90,7 +90,7 @@ void PrintVisitor::Visit(ImportStatement* node) {
if (!node->symbols.empty()) {
out_ << " (\n";
for (auto& symbol : node->symbols) {
Visitor::Visit(&symbol);
Visit(&symbol);
out_ << '\n';
}
out_ << ')';
@ -183,7 +183,7 @@ void PrintVisitor::Visit(AbstractTypeDefinitionStatement* node) {
break;
}
out_ << "] (";
Visit(node->definition.get());
Visit(node->type.get());
out_ << ")\n";
}
@ -413,7 +413,7 @@ void PrintVisitor::Visit(FunctionCallExpression* node) {
Visitor::Visit(argument);
out_ << ", ";
}
out_ << ")\n";
out_ << ")";
}
void PrintVisitor::Visit(TupleExpression* node) {
@ -444,11 +444,24 @@ void PrintVisitor::Visit(TypeConstructor* node) {
out_ << "[TypeConstructor ";
Visit(node->type.get());
out_ << "]\n(";
bool is_first = true;
for (auto& parameter : node->parameters) {
Visit(&parameter.first);
out_ << " = ";
Visitor::Visit(parameter.second);
out_ << ")\n(";
if (!is_first) {
out_ << ")\n";
is_first = false;
}
out_ << '(';
Visit(&std::get<0>(parameter));
switch (std::get<1>(parameter)) {
case TypeConstructor::Assign:
out_ << " = ";
break;
case TypeConstructor::Move:
out_ << " <- ";
break;
}
Visitor::Visit(std::get<2>(parameter));
}
out_ << ")\n";
}
@ -530,12 +543,12 @@ void PrintVisitor::Visit(AnnotatedName* node) {
void PrintVisitor::Visit(FunctionType* node) {
out_ << "[FunctionType] (";
bool first = true;
bool is_first = true;
for (auto& type : node->types) {
if (!first) {
if (!is_first) {
out_ << " -> ";
}
first = false;
is_first = false;
Visitor::Visit(type);
}
out_ << ')';
@ -601,7 +614,13 @@ void PrintVisitor::Visit(ParametrizedType* node) {
}
void PrintVisitor::Visit(TypeExpression* node) {
out_ << "[TypeExpression] (";
out_ << "[TypeExpression ";
if (node->array_size.has_value()) {
out_ << "[array size: " << node->array_size.value() << ']';
}
out_ << "] (";
for (auto& type_namespace : node->namespaces) {
Visitor::Visit(type_namespace);
out_ << '.';
@ -655,7 +674,7 @@ void PrintVisitor::Visit(ExtendedName* node) {
out_ << "[ExtendedName " << node->name << "] ";
}
void PrintVisitor::Visit(AnyIdentifier* node) { // std::string
void PrintVisitor::Visit(std::string* node) { // std::string
out_ << "[Identifier " << *node << "] ";
}