mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 23:18:44 +00:00
variable namespace, function declaration fixes
This commit is contained in:
parent
c31b20fa24
commit
f973f65b5b
17 changed files with 511 additions and 98 deletions
|
|
@ -50,20 +50,15 @@ void BuildVisitor::Visit(Sources* node) {
|
|||
void BuildVisitor::Visit(Namespace* node) {
|
||||
auto parse_node = current_node_;
|
||||
|
||||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 2) {
|
||||
current_node_ = parse_node.ChildByFieldName("name");
|
||||
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 = Namespace::Const;
|
||||
} else if (modifier == "var") {
|
||||
node->modifier = Namespace::Var;
|
||||
}
|
||||
|
||||
node->name = ExtendedName();
|
||||
Visit(&node->name.value());
|
||||
}
|
||||
|
||||
current_node_ = parse_node.ChildByFieldName("type");
|
||||
|
|
@ -338,22 +333,10 @@ void BuildVisitor::Visit(FunctionDefinition* node) {
|
|||
size_t child_count = parse_node.NamedChildCount();
|
||||
|
||||
if (child_count > 1) {
|
||||
bool parameters_ended = false;
|
||||
|
||||
node->arguments.resize(child_count - 1);
|
||||
for (size_t i = 0; i + 1 < child_count; ++i) {
|
||||
current_node_ = parse_node.NthNamedChild(i + 1);
|
||||
|
||||
if (current_node_.GetType() != parser::tokens::AnnotatedAbstractType) {
|
||||
parameters_ended = true;
|
||||
}
|
||||
|
||||
if (!parameters_ended) {
|
||||
node->parameters.push_back(std::make_unique<AnnotatedAbstractType>());
|
||||
Visit(node->parameters.back().get());
|
||||
} else {
|
||||
node->arguments.emplace_back();
|
||||
Visit(&node->arguments.back());
|
||||
}
|
||||
Visit(&node->arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue