浏览代码

LibSQL: Clean up SyntaxHighlighter code

This changes SyntaxHighlighter.{cpp,h} to use east const style. It also
removes two unused headers and simplifies a loop.
Max Wipfli 4 年之前
父节点
当前提交
a9378ce5c2
共有 2 个文件被更改,包括 7 次插入10 次删除
  1. 6 9
      Userland/Libraries/LibSQL/SyntaxHighlighter.cpp
  2. 1 1
      Userland/Libraries/LibSQL/SyntaxHighlighter.h

+ 6 - 9
Userland/Libraries/LibSQL/SyntaxHighlighter.cpp

@@ -5,15 +5,13 @@
  */
  */
 
 
 #include <AK/Debug.h>
 #include <AK/Debug.h>
-#include <LibGUI/TextEditor.h>
-#include <LibGfx/Font.h>
 #include <LibGfx/Palette.h>
 #include <LibGfx/Palette.h>
 #include <LibSQL/Lexer.h>
 #include <LibSQL/Lexer.h>
 #include <LibSQL/SyntaxHighlighter.h>
 #include <LibSQL/SyntaxHighlighter.h>
 
 
 namespace SQL {
 namespace SQL {
 
 
-static Syntax::TextStyle style_for_token_type(const Gfx::Palette& palette, TokenType type)
+static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, TokenType type)
 {
 {
     switch (Token::category(type)) {
     switch (Token::category(type)) {
     case TokenCategory::Keyword:
     case TokenCategory::Keyword:
@@ -41,7 +39,7 @@ bool SyntaxHighlighter::is_identifier(void* token) const
     return sql_token == SQL::TokenType::Identifier;
     return sql_token == SQL::TokenType::Identifier;
 }
 }
 
 
-void SyntaxHighlighter::rehighlight(const Palette& palette)
+void SyntaxHighlighter::rehighlight(Palette const& palette)
 {
 {
     auto text = m_client->get_text();
     auto text = m_client->get_text();
 
 
@@ -49,7 +47,7 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
 
 
     Vector<GUI::TextDocumentSpan> spans;
     Vector<GUI::TextDocumentSpan> spans;
 
 
-    auto append_token = [&](StringView str, const SQL::Token& token) {
+    auto append_token = [&](StringView str, SQL::Token const& token) {
         if (str.is_empty())
         if (str.is_empty())
             return;
             return;
 
 
@@ -78,12 +76,11 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
             span.range.end().line(), span.range.end().column());
             span.range.end().line(), span.range.end().column());
     };
     };
 
 
-    bool was_eof = false;
-    for (auto token = lexer.next(); !was_eof; token = lexer.next()) {
+    for (;;) {
+        auto token = lexer.next();
         append_token(token.value(), token);
         append_token(token.value(), token);
-
         if (token.type() == SQL::TokenType::Eof)
         if (token.type() == SQL::TokenType::Eof)
-            was_eof = true;
+            break;
     }
     }
 
 
     m_client->do_set_spans(move(spans));
     m_client->do_set_spans(move(spans));

+ 1 - 1
Userland/Libraries/LibSQL/SyntaxHighlighter.h

@@ -18,7 +18,7 @@ public:
     virtual bool is_identifier(void*) const override;
     virtual bool is_identifier(void*) const override;
 
 
     virtual Syntax::Language language() const override { return Syntax::Language::SQL; }
     virtual Syntax::Language language() const override { return Syntax::Language::SQL; }
-    virtual void rehighlight(const Palette&) override;
+    virtual void rehighlight(Palette const&) override;
 
 
 protected:
 protected:
     virtual Vector<MatchingTokenPair> matching_token_pairs() const override;
     virtual Vector<MatchingTokenPair> matching_token_pairs() const override;