summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-07-26 20:49:17 -0400
committerAndreas Kling <kling@serenityos.org>2020-07-27 12:11:19 +0200
commit9ee1edae2aefcb95e87b710333127872bb174903 (patch)
treed88366114c20b682aa6ddd1afa81a4212e1c4b5f /Libraries
parent4d783338c1ce1ce05d9eceb49529c46d524bfd40 (diff)
downloadserenity-9ee1edae2aefcb95e87b710333127872bb174903.zip
CppLexer: Support raw string literals
Handles prefixes and delimiters (`R"(text)", `u8R"f(text)f"`, ...).
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/CppLexer.cpp22
-rw-r--r--Libraries/LibGUI/CppLexer.h1
-rw-r--r--Libraries/LibGUI/CppSyntaxHighlighter.cpp1
3 files changed, 24 insertions, 0 deletions
diff --git a/Libraries/LibGUI/CppLexer.cpp b/Libraries/LibGUI/CppLexer.cpp
index 45fbd310eb..b7b89e4ec3 100644
--- a/Libraries/LibGUI/CppLexer.cpp
+++ b/Libraries/LibGUI/CppLexer.cpp
@@ -636,6 +636,28 @@ Vector<CppToken> CppLexer::lex()
commit_token(CppToken::Type::DoubleQuotedString);
continue;
}
+ if (size_t prefix = match_string_prefix('R'); prefix > 0 && peek(prefix) == '"') {
+ begin_token();
+ for (size_t i = 0; i < prefix + 1; ++i)
+ consume();
+ size_t prefix_start = m_index;
+ while (peek() && peek() != '(')
+ consume();
+ StringView prefix_string = m_input.substring_view(prefix_start, m_index - prefix_start);
+ while (peek()) {
+ if (consume() == '"') {
+ ASSERT(m_index >= prefix_string.length() + 2);
+ ASSERT(m_input[m_index - 1] == '"');
+ if (m_input[m_index - 1 - prefix_string.length() - 1] == ')') {
+ StringView suffix_string = m_input.substring_view(m_index - 1 - prefix_string.length(), prefix_string.length());
+ if (prefix_string == suffix_string)
+ break;
+ }
+ }
+ }
+ commit_token(CppToken::Type::DoubleQuotedString);
+ continue;
+ }
if (size_t prefix = match_string_prefix('\''); prefix > 0) {
begin_token();
for (size_t i = 0; i < prefix; ++i)
diff --git a/Libraries/LibGUI/CppLexer.h b/Libraries/LibGUI/CppLexer.h
index 5e14dc2d88..e484ee2997 100644
--- a/Libraries/LibGUI/CppLexer.h
+++ b/Libraries/LibGUI/CppLexer.h
@@ -89,6 +89,7 @@ namespace GUI {
__TOKEN(ArrowAsterisk) \
__TOKEN(DoubleQuotedString) \
__TOKEN(SingleQuotedString) \
+ __TOKEN(RawString) \
__TOKEN(EscapeSequence) \
__TOKEN(Comment) \
__TOKEN(Integer) \
diff --git a/Libraries/LibGUI/CppSyntaxHighlighter.cpp b/Libraries/LibGUI/CppSyntaxHighlighter.cpp
index 329e792ad8..f1b4d225b5 100644
--- a/Libraries/LibGUI/CppSyntaxHighlighter.cpp
+++ b/Libraries/LibGUI/CppSyntaxHighlighter.cpp
@@ -43,6 +43,7 @@ static TextStyle style_for_token_type(Gfx::Palette palette, CppToken::Type type)
return { palette.syntax_identifier() };
case CppToken::Type::DoubleQuotedString:
case CppToken::Type::SingleQuotedString:
+ case CppToken::Type::RawString:
return { palette.syntax_string() };
case CppToken::Type::Integer:
case CppToken::Type::Float: