diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index 7fdf677a91..0004393909 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -92,12 +92,15 @@ Lexer::Lexer(std::string expr_) : expr(std::move(expr_)) it = expr.begin(); } -std::string Lexer::FetchDelimString(char delim) +Token Lexer::GetDelimitedToken(TokenType type, char delimeter) { - const std::string result = FetchCharsWhile([delim](char c) { return c != delim; }); - if (it != expr.end()) - ++it; - return result; + const std::string value = FetchCharsWhile([&](char c) { return c != delimeter && c != '\n'; }); + + if (it == expr.end() || *it != delimeter) + return Token(TOK_INVALID); + + ++it; + return Token(type, value); } std::string Lexer::FetchWordChars() @@ -110,7 +113,7 @@ std::string Lexer::FetchWordChars() Token Lexer::GetDelimitedLiteral() { - return Token(TOK_LITERAL, FetchDelimString('\'')); + return GetDelimitedToken(TOK_LITERAL, '\''); } Token Lexer::GetVariable() @@ -120,7 +123,7 @@ Token Lexer::GetVariable() Token Lexer::GetFullyQualifiedControl() { - return Token(TOK_CONTROL, FetchDelimString('`')); + return GetDelimitedToken(TOK_CONTROL, '`'); } Token Lexer::GetBareword(char first_char) diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.h b/Source/Core/InputCommon/ControlReference/ExpressionParser.h index bc39762127..3172e77f48 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.h +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.h @@ -91,8 +91,8 @@ private: return value; } - std::string FetchDelimString(char delim); std::string FetchWordChars(); + Token GetDelimitedToken(TokenType type, char delimeter); Token GetDelimitedLiteral(); Token GetVariable(); Token GetFullyQualifiedControl();