summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-07-26 20:16:55 -0400
committerAndreas Kling <kling@serenityos.org>2020-07-27 12:11:19 +0200
commit4d783338c1ce1ce05d9eceb49529c46d524bfd40 (patch)
treecf4b6b8dac567d732a7ad8a9c3355f1d6557c335 /Libraries
parent34dc1634418aded05b3b1e8230b39b297e1307ce (diff)
downloadserenity-4d783338c1ce1ce05d9eceb49529c46d524bfd40.zip
CppLexer: Support L, u, u8, U prefixes on string and char literals
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/CppLexer.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/Libraries/LibGUI/CppLexer.cpp b/Libraries/LibGUI/CppLexer.cpp
index e5918604bc..45fbd310eb 100644
--- a/Libraries/LibGUI/CppLexer.cpp
+++ b/Libraries/LibGUI/CppLexer.cpp
@@ -308,6 +308,22 @@ Vector<CppToken> CppLexer::lex()
}
};
+ auto match_string_prefix = [&](char quote) -> size_t {
+ if (peek() == quote)
+ return 1;
+ if (peek() == 'L' && peek(1) == quote)
+ return 2;
+ if (peek() == 'u') {
+ if (peek(1) == quote)
+ return 2;
+ if (peek(1) == '8' && peek(2) == quote)
+ return 3;
+ }
+ if (peek() == 'U' && peek(1) == quote)
+ return 2;
+ return 0;
+ };
+
while (m_index < m_input.length()) {
auto ch = peek();
if (isspace(ch)) {
@@ -597,13 +613,13 @@ Vector<CppToken> CppLexer::lex()
emit_token_equals(CppToken::Type::Slash, CppToken::Type::SlashEquals);
continue;
}
- if (ch == '"') {
+ if (size_t prefix = match_string_prefix('"'); prefix > 0) {
begin_token();
- consume();
+ for (size_t i = 0; i < prefix; ++i)
+ consume();
while (peek()) {
if (peek() == '\\') {
- size_t escape = match_escape_sequence();
- if (escape > 0) {
+ if (size_t escape = match_escape_sequence(); escape > 0) {
commit_token(CppToken::Type::DoubleQuotedString);
begin_token();
for (size_t i = 0; i < escape; ++i)
@@ -620,13 +636,13 @@ Vector<CppToken> CppLexer::lex()
commit_token(CppToken::Type::DoubleQuotedString);
continue;
}
- if (ch == '\'') {
+ if (size_t prefix = match_string_prefix('\''); prefix > 0) {
begin_token();
- consume();
+ for (size_t i = 0; i < prefix; ++i)
+ consume();
while (peek()) {
if (peek() == '\\') {
- size_t escape = match_escape_sequence();
- if (escape > 0) {
+ if (size_t escape = match_escape_sequence(); escape > 0) {
commit_token(CppToken::Type::SingleQuotedString);
begin_token();
for (size_t i = 0; i < escape; ++i)