mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:02:45 +00:00 
			
		
		
		
	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.
			
			
This commit is contained in:
		
							parent
							
								
									261f233060
								
							
						
					
					
						commit
						a9378ce5c2
					
				
					 2 changed files with 7 additions and 10 deletions
				
			
		|  | @ -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 (;;) { | ||||||
|     for (auto token = lexer.next(); !was_eof; token = lexer.next()) { |         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)); | ||||||
|  |  | ||||||
|  | @ -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; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Max Wipfli
						Max Wipfli