mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
ExpressionParser: Allow unary functions to be used without parens around the argument. e.g. !Up
This commit is contained in:
parent
2a377e35ed
commit
d4f9b8c4ef
@ -839,7 +839,14 @@ private:
|
|||||||
std::vector<Token> tokens;
|
std::vector<Token> tokens;
|
||||||
std::vector<Token>::iterator m_it;
|
std::vector<Token>::iterator m_it;
|
||||||
|
|
||||||
Token Chew() { return *m_it++; }
|
Token Chew()
|
||||||
|
{
|
||||||
|
const Token tok = Peek();
|
||||||
|
if (TOK_EOF != tok.type)
|
||||||
|
++m_it;
|
||||||
|
return tok;
|
||||||
|
}
|
||||||
|
|
||||||
Token Peek() { return *m_it; }
|
Token Peek() { return *m_it; }
|
||||||
|
|
||||||
bool Expects(TokenType type)
|
bool Expects(TokenType type)
|
||||||
@ -850,14 +857,28 @@ private:
|
|||||||
|
|
||||||
FunctionArguments ParseFunctionArguments()
|
FunctionArguments ParseFunctionArguments()
|
||||||
{
|
{
|
||||||
if (!Expects(TOK_LPAREN))
|
std::vector<std::unique_ptr<Expression>> args;
|
||||||
return {ParseStatus::SyntaxError};
|
|
||||||
|
if (TOK_LPAREN != Peek().type)
|
||||||
|
{
|
||||||
|
// Single argument with no parens (useful for unary ! function)
|
||||||
|
auto arg = ParseAtom(Chew());
|
||||||
|
if (ParseStatus::Successful != arg.status)
|
||||||
|
return {ParseStatus::SyntaxError};
|
||||||
|
|
||||||
|
args.emplace_back(std::move(arg.expr));
|
||||||
|
return {ParseStatus::Successful, std::move(args)};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chew the L-Paren
|
||||||
|
Chew();
|
||||||
|
|
||||||
// Check for empty argument list:
|
// Check for empty argument list:
|
||||||
if (TOK_RPAREN == Peek().type)
|
if (TOK_RPAREN == Peek().type)
|
||||||
|
{
|
||||||
|
Chew();
|
||||||
return {ParseStatus::Successful};
|
return {ParseStatus::Successful};
|
||||||
|
}
|
||||||
std::vector<std::unique_ptr<Expression>> args;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user