summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2024-11-07 19:34:55 -0600
committerJordan Woyak <jordan.woyak@gmail.com>2025-01-17 02:29:23 -0600
commitc94ec85460070b91f9c337dec59b7f9f45e0f825 (patch)
tree71cb3da0c0eb25ad67c0ca5065f25c3e6f286c75 /Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
parent2c83a256ae4b954314f5cef1d1d60792f06bd84b (diff)
InputCommon: Make input expression multiline-comment tokenizing less hacky.
Diffstat (limited to 'Source/Core/InputCommon/ControlReference/ExpressionParser.cpp')
-rw-r--r--Source/Core/InputCommon/ControlReference/ExpressionParser.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
index 7fdf677a91..f3cb5206af 100644
--- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
+++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
@@ -181,7 +181,19 @@ Token Lexer::NextToken()
case '*':
return Token(TOK_MUL);
case '/':
+ {
+ // Handle /* */ style comments.
+ if (it != expr.end() && *it == '*')
+ {
+ ++it;
+ const auto end_of_comment = expr.find("*/", it - expr.begin());
+ if (end_of_comment == std::string::npos)
+ return Token(TOK_INVALID);
+ it = expr.begin() + end_of_comment + 2;
+ return Token(TOK_COMMENT);
+ }
return Token(TOK_DIV);
+ }
case '%':
return Token(TOK_MOD);
case '=':
@@ -214,26 +226,10 @@ ParseStatus Lexer::Tokenize(std::vector<Token>& tokens)
{
while (true)
{
- const std::size_t string_position = it - expr.begin();
+ const std::string::iterator prev_it = it;
Token tok = NextToken();
-
- tok.string_position = string_position;
- tok.string_length = it - expr.begin();
-
- // Handle /* */ style comments.
- if (tok.type == TOK_DIV && PeekToken().type == TOK_MUL)
- {
- const auto end_of_comment = expr.find("*/", it - expr.begin());
-
- if (end_of_comment == std::string::npos)
- return ParseStatus::SyntaxError;
-
- tok.type = TOK_COMMENT;
- tok.string_length = end_of_comment + 4;
-
- it = expr.begin() + end_of_comment + 2;
- }
-
+ tok.string_position = prev_it - expr.begin();
+ tok.string_length = it - prev_it;
tokens.push_back(tok);
if (tok.type == TOK_INVALID)