Skip to content
Permalink
Browse files

ExpressionParser: Allow unary functions to be used without parens aro…

…und the argument. e.g. !`Up`
  • Loading branch information...
jordan-woyak committed Jan 20, 2019
1 parent 2a377e3 commit d4f9b8c4efe9ce48aac5b43487c5d6c5d5fbd83b
Showing with 26 additions and 5 deletions.
  1. +26 −5 Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
@@ -839,7 +839,14 @@ class Parser
std::vector<Token> tokens;
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; }

bool Expects(TokenType type)
@@ -850,14 +857,28 @@ class Parser

FunctionArguments ParseFunctionArguments()
{
if (!Expects(TOK_LPAREN))
return {ParseStatus::SyntaxError};
std::vector<std::unique_ptr<Expression>> args;

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:
if (TOK_RPAREN == Peek().type)
{
Chew();
return {ParseStatus::Successful};

std::vector<std::unique_ptr<Expression>> args;
}

while (true)
{

0 comments on commit d4f9b8c

Please sign in to comment.
You can’t perform that action at this time.