From 5a36d8acb85ae346f670467e761deb724a5f4813 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 26 Jul 2020 13:35:47 -0400 Subject: [PATCH] CppLexer: Add token type for "*=" --- Libraries/LibGUI/CppLexer.cpp | 13 ++++++++++++- Libraries/LibGUI/CppLexer.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/CppLexer.cpp b/Libraries/LibGUI/CppLexer.cpp index c901437d00..8db91f3f23 100644 --- a/Libraries/LibGUI/CppLexer.cpp +++ b/Libraries/LibGUI/CppLexer.cpp @@ -243,6 +243,17 @@ Vector CppLexer::lex() tokens.append(token); }; + auto emit_token_equals = [&](auto type, auto equals_type) { + if (peek(1) == '=') { + begin_token(); + consume(); + consume(); + commit_token(equals_type); + return; + } + emit_token(type); + }; + auto match_escape_sequence = [&]() -> size_t { switch (peek(1)) { case '\'': @@ -336,7 +347,7 @@ Vector CppLexer::lex() continue; } if (ch == '*') { - emit_token(CppToken::Type::Asterisk); + emit_token_equals(CppToken::Type::Asterisk, CppToken::Type::AsteriskEquals); continue; } if (ch == ';') { diff --git a/Libraries/LibGUI/CppLexer.h b/Libraries/LibGUI/CppLexer.h index 9de2e319e0..7e217c8b10 100644 --- a/Libraries/LibGUI/CppLexer.h +++ b/Libraries/LibGUI/CppLexer.h @@ -45,6 +45,7 @@ namespace GUI { __TOKEN(RightBracket) \ __TOKEN(Comma) \ __TOKEN(Asterisk) \ + __TOKEN(AsteriskEquals) \ __TOKEN(Semicolon) \ __TOKEN(DoubleQuotedString) \ __TOKEN(SingleQuotedString) \