Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/include/compiler/ast/node_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum class NodeType {
IfStatement,
IntegerLiteralValue,
ListAccessor,
ListDynamicSize,
ListStatement,
PassStatement,
ProgramRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <functional>
#include <stack>
#include <unordered_map>

#include "compiler/ast/node.hpp"
#include "compiler/ast/types.hpp"
#include "compiler/ast/node_type.hpp"
#include "compiler/utils/error_buffer.hpp"
#include "compiler/utils/source_ref.hpp"

Expand All @@ -27,21 +26,21 @@ struct ParserContext {
return *tokenIter;
}

static ast::Node::Ptr pushChildNode(ast::Node::Ptr node, const ast::NodeType &nodeType,
static ast::Node::Ptr pushChildNode(const ast::Node::Ptr &node, ast::NodeType nodeType,
const utils::SourceRef &ref) {
auto &childNode = node->children.emplace_back(new ast::Node(nodeType, node));
childNode->ref = ref;
return childNode;
}

static ast::Node::Ptr unshiftChildNode(ast::Node::Ptr node, const ast::NodeType &nodeType,
static ast::Node::Ptr unshiftChildNode(const ast::Node::Ptr &node, ast::NodeType nodeType,
const utils::SourceRef &ref) {
auto &childNode = node->children.emplace_front(new ast::Node(nodeType, node));
childNode->ref = ref;
return childNode;
}

ast::Node::Ptr pushChildNode(const ast::NodeType &nodeType) {
ast::Node::Ptr pushChildNode(ast::NodeType nodeType) {
return pushChildNode(node, nodeType, tokenIter->ref);
}

Expand Down
7 changes: 5 additions & 2 deletions compiler/lib/ast/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ void Node::dump(std::ostream &stream, int depth) const {
case NodeType::ListAccessor:
stream << "ListAccessor\n";
break;
case NodeType::ListDynamicSize:
stream << "ListDynamicSize\n";
break;
case NodeType::ForStatement:
stream << "ForStatement\n";
break;
Expand All @@ -221,12 +224,12 @@ void Node::dump(std::ostream &stream, int depth) const {
default:
stream << "Unknown\n";
}
for (auto child : children)
for (const auto &child : children)
child->dump(stream, depth + 1);
}

std::string Node::dump(int depth) const {
std::stringstream str;
dump(str);
dump(str, depth);
return str.str();
}
13 changes: 12 additions & 1 deletion compiler/lib/frontend/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,18 @@ void parseListStatement(ParserContext &ctx) {
ctx.goParentNode();
}
ctx.goNextToken();
ctx.goParentNode();
if (ctx.token().is(Special::EndOfExpression)) {
ctx.goParentNode();
} else if (ctx.token().is(Operator::Mult)) {
ctx.goNextToken();
ctx.node = ctx.pushChildNode(NodeType::ListDynamicSize);
ctx.node = ctx.pushChildNode(NodeType::Expression);
ctx.propagate();
ctx.goParentNode();
ctx.goParentNode();
} else {
ctx.pushError("Either end of line or '*' was expected");
}
ctx.goParentNode();
}

Expand Down