mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
simplify parser
This commit is contained in:
parent
3862ceb528
commit
3da2b67b67
@ -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)
|
||||
{
|
||||
|
@ -7,4 +7,4 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (95-98): Expected '(' but got identifier
|
||||
// ParserError 6913: (95-98): Call or assignment expected.
|
||||
|
@ -6,4 +6,4 @@ contract test {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// ParserError 2314: (85-86): Expected '(' but got '}'
|
||||
// ParserError 6913: (85-86): Call or assignment expected.
|
||||
|
Loading…
Reference in New Issue
Block a user