mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +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 <LibGUI/TextEditor.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibSQL/Lexer.h>
|
||||
#include <LibSQL/SyntaxHighlighter.h>
|
||||
|
||||
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)) {
|
||||
case TokenCategory::Keyword:
|
||||
|
@ -41,7 +39,7 @@ bool SyntaxHighlighter::is_identifier(void* token) const
|
|||
return sql_token == SQL::TokenType::Identifier;
|
||||
}
|
||||
|
||||
void SyntaxHighlighter::rehighlight(const Palette& palette)
|
||||
void SyntaxHighlighter::rehighlight(Palette const& palette)
|
||||
{
|
||||
auto text = m_client->get_text();
|
||||
|
||||
|
@ -49,7 +47,7 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
|
|||
|
||||
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())
|
||||
return;
|
||||
|
||||
|
@ -78,12 +76,11 @@ void SyntaxHighlighter::rehighlight(const Palette& palette)
|
|||
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);
|
||||
|
||||
if (token.type() == SQL::TokenType::Eof)
|
||||
was_eof = true;
|
||||
break;
|
||||
}
|
||||
|
||||
m_client->do_set_spans(move(spans));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue