mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 16:58:45 +00:00
changes for new grammar, fixes
This commit is contained in:
parent
3106a64949
commit
f912cdac41
10 changed files with 59 additions and 5 deletions
|
|
@ -167,6 +167,14 @@ void BuildVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
// error
|
||||
}
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 2) { // name, value [, in_expression]
|
||||
current_node_ = parse_node.ChildByFieldName("in_expression");
|
||||
node->in_expression.emplace();
|
||||
Visit(node->in_expression.value());
|
||||
}
|
||||
|
||||
current_node_ = parse_node;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,11 +47,22 @@ void ExecuteVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
}
|
||||
|
||||
void ExecuteVisitor::Visit(VariableDefinitionStatement* node) {
|
||||
// TODO: optional variable definitions
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
context_manager_.EnterContext();
|
||||
}
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
|
||||
is_const_definition_ = node->modifier;
|
||||
Visitor::Visit(node->name); // current_type_ passed from value
|
||||
is_const_definition_ = std::nullopt;
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
Visitor::Visit(node->in_expression.value());
|
||||
context_manager_.ExitContext();
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteVisitor::Visit(FunctionDeclaration* node) {
|
||||
|
|
|
|||
|
|
@ -93,6 +93,12 @@ void PrintVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
Visitor::Visit(node->name);
|
||||
out_ << "] = (";
|
||||
Visitor::Visit(node->value);
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
out_ << ") in (";
|
||||
Visitor::Visit(node->in_expression.value());
|
||||
}
|
||||
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,11 @@ void TypeCheckVisitor::Visit(AliasDefinitionStatement* node) {
|
|||
|
||||
// TODO: move, etc.
|
||||
void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
||||
is_in_statement_ = true;
|
||||
// TODO: optional variable definitions
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
context_manager_.EnterContext();
|
||||
}
|
||||
|
||||
Visitor::Visit(node->value);
|
||||
// current_type from value automatically passed to name definitions
|
||||
|
|
@ -110,8 +114,12 @@ void TypeCheckVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
Visitor::Visit(node->name);
|
||||
is_const_definition_ = std::nullopt;
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
Visitor::Visit(node->in_expression.value());
|
||||
context_manager_.ExitContext();
|
||||
}
|
||||
|
||||
current_type_ = internal_to_abstract_type_.at(info::type::InternalType::Unit);
|
||||
is_in_statement_ = false;
|
||||
|
||||
node->base.type_ = current_type_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,6 +123,12 @@ void TypedPrintVisitor::Visit(VariableDefinitionStatement* node) {
|
|||
Visitor::Visit(node->name);
|
||||
out_ << "] = (";
|
||||
Visitor::Visit(node->value);
|
||||
|
||||
if (node->in_expression.has_value()) {
|
||||
out_ << ") in (";
|
||||
Visitor::Visit(node->in_expression.value());
|
||||
}
|
||||
|
||||
out_ << ")\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -328,6 +328,9 @@ void Visitor::Visit(AliasDefinitionStatement* node) {
|
|||
void Visitor::Visit(VariableDefinitionStatement* node) {
|
||||
Visit(node->name);
|
||||
Visit(node->value);
|
||||
if (node->in_expression.has_value()) {
|
||||
Visit(node->in_expression.value());
|
||||
}
|
||||
}
|
||||
|
||||
void Visitor::Visit(FunctionDeclaration* node) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue