Replace ! with a function call writei
This commit is contained in:
@ -12,9 +12,9 @@ namespace elna::source
|
||||
definition->body().accept(this);
|
||||
}
|
||||
|
||||
void empty_visitor::visit(bang_statement *statement)
|
||||
void empty_visitor::visit(call_statement *statement)
|
||||
{
|
||||
statement->body().accept(this);
|
||||
statement->arguments().accept(this);
|
||||
}
|
||||
|
||||
void empty_visitor::visit(question_mark_statement *statement)
|
||||
@ -259,17 +259,22 @@ namespace elna::source
|
||||
return m_operator;
|
||||
}
|
||||
|
||||
bang_statement::bang_statement(std::unique_ptr<expression>&& body)
|
||||
: m_body(std::move(body))
|
||||
call_statement::call_statement(const std::string& name, std::unique_ptr<expression>&& body)
|
||||
: m_name(name), m_body(std::move(body))
|
||||
{
|
||||
}
|
||||
|
||||
void bang_statement::accept(parser_visitor *visitor)
|
||||
void call_statement::accept(parser_visitor *visitor)
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
expression& bang_statement::body()
|
||||
std::string& call_statement::name() noexcept
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
expression& call_statement::arguments()
|
||||
{
|
||||
return *m_body;
|
||||
}
|
||||
@ -510,9 +515,9 @@ namespace elna::source
|
||||
{
|
||||
return parse_assign_statement();
|
||||
}
|
||||
else if (iterator.current(token::type::bang))
|
||||
else if (iterator.current(token::type::identifier) && iterator.look_ahead(token::type::left_paren))
|
||||
{
|
||||
return parse_bang_statement();
|
||||
return parse_call_statement();
|
||||
}
|
||||
else if (iterator.current(token::type::question_mark))
|
||||
{
|
||||
@ -534,17 +539,18 @@ namespace elna::source
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<bang_statement> parser::parse_bang_statement()
|
||||
std::unique_ptr<call_statement> parser::parse_call_statement()
|
||||
{
|
||||
if (!iterator.advance(token::type::bang))
|
||||
auto function_name = iterator.advance(token::type::identifier);
|
||||
if (function_name.has_value() && !iterator.skip(token::type::left_paren))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
auto bang_body = parse_expression();
|
||||
|
||||
if (bang_body != nullptr)
|
||||
if (bang_body != nullptr && iterator.skip(token::type::right_paren))
|
||||
{
|
||||
return std::make_unique<bang_statement>(std::move(bang_body));
|
||||
return std::make_unique<call_statement>(function_name->get().identifier(), std::move(bang_body));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user