Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputCommon/ExpressionParser: Require delimited tokens actually have their terminating delimiter. #13279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ 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;
std::string value;
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()
Expand All @@ -110,7 +114,7 @@ std::string Lexer::FetchWordChars()

Token Lexer::GetDelimitedLiteral()
{
return Token(TOK_LITERAL, FetchDelimString('\''));
return GetDelimitedToken(TOK_LITERAL, '\'');
}

Token Lexer::GetVariable()
Expand All @@ -120,7 +124,7 @@ Token Lexer::GetVariable()

Token Lexer::GetFullyQualifiedControl()
{
return Token(TOK_CONTROL, FetchDelimString('`'));
return GetDelimitedToken(TOK_CONTROL, '`');
}

Token Lexer::GetBareword(char first_char)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class Lexer
return value;
}

std::string FetchDelimString(char delim);
std::string FetchWordChars();
Token GetDelimitedToken(TokenType type, char delimeter);
Token GetDelimitedLiteral();
Token GetVariable();
Token GetFullyQualifiedControl();
Expand Down