simplify parser

This commit is contained in:
Alex Beregszaszi 2020-07-30 12:12:55 +01:00 committed by chriseth
parent 3862ceb528
commit 3da2b67b67
3 changed files with 13 additions and 24 deletions

View File

@ -265,10 +265,12 @@ Expression Parser::parseExpression()
RecursionGuard recursionGuard(*this);
ElementaryOperation operation = parseElementaryOperation();
if (holds_alternative<FunctionCall>(operation) || currentToken() == Token::LParen)
return parseCall(std::move(operation));
else if (holds_alternative<Identifier>(operation))
if (holds_alternative<Identifier>(operation))
{
if (currentToken() == Token::LParen)
return parseCall(std::move(operation));
return std::get<Identifier>(operation);
}
else
{
yulAssert(holds_alternative<Literal>(operation), "");
@ -284,16 +286,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
{
case Token::Identifier:
{
YulString literal{currentLiteral()};
if (m_dialect.builtin(literal))
{
Identifier identifier{currentLocation(), literal};
advance();
expectToken(Token::LParen, false);
return FunctionCall{identifier.location, identifier, {}};
}
else
ret = Identifier{currentLocation(), literal};
ret = Identifier{currentLocation(), YulString{currentLiteral()}};
advance();
break;
}
@ -422,17 +415,13 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp)
{
RecursionGuard recursionGuard(*this);
FunctionCall ret;
if (holds_alternative<Identifier>(_initialOp))
{
ret.functionName = std::move(std::get<Identifier>(_initialOp));
ret.location = ret.functionName.location;
}
else if (holds_alternative<FunctionCall>(_initialOp))
ret = std::move(std::get<FunctionCall>(_initialOp));
else
if (!holds_alternative<Identifier>(_initialOp))
fatalParserError(9980_error, "Function name expected.");
FunctionCall ret;
ret.functionName = std::move(std::get<Identifier>(_initialOp));
ret.location = ret.functionName.location;
expectToken(Token::LParen);
if (currentToken() != Token::RParen)
{

View File

@ -7,4 +7,4 @@ contract C {
}
}
// ----
// ParserError 2314: (95-98): Expected '(' but got identifier
// ParserError 6913: (95-98): Call or assignment expected.

View File

@ -6,4 +6,4 @@ contract test {
}
}
// ----
// ParserError 2314: (85-86): Expected '(' but got '}'
// ParserError 6913: (85-86): Call or assignment expected.