diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2024-11-07 21:06:39 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2025-01-19 17:20:07 -0600 |
| commit | 78bb30d44c5a2d0cd57bc1f7d9748b9381d23e54 (patch) | |
| tree | c49f8d9eee96c0dcb0377c80326f9603c9819b1f /Source/Core/InputCommon | |
| parent | 90eba2b1a0143f64856eb8eada6080ad7a5d5e33 (diff) | |
InputCommon/ExpressionParser: Require delimited tokens actually have their terminating delimiter.
Diffstat (limited to 'Source/Core/InputCommon')
| -rw-r--r-- | Source/Core/InputCommon/ControlReference/ExpressionParser.cpp | 17 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControlReference/ExpressionParser.h | 2 |
2 files changed, 11 insertions, 8 deletions
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(); |
