const -> let

This commit is contained in:
ProgramSnail 2023-07-03 19:05:50 +03:00
parent 3ae6ed079d
commit 189306df26
33 changed files with 406 additions and 285 deletions

View file

@ -315,6 +315,8 @@ void BuildVisitor::Visit(PartitionStatement* node) {
node->modifier = utils::PartitionModifier::Exec;
} else if (partition_modifier == "test") {
node->modifier = utils::PartitionModifier::Test;
} else if (partition_modifier == "example") {
node->modifier = utils::PartitionModifier::Example;
} else {
// error
}
@ -826,6 +828,15 @@ void BuildVisitor::Visit(Expression& node) {
} else if (current_node_type == parser::tokens::SubExpression) {
node = std::make_unique<SubExpression>();
Visit(*std::get<std::unique_ptr<SubExpression>>(node));
} else if (current_node_type == parser::tokens::AndExpression) {
node = std::make_unique<AndExpression>();
Visit(std::get<std::unique_ptr<AndExpression>>(node).get());
} else if (current_node_type == parser::tokens::OrExpression) {
node = std::make_unique<OrExpression>();
Visit(std::get<std::unique_ptr<OrExpression>>(node).get());
} else if (current_node_type == parser::tokens::ArrayExpression) {
node = std::make_unique<ArrayExpression>();
Visit(std::get<std::unique_ptr<ArrayExpression>>(node).get());
} else {
// error
}
@ -849,9 +860,6 @@ void BuildVisitor::Visit(SuperExpression& node) {
} else if (current_node_type == parser::tokens::VariantExpression) {
node = std::make_unique<VariantExpression>();
Visit(std::get<std::unique_ptr<VariantExpression>>(node).get());
} else if (current_node_type == parser::tokens::ArrayExpression) {
node = std::make_unique<ArrayExpression>();
Visit(std::get<std::unique_ptr<ArrayExpression>>(node).get());
} else if (current_node_type == parser::tokens::Expression) {
node = std::make_unique<Expression>();
Visit(*std::get<std::unique_ptr<Expression>>(node));
@ -884,7 +892,7 @@ void BuildVisitor::VisitBinaryOperatorExpression(FunctionCallExpression* node) {
node->arguments.resize(2);
current_node_ = parse_node.ChildByFieldName("left_expression");
Visit(node->arguments[0]);
Visit(node->arguments[0].second);
node->name = parse_node.ChildByFieldName("operator_name").GetValue();
@ -896,15 +904,16 @@ void BuildVisitor::VisitBinaryOperatorExpression(FunctionCallExpression* node) {
}
current_node_ = parse_node.ChildByFieldName("right_expression");
Visit(node->arguments[1]);
Visit(node->arguments[1].second);
// ??
for (size_t i = 0; i < node->arguments.size(); ++i) {
if (std::holds_alternative<std::unique_ptr<FunctionCallExpression>>(node->arguments[i])) {
FunctionCallExpression* argument_node = std::get<std::unique_ptr<FunctionCallExpression>>(node->arguments[i]).get();
if (std::holds_alternative<std::unique_ptr<FunctionCallExpression>>(node->arguments[i].second)) {
FunctionCallExpression* argument_node = std::get<std::unique_ptr<FunctionCallExpression>>(node->arguments[i].second).get();
if (argument_node->is_binary_operator_expression
&& argument_node->precedence.has_value()
&& argument_node->precedence.value() == node->precedence.value()) {
&& argument_node->precedence.value() == node->precedence.value()
&& node->name != argument_node->name) { // same operators can be chained
error_handling::HandleParsingError("Operators can't be chained (left argument)", node->base.start_position, node->base.end_position);
}
}
@ -986,6 +995,7 @@ void BuildVisitor::Visit(FunctionCallExpression* node) {
if (child_count > excluded_child_count) {
bool parameters_ended = false;
bool last_child_is_annotation = false;
for (size_t i = 0; i + excluded_child_count < child_count; ++i) {
current_node_ = parse_node.NthNamedChild(i + excluded_child_count);
@ -998,10 +1008,26 @@ void BuildVisitor::Visit(FunctionCallExpression* node) {
node->parameters.push_back(std::make_unique<TypeExpression>());
Visit(node->parameters.back().get());
} else {
node->arguments.push_back(std::make_unique<SubExpressionToken>());
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->arguments.back()));
if (!current_node_.PreviousSibling().IsNull() && current_node_.PreviousSibling().GetValue() == "::") { // annotation
node->arguments.push_back({current_node_.GetValue(), SubExpression()});
last_child_is_annotation = true;
} else if (last_child_is_annotation) { // argument after annotation
node->arguments.back().second = std::make_unique<SubExpressionToken>();
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->arguments.back().second));
last_child_is_annotation = false;
} else { // argument without annotation
node->arguments.push_back({std::nullopt, std::make_unique<SubExpressionToken>()});
Visit(*std::get<std::unique_ptr<SubExpressionToken>>(node->arguments.back().second));
last_child_is_annotation = false;
}
}
}
if (last_child_is_annotation) {
error_handling::HandleInternalError("Last child is annotation",
"BuildVisitor.FunctionCallExpression",
&node->base);
}
}
current_node_ = parse_node;
@ -1137,6 +1163,40 @@ void BuildVisitor::Visit(LambdaFunction* node) {
current_node_ = parse_node;
}
void BuildVisitor::Visit(AndExpression* node) {
SetPosition(node->base, current_node_);
auto parse_node = current_node_;
size_t expressions_count = parse_node.NamedChildCount();
node->expressions.resize(expressions_count);
for (size_t i = 0; i < expressions_count; ++i) {
current_node_ = parse_node.NthNamedChild(i);
Visit(node->expressions[i]);
}
current_node_ = parse_node;
}
void BuildVisitor::Visit(OrExpression* node) {
SetPosition(node->base, current_node_);
auto parse_node = current_node_;
size_t expressions_count = parse_node.NamedChildCount();
node->expressions.resize(expressions_count);
for (size_t i = 0; i < expressions_count; ++i) {
current_node_ = parse_node.NthNamedChild(i);
Visit(node->expressions[i]);
}
current_node_ = parse_node;
}
void BuildVisitor::Visit(ArrayExpression* node) {
SetPosition(node->base, current_node_);
@ -1296,12 +1356,31 @@ void BuildVisitor::Visit(FunctionType* node) {
size_t types_count = parse_node.NamedChildCount();
node->types.resize(types_count);
node->types.reserve(types_count);
bool last_child_is_annotation = false;
for (size_t i = 0; i < types_count; ++i) {
current_node_ = parse_node.NthNamedChild(i);
node->types[i] = std::make_unique<ExtendedScopedAnyType>();
Visit(node->types[i].get());
if (!current_node_.PreviousSibling().IsNull() && current_node_.PreviousSibling().GetValue() == "::") { // annotation
node->types.push_back({current_node_.GetValue(), nullptr});
last_child_is_annotation = true;
} else if (last_child_is_annotation) { // argument after annotation
node->types.back().second = std::make_unique<ExtendedScopedAnyType>();
Visit(node->types.back().second.get());
last_child_is_annotation = false;
} else { // argument without annotation
node->types.push_back({std::nullopt, std::make_unique<ExtendedScopedAnyType>()});
Visit(node->types.back().second.get());
last_child_is_annotation = false;
}
}
if (last_child_is_annotation) {
error_handling::HandleInternalError("Last child is annotation",
"BuildVisitor.FunctionType",
&node->base);
}
current_node_ = parse_node;