Skip to content

Commit

Permalink
fix quote in quotes issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Prevter committed Oct 9, 2024
1 parent c3f1c29 commit aa0aeab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/rift/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace rift {
Token parseNumber();

/// @brief Parse a string.
Token parseString();
Token parseString(char quote);

/// @brief Parse an identifier.
Token parseIdentifier();
Expand All @@ -57,4 +57,4 @@ namespace rift {
size_t m_expressionDepth = 0;
};

}
}
11 changes: 7 additions & 4 deletions src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace rift {
return parseIdentifier();
} else {
switch (c) {
case '\'': case '"': return parseString();
case '\'': case '"': return parseString(c);
case '(': return createToken(TokenType::LEFT_PAREN, "(");
case ')': return createToken(TokenType::RIGHT_PAREN, ")");
case '+': return createToken(TokenType::PLUS, "+");
Expand Down Expand Up @@ -157,10 +157,13 @@ namespace rift {
return createToken(TokenType::INTEGER, m_script.substr(start, m_index - start));
}

Token Lexer::parseString() {
Token Lexer::parseString(char quote) {
size_t start = m_index - 1;
while (!isEnd() && peek() != '\'' && peek() != '"') {
bool isSingleQuote = quote == '\'';
bool isEscape = false;
while (!isEnd() && (peek() != (isSingleQuote ? '\'' : '"') || isEscape)) {
advance();
isEscape = !isEscape && peek() == '\\';
}

if (isEnd()) {
Expand All @@ -179,4 +182,4 @@ namespace rift {
return createToken(TokenType::IDENTIFIER, m_script.substr(start, m_index - start));
}

}
}

0 comments on commit aa0aeab

Please sign in to comment.