diff --git a/src/language/ASTSymbolInitializationChecker.cpp b/src/language/ASTSymbolInitializationChecker.cpp index f42d5a0a88e8ef1ef938bb8d402db4fdf0e2db62..038e9da4a295c02f45fd0195532a14b16404e865 100644 --- a/src/language/ASTSymbolInitializationChecker.cpp +++ b/src/language/ASTSymbolInitializationChecker.cpp @@ -8,7 +8,7 @@ void ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) { if (node.is_type<language::declaration>()) { - auto set_is_initialized = [&](ASTNode& name_node) { + auto check_if_initialized = [&](ASTNode& name_node) { const std::string& symbol = name_node.string(); auto [i_symbol, found] = node.m_symbol_table->find(symbol, name_node.begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); @@ -19,11 +19,11 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) }; if (node.children[1]->is_type<language::name>()) { - set_is_initialized(*node.children[1]); + check_if_initialized(*node.children[1]); } else if (node.children[1]->is_type<language::name_list>()) { ASTNode& name_list_node = *node.children[1]; for (auto& child_node : name_list_node.children) { - set_is_initialized(*child_node); + check_if_initialized(*child_node); } } } else if (node.is_type<language::let_declaration>()) { @@ -44,11 +44,22 @@ ASTSymbolInitializationChecker::_checkSymbolInitialization(ASTNode& node) } else if (node.is_type<language::eq_op>()) { // first checks for right hand side this->_checkSymbolInitialization(*node.children[1]); - // then marks left hand side as initialized - const std::string& symbol = node.children[0]->string(); - auto [i_symbol, found] = node.m_symbol_table->find(symbol, node.children[0]->begin()); - Assert(found, "unexpected error, should have been detected through declaration checking"); - i_symbol->attributes().setIsInitialized(); + + auto set_is_initialized = [&](ASTNode& name_node) { + const std::string& symbol = name_node.string(); + auto [i_symbol, found] = node.m_symbol_table->find(symbol, name_node.begin()); + Assert(found, "unexpected error, should have been detected through declaration checking"); + i_symbol->attributes().setIsInitialized(); + }; + + if (node.children[0]->is_type<language::name>()) { + set_is_initialized(*node.children[0]); + } else if (node.children[0]->is_type<language::name_list>()) { + ASTNode& name_list_node = *node.children[0]; + for (auto& child_node : name_list_node.children) { + set_is_initialized(*child_node); + } + } } else if (node.is_type<language::name>()) { auto [i_symbol, found] = node.m_symbol_table->find(node.string(), node.begin()); Assert(found, "unexpected error, should have been detected through declaration checking"); diff --git a/src/language/PEGGrammar.hpp b/src/language/PEGGrammar.hpp index b44f873c0223703dfd42ee424ca799bbfb0aa130..e3249dd6af58a210432d0e5ed44a330183a2f4f6 100644 --- a/src/language/PEGGrammar.hpp +++ b/src/language/PEGGrammar.hpp @@ -211,9 +211,10 @@ struct expression_list : seq< open_parent, expression, plus< if_must< COMMA, exp struct affect_op : sor< eq_op, multiplyeq_op, divideeq_op, pluseq_op, minuseq_op > {}; -struct affectation : seq< NAME , if_must< affect_op, sor< expression_list, expression > > >{}; - struct name_list; + +struct affectation : seq< sor< NAME, name_list >, if_must< affect_op, sor< expression_list, expression > > >{}; + struct declaration : if_must< type_expression, sor< NAME, name_list>, opt< if_must< seq< one< '=' >, ignored >, sor< expression_list, expression > > > >{}; struct type_mapping : seq< type_expression, RIGHT_ARROW, type_expression >{};