From 97c4344f33ba1e030c0ebe657b550127b27f93b5 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 26 Jul 2020 16:37:23 -0400 Subject: CppLexer: Add token types for "<", "<=", "<<", "<<=", "<>" --- Libraries/LibGUI/CppLexer.cpp | 30 ++++++++++++++++++++++++++++++ Libraries/LibGUI/CppLexer.h | 11 +++++++++++ 2 files changed, 41 insertions(+) diff --git a/Libraries/LibGUI/CppLexer.cpp b/Libraries/LibGUI/CppLexer.cpp index 4631a9185e..6f9cc1e101 100644 --- a/Libraries/LibGUI/CppLexer.cpp +++ b/Libraries/LibGUI/CppLexer.cpp @@ -342,6 +342,32 @@ Vector CppLexer::lex() emit_token(CppToken::Type::RightBracket); continue; } + if (ch == '<') { + begin_token(); + consume(); + if (peek() == '<') { + consume(); + if (peek() == '=') { + consume(); + commit_token(CppToken::Type::LessLessEquals); + continue; + } + commit_token(CppToken::Type::LessLess); + continue; + } + if (peek() == '=') { + consume(); + commit_token(CppToken::Type::LessEquals); + continue; + } + if (peek() == '>') { + consume(); + commit_token(CppToken::Type::LessGreater); + continue; + } + commit_token(CppToken::Type::Less); + continue; + } if (ch == ',') { emit_token(CppToken::Type::Comma); continue; @@ -358,6 +384,10 @@ Vector CppLexer::lex() emit_token_equals(CppToken::Type::Asterisk, CppToken::Type::AsteriskEquals); continue; } + if (ch == '%') { + emit_token_equals(CppToken::Type::Percent, CppToken::Type::PercentEquals); + continue; + } if (ch == '=') { emit_token_equals(CppToken::Type::Equals, CppToken::Type::EqualsEquals); continue; diff --git a/Libraries/LibGUI/CppLexer.h b/Libraries/LibGUI/CppLexer.h index cc0c76ecb6..4a7d077daa 100644 --- a/Libraries/LibGUI/CppLexer.h +++ b/Libraries/LibGUI/CppLexer.h @@ -43,6 +43,15 @@ namespace GUI { __TOKEN(RightCurly) \ __TOKEN(LeftBracket) \ __TOKEN(RightBracket) \ + __TOKEN(Less) \ + __TOKEN(Greater) \ + __TOKEN(LessEquals) \ + __TOKEN(GreaterEquals) \ + __TOKEN(LessLess) \ + __TOKEN(GreaterGreater) \ + __TOKEN(LessLessEquals) \ + __TOKEN(GreaterGreaterEquals) \ + __TOKEN(LessGreater) \ __TOKEN(Comma) \ __TOKEN(Plus) \ __TOKEN(PlusEquals) \ @@ -52,6 +61,8 @@ namespace GUI { __TOKEN(AsteriskEquals) \ __TOKEN(Slash) \ __TOKEN(SlashEquals) \ + __TOKEN(Percent) \ + __TOKEN(PercentEquals) \ __TOKEN(Equals) \ __TOKEN(EqualsEquals) \ __TOKEN(Semicolon) \ -- cgit v1.2.3