Skip to content
Snippets Groups Projects
Unverified Commit 89a2f041 authored by Nora Abi Akar's avatar Nora Abi Akar Committed by GitHub
Browse files

Modcc: parse the unit of `FUNCTION` (#1361)

* add function unit parsing
* add unit tests
parent 2adcd65c
No related branches found
No related tags found
No related merge requests found
......@@ -973,6 +973,14 @@ symbol_ptr Parser::parse_function() {
auto p = parse_prototype();
if (p == nullptr) return nullptr;
// Functions may have a unit attached
if (token_.type == tok::lparen) {
unit_description();
if (status_ == lexerStatus::error) {
return {};
}
}
// check for opening left brace {
if (!expect(tok::lbrace)) return nullptr;
......
......@@ -205,17 +205,46 @@ TEST(Parser, net_receive) {
}
TEST(Parser, function) {
char str[] =
"FUNCTION foo(x, y) {"
" LOCAL a\n"
" a = 3\n"
" b = x * y + 2\n"
" y = x + y * 2\n"
" foo = a * x + y\n"
"}";
{
char str[] =
"FUNCTION foo(x, y) {"
" LOCAL a\n"
" a = 3\n"
" b = x * y + 2\n"
" y = x + y * 2\n"
" foo = a * x + y\n"
"}";
std::unique_ptr<Symbol> sym;
EXPECT_TRUE(check_parse(sym, &Parser::parse_function, str));
}
{
char str[] =
"FUNCTION foo(x (mv), y (/mA)) {"
" foo = x * y\n"
"}";
std::unique_ptr<Symbol> sym;
EXPECT_TRUE(check_parse(sym, &Parser::parse_function, str));
std::unique_ptr<Symbol> sym;
EXPECT_TRUE(check_parse(sym, &Parser::parse_function, str));
}
{
char str[] =
"FUNCTION foo(x (mv), y (/mA)) (mv/mA) {"
" foo = x * y\n"
"}";
std::unique_ptr<Symbol> sym;
EXPECT_TRUE(check_parse(sym, &Parser::parse_function, str));
}
{
char str[] =
"FUNCTION foo(x (mv), y (/mA)) (mv-mA) {"
" foo = x * y\n"
"}";
std::unique_ptr<Symbol> sym;
EXPECT_FALSE(check_parse(sym, &Parser::parse_function, str));
}
}
TEST(Parser, parse_solve) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment