mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-09 08:28:43 +00:00
fixes, optional type name added
This commit is contained in:
parent
d38d75c9d8
commit
0850e6aa6b
14 changed files with 163 additions and 99 deletions
|
|
@ -53,19 +53,11 @@ void BuildVisitor::Visit(Namespace* node) {
|
|||
|
||||
auto parse_node = current_node_;
|
||||
|
||||
size_t child_count = parse_node.ChildCount();
|
||||
|
||||
if (child_count > 3) { // "namespace", ["var"/"const",] type, scope
|
||||
std::string modifier = parse_node.NthChild(1).GetValue();
|
||||
if (modifier == "const") {
|
||||
node->modifier = utils::ClassInternalsModifier::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = utils::ClassInternalsModifier::Var;
|
||||
} else {
|
||||
error_handling::HandleInternalError("Can't parse namespace modifier",
|
||||
"BuildVisitor.Namespace",
|
||||
&node->base);
|
||||
}
|
||||
std::string modifier = parse_node.NthChild(1).GetValue();
|
||||
if (modifier == "const") {
|
||||
node->modifier = utils::ClassInternalsModifier::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = utils::ClassInternalsModifier::Var;
|
||||
} else {
|
||||
node->modifier = utils::ClassInternalsModifier::Static;
|
||||
}
|
||||
|
|
@ -1380,17 +1372,50 @@ void BuildVisitor::Visit(TypeExpression* node) {
|
|||
Visit(&node->type);
|
||||
++excluded_child_count;
|
||||
|
||||
current_node_ = current_node_.NextSibling();
|
||||
auto suffix_node1 = current_node_.NextSibling();
|
||||
|
||||
if (!current_node_.IsNull()) {
|
||||
current_node_ = current_node_.NextSibling();
|
||||
if (!current_node_.IsNull()) {
|
||||
NumberLiteral literal;
|
||||
Visit(&literal);
|
||||
node->array_size = literal.value;
|
||||
++excluded_child_count;
|
||||
// TODO: better structure // TODO: check
|
||||
if (!suffix_node1.IsNull()) {
|
||||
auto suffix_node2 = suffix_node1.NextSibling();
|
||||
if (!suffix_node2.IsNull()) {
|
||||
auto suffix_node3 = suffix_node2.NextSibling();
|
||||
if (!suffix_node3.IsNull()) {
|
||||
current_node_ = suffix_node2;
|
||||
|
||||
NumberLiteral literal;
|
||||
Visit(&literal);
|
||||
node->array_size = literal.value;
|
||||
++excluded_child_count;
|
||||
|
||||
node->is_optional = true;
|
||||
} else {
|
||||
if (suffix_node1.GetValue() == "_" && suffix_node2.GetValue() == "!") {
|
||||
node->array_size = 0;
|
||||
|
||||
node->is_optional = true;
|
||||
} else if (suffix_node1.GetValue() == "_") {
|
||||
current_node_ = suffix_node2;
|
||||
|
||||
NumberLiteral literal;
|
||||
Visit(&literal);
|
||||
node->array_size = literal.value;
|
||||
++excluded_child_count;
|
||||
} else {
|
||||
error_handling::HandleInternalError("Undefined suffix (2 elements)",
|
||||
"BuildVisitor.TypeExpression",
|
||||
std::nullopt);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
node->array_size = 0;
|
||||
if (suffix_node1.GetValue() == "_") {
|
||||
node->array_size = 0;
|
||||
} else if (suffix_node1.GetValue() == "!") {
|
||||
node->is_optional = true;
|
||||
} else {
|
||||
error_handling::HandleInternalError("Undefined suffix (1 element)",
|
||||
"BuildVisitor.TypeExpression",
|
||||
std::nullopt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue