mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
LibSyntax: Move GUI::Highlighter to Syntax::Highlighter in LibSyntax
This is a move towards dropping more LibGUI dependencies.
This commit is contained in:
parent
ff2438e0ce
commit
43c7d7d285
22 changed files with 99 additions and 61 deletions
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
#include "Cell.h"
|
#include "Cell.h"
|
||||||
#include <LibGUI/JSSyntaxHighlighter.h>
|
#include <LibGUI/JSSyntaxHighlighter.h>
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
|
||||||
|
|
||||||
namespace Spreadsheet {
|
namespace Spreadsheet {
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
m_cell_value_editor->set_enabled(true);
|
m_cell_value_editor->set_enabled(true);
|
||||||
static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&cell);
|
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(&cell);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,11 +207,11 @@ void SpreadsheetWidget::setup_tabs(NonnullRefPtrVector<Sheet> new_sheets)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
m_cell_value_editor->set_enabled(true);
|
m_cell_value_editor->set_enabled(true);
|
||||||
static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(first_cell);
|
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(first_cell);
|
||||||
};
|
};
|
||||||
m_selected_view->on_selection_dropped = [&]() {
|
m_selected_view->on_selection_dropped = [&]() {
|
||||||
m_cell_value_editor->set_enabled(false);
|
m_cell_value_editor->set_enabled(false);
|
||||||
static_cast<CellSyntaxHighlighter*>(const_cast<GUI::SyntaxHighlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
|
static_cast<CellSyntaxHighlighter*>(const_cast<Syntax::Highlighter*>(m_cell_value_editor->syntax_highlighter()))->set_cell(nullptr);
|
||||||
m_cell_value_editor->set_text("");
|
m_cell_value_editor->set_text("");
|
||||||
m_current_cell_label->set_enabled(false);
|
m_current_cell_label->set_enabled(false);
|
||||||
m_current_cell_label->set_text("");
|
m_current_cell_label->set_text("");
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/ScrollBar.h>
|
#include <LibGUI/ScrollBar.h>
|
||||||
#include <LibGUI/ShellSyntaxHighlighter.h>
|
#include <LibGUI/ShellSyntaxHighlighter.h>
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibMarkdown/Document.h>
|
#include <LibMarkdown/Document.h>
|
||||||
#include <LibWeb/DOM/ElementFactory.h>
|
#include <LibWeb/DOM/ElementFactory.h>
|
||||||
|
|
|
@ -27,6 +27,7 @@ add_subdirectory(LibProtocol)
|
||||||
add_subdirectory(LibPthread)
|
add_subdirectory(LibPthread)
|
||||||
add_subdirectory(LibRegex)
|
add_subdirectory(LibRegex)
|
||||||
add_subdirectory(LibSymbolClient)
|
add_subdirectory(LibSymbolClient)
|
||||||
|
add_subdirectory(LibSyntax)
|
||||||
add_subdirectory(LibSystem)
|
add_subdirectory(LibSystem)
|
||||||
add_subdirectory(LibTar)
|
add_subdirectory(LibTar)
|
||||||
add_subdirectory(LibTextCodec)
|
add_subdirectory(LibTextCodec)
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
namespace Cpp {
|
namespace Cpp {
|
||||||
|
|
||||||
static GUI::TextStyle style_for_token_type(const Gfx::Palette& palette, Cpp::Token::Type type)
|
static Syntax::TextStyle style_for_token_type(const Gfx::Palette& palette, Cpp::Token::Type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Cpp::Token::Type::Keyword:
|
case Cpp::Token::Type::Keyword:
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace Cpp {
|
namespace Cpp {
|
||||||
|
|
||||||
class SyntaxHighlighter final : public GUI::SyntaxHighlighter {
|
class SyntaxHighlighter final : public Syntax::Highlighter {
|
||||||
public:
|
public:
|
||||||
SyntaxHighlighter() { }
|
SyntaxHighlighter() { }
|
||||||
virtual ~SyntaxHighlighter() override;
|
virtual ~SyntaxHighlighter() override;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
virtual bool is_identifier(void*) const override;
|
virtual bool is_identifier(void*) const override;
|
||||||
virtual bool is_navigatable(void*) const override;
|
virtual bool is_navigatable(void*) const override;
|
||||||
|
|
||||||
virtual GUI::SyntaxLanguage language() const override { return GUI::SyntaxLanguage::Cpp; }
|
virtual Syntax::Language language() const override { return Syntax::Language::Cpp; }
|
||||||
virtual void rehighlight(Gfx::Palette) override;
|
virtual void rehighlight(Gfx::Palette) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -83,7 +83,6 @@ set(SOURCES
|
||||||
Splitter.cpp
|
Splitter.cpp
|
||||||
StackWidget.cpp
|
StackWidget.cpp
|
||||||
StatusBar.cpp
|
StatusBar.cpp
|
||||||
SyntaxHighlighter.cpp
|
|
||||||
TabWidget.cpp
|
TabWidget.cpp
|
||||||
TableView.cpp
|
TableView.cpp
|
||||||
TextBox.cpp
|
TextBox.cpp
|
||||||
|
@ -110,4 +109,4 @@ set(GENERATED_SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibGUI gui)
|
serenity_lib(LibGUI gui)
|
||||||
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibShell LibRegex LibJS)
|
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibShell LibRegex LibJS LibSyntax)
|
||||||
|
|
|
@ -77,7 +77,6 @@ class SpinBox;
|
||||||
class Splitter;
|
class Splitter;
|
||||||
class StackWidget;
|
class StackWidget;
|
||||||
class StatusBar;
|
class StatusBar;
|
||||||
class SyntaxHighlighter;
|
|
||||||
class TabWidget;
|
class TabWidget;
|
||||||
class TableView;
|
class TableView;
|
||||||
class TextBox;
|
class TextBox;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
static TextStyle style_for_token_type(Gfx::Palette palette, GMLToken::Type type)
|
static Syntax::TextStyle style_for_token_type(Gfx::Palette palette, GMLToken::Type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GMLToken::Type::LeftCurly:
|
case GMLToken::Type::LeftCurly:
|
||||||
|
@ -88,7 +88,7 @@ void GMLSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||||
|
|
||||||
Vector<GMLSyntaxHighlighter::MatchingTokenPair> GMLSyntaxHighlighter::matching_token_pairs() const
|
Vector<GMLSyntaxHighlighter::MatchingTokenPair> GMLSyntaxHighlighter::matching_token_pairs() const
|
||||||
{
|
{
|
||||||
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
|
static Vector<MatchingTokenPair> pairs;
|
||||||
if (pairs.is_empty()) {
|
if (pairs.is_empty()) {
|
||||||
pairs.append({ reinterpret_cast<void*>(GMLToken::Type::LeftCurly), reinterpret_cast<void*>(GMLToken::Type::RightCurly) });
|
pairs.append({ reinterpret_cast<void*>(GMLToken::Type::LeftCurly), reinterpret_cast<void*>(GMLToken::Type::RightCurly) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -26,18 +26,18 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class GMLSyntaxHighlighter final : public SyntaxHighlighter {
|
class GMLSyntaxHighlighter final : public Syntax::Highlighter {
|
||||||
public:
|
public:
|
||||||
GMLSyntaxHighlighter() { }
|
GMLSyntaxHighlighter() { }
|
||||||
virtual ~GMLSyntaxHighlighter() override;
|
virtual ~GMLSyntaxHighlighter() override;
|
||||||
|
|
||||||
virtual bool is_identifier(void*) const override;
|
virtual bool is_identifier(void*) const override;
|
||||||
|
|
||||||
virtual SyntaxLanguage language() const override { return SyntaxLanguage::INI; }
|
virtual Syntax::Language language() const override { return Syntax::Language::GML; }
|
||||||
virtual void rehighlight(Gfx::Palette) override;
|
virtual void rehighlight(Gfx::Palette) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
static TextStyle style_for_token_type(Gfx::Palette palette, IniToken::Type type)
|
static Syntax::TextStyle style_for_token_type(const Gfx::Palette& palette, IniToken::Type type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case IniToken::Type::LeftBracket:
|
case IniToken::Type::LeftBracket:
|
||||||
|
@ -87,7 +87,7 @@ void IniSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||||
|
|
||||||
Vector<IniSyntaxHighlighter::MatchingTokenPair> IniSyntaxHighlighter::matching_token_pairs() const
|
Vector<IniSyntaxHighlighter::MatchingTokenPair> IniSyntaxHighlighter::matching_token_pairs() const
|
||||||
{
|
{
|
||||||
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
|
static Vector<MatchingTokenPair> pairs;
|
||||||
if (pairs.is_empty()) {
|
if (pairs.is_empty()) {
|
||||||
pairs.append({ reinterpret_cast<void*>(IniToken::Type::LeftBracket), reinterpret_cast<void*>(IniToken::Type::RightBracket) });
|
pairs.append({ reinterpret_cast<void*>(IniToken::Type::LeftBracket), reinterpret_cast<void*>(IniToken::Type::RightBracket) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,18 +26,18 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class IniSyntaxHighlighter final : public SyntaxHighlighter {
|
class IniSyntaxHighlighter final : public Syntax::Highlighter {
|
||||||
public:
|
public:
|
||||||
IniSyntaxHighlighter() { }
|
IniSyntaxHighlighter() { }
|
||||||
virtual ~IniSyntaxHighlighter() override;
|
virtual ~IniSyntaxHighlighter() override;
|
||||||
|
|
||||||
virtual bool is_identifier(void*) const override;
|
virtual bool is_identifier(void*) const override;
|
||||||
|
|
||||||
virtual SyntaxLanguage language() const override { return SyntaxLanguage::INI; }
|
virtual Syntax::Language language() const override { return Syntax::Language::INI; }
|
||||||
virtual void rehighlight(Gfx::Palette) override;
|
virtual void rehighlight(Gfx::Palette) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
static TextStyle style_for_token_type(Gfx::Palette palette, JS::TokenType type)
|
static Syntax::TextStyle style_for_token_type(Gfx::Palette palette, JS::TokenType type)
|
||||||
{
|
{
|
||||||
switch (JS::Token::category(type)) {
|
switch (JS::Token::category(type)) {
|
||||||
case JS::TokenCategory::Invalid:
|
case JS::TokenCategory::Invalid:
|
||||||
|
@ -133,9 +133,9 @@ void JSSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<SyntaxHighlighter::MatchingTokenPair> JSSyntaxHighlighter::matching_token_pairs() const
|
Vector<Syntax::Highlighter::MatchingTokenPair> JSSyntaxHighlighter::matching_token_pairs() const
|
||||||
{
|
{
|
||||||
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
|
static Vector<Syntax::Highlighter::MatchingTokenPair> pairs;
|
||||||
if (pairs.is_empty()) {
|
if (pairs.is_empty()) {
|
||||||
pairs.append({ reinterpret_cast<void*>(JS::TokenType::CurlyOpen), reinterpret_cast<void*>(JS::TokenType::CurlyClose) });
|
pairs.append({ reinterpret_cast<void*>(JS::TokenType::CurlyOpen), reinterpret_cast<void*>(JS::TokenType::CurlyClose) });
|
||||||
pairs.append({ reinterpret_cast<void*>(JS::TokenType::ParenOpen), reinterpret_cast<void*>(JS::TokenType::ParenClose) });
|
pairs.append({ reinterpret_cast<void*>(JS::TokenType::ParenOpen), reinterpret_cast<void*>(JS::TokenType::ParenClose) });
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class JSSyntaxHighlighter : public SyntaxHighlighter {
|
class JSSyntaxHighlighter : public Syntax::Highlighter {
|
||||||
public:
|
public:
|
||||||
JSSyntaxHighlighter() { }
|
JSSyntaxHighlighter() { }
|
||||||
virtual ~JSSyntaxHighlighter() override;
|
virtual ~JSSyntaxHighlighter() override;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
virtual bool is_identifier(void*) const override;
|
virtual bool is_identifier(void*) const override;
|
||||||
virtual bool is_navigatable(void*) const override;
|
virtual bool is_navigatable(void*) const override;
|
||||||
|
|
||||||
virtual SyntaxLanguage language() const override { return SyntaxLanguage::JavaScript; }
|
virtual Syntax::Language language() const override { return Syntax::Language::JavaScript; }
|
||||||
virtual void rehighlight(Gfx::Palette) override;
|
virtual void rehighlight(Gfx::Palette) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -523,9 +523,9 @@ void ShellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<SyntaxHighlighter::MatchingTokenPair> ShellSyntaxHighlighter::matching_token_pairs() const
|
Vector<Syntax::Highlighter::MatchingTokenPair> ShellSyntaxHighlighter::matching_token_pairs() const
|
||||||
{
|
{
|
||||||
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
|
static Vector<Syntax::Highlighter::MatchingTokenPair> pairs;
|
||||||
if (pairs.is_empty()) {
|
if (pairs.is_empty()) {
|
||||||
pairs.append({
|
pairs.append({
|
||||||
(void*)static_cast<size_t>(AugmentedTokenKind::OpenParen),
|
(void*)static_cast<size_t>(AugmentedTokenKind::OpenParen),
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
class ShellSyntaxHighlighter : public SyntaxHighlighter {
|
class ShellSyntaxHighlighter : public Syntax::Highlighter {
|
||||||
public:
|
public:
|
||||||
ShellSyntaxHighlighter() { }
|
ShellSyntaxHighlighter() { }
|
||||||
virtual ~ShellSyntaxHighlighter() override;
|
virtual ~ShellSyntaxHighlighter() override;
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
virtual bool is_identifier(void*) const override;
|
virtual bool is_identifier(void*) const override;
|
||||||
virtual bool is_navigatable(void*) const override;
|
virtual bool is_navigatable(void*) const override;
|
||||||
|
|
||||||
virtual SyntaxLanguage language() const override { return SyntaxLanguage::Shell; }
|
virtual Syntax::Language language() const override { return Syntax::Language::Shell; }
|
||||||
virtual void rehighlight(Gfx::Palette) override;
|
virtual void rehighlight(Gfx::Palette) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -38,13 +38,13 @@
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGUI/RegularEditingEngine.h>
|
#include <LibGUI/RegularEditingEngine.h>
|
||||||
#include <LibGUI/ScrollBar.h>
|
#include <LibGUI/ScrollBar.h>
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
|
||||||
#include <LibGUI/TextEditor.h>
|
#include <LibGUI/TextEditor.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Font.h>
|
#include <LibGfx/Font.h>
|
||||||
#include <LibGfx/FontDatabase.h>
|
#include <LibGfx/FontDatabase.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
#include <LibSyntax/Highlighter.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -1586,12 +1586,12 @@ void TextEditor::flush_pending_change_notification_if_needed()
|
||||||
m_has_pending_change_notification = false;
|
m_has_pending_change_notification = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SyntaxHighlighter* TextEditor::syntax_highlighter() const
|
const Syntax::Highlighter* TextEditor::syntax_highlighter() const
|
||||||
{
|
{
|
||||||
return m_highlighter.ptr();
|
return m_highlighter.ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditor::set_syntax_highlighter(OwnPtr<SyntaxHighlighter> highlighter)
|
void TextEditor::set_syntax_highlighter(OwnPtr<Syntax::Highlighter> highlighter)
|
||||||
{
|
{
|
||||||
if (m_highlighter)
|
if (m_highlighter)
|
||||||
m_highlighter->detach();
|
m_highlighter->detach();
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <LibGUI/TextDocument.h>
|
#include <LibGUI/TextDocument.h>
|
||||||
#include <LibGUI/TextRange.h>
|
#include <LibGUI/TextRange.h>
|
||||||
#include <LibGfx/TextAlignment.h>
|
#include <LibGfx/TextAlignment.h>
|
||||||
|
#include <LibSyntax/Forward.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -173,8 +174,8 @@ public:
|
||||||
void set_cursor(size_t line, size_t column);
|
void set_cursor(size_t line, size_t column);
|
||||||
void set_cursor(const TextPosition&);
|
void set_cursor(const TextPosition&);
|
||||||
|
|
||||||
const SyntaxHighlighter* syntax_highlighter() const;
|
const Syntax::Highlighter* syntax_highlighter() const;
|
||||||
void set_syntax_highlighter(OwnPtr<SyntaxHighlighter>);
|
void set_syntax_highlighter(OwnPtr<Syntax::Highlighter>);
|
||||||
|
|
||||||
const AutocompleteProvider* autocomplete_provider() const;
|
const AutocompleteProvider* autocomplete_provider() const;
|
||||||
void set_autocomplete_provider(OwnPtr<AutocompleteProvider>&&);
|
void set_autocomplete_provider(OwnPtr<AutocompleteProvider>&&);
|
||||||
|
@ -344,7 +345,7 @@ private:
|
||||||
|
|
||||||
NonnullOwnPtrVector<LineVisualData> m_line_visual_data;
|
NonnullOwnPtrVector<LineVisualData> m_line_visual_data;
|
||||||
|
|
||||||
OwnPtr<SyntaxHighlighter> m_highlighter;
|
OwnPtr<Syntax::Highlighter> m_highlighter;
|
||||||
OwnPtr<AutocompleteProvider> m_autocomplete_provider;
|
OwnPtr<AutocompleteProvider> m_autocomplete_provider;
|
||||||
OwnPtr<AutocompleteBox> m_autocomplete_box;
|
OwnPtr<AutocompleteBox> m_autocomplete_box;
|
||||||
bool m_should_keep_autocomplete_box { false };
|
bool m_should_keep_autocomplete_box { false };
|
||||||
|
|
6
Userland/Libraries/LibSyntax/CMakeLists.txt
Normal file
6
Userland/Libraries/LibSyntax/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
set(SOURCES
|
||||||
|
Highlighter.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
serenity_lib(LibSyntax syntax)
|
||||||
|
target_link_libraries(LibSyntax LibC)
|
33
Userland/Libraries/LibSyntax/Forward.h
Normal file
33
Userland/Libraries/LibSyntax/Forward.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Syntax {
|
||||||
|
|
||||||
|
class Highlighter;
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -24,16 +24,16 @@
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibGUI/SyntaxHighlighter.h>
|
|
||||||
#include <LibGUI/TextEditor.h>
|
#include <LibGUI/TextEditor.h>
|
||||||
|
#include <LibSyntax/Highlighter.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace Syntax {
|
||||||
|
|
||||||
SyntaxHighlighter::~SyntaxHighlighter()
|
Highlighter::~Highlighter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::highlight_matching_token_pair()
|
void Highlighter::highlight_matching_token_pair()
|
||||||
{
|
{
|
||||||
ASSERT(m_editor);
|
ASSERT(m_editor);
|
||||||
auto& document = m_editor->document();
|
auto& document = m_editor->document();
|
||||||
|
@ -125,19 +125,19 @@ void SyntaxHighlighter::highlight_matching_token_pair()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::attach(TextEditor& editor)
|
void Highlighter::attach(GUI::TextEditor& editor)
|
||||||
{
|
{
|
||||||
ASSERT(!m_editor);
|
ASSERT(!m_editor);
|
||||||
m_editor = editor;
|
m_editor = editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::detach()
|
void Highlighter::detach()
|
||||||
{
|
{
|
||||||
ASSERT(m_editor);
|
ASSERT(m_editor);
|
||||||
m_editor = nullptr;
|
m_editor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::cursor_did_change()
|
void Highlighter::cursor_did_change()
|
||||||
{
|
{
|
||||||
ASSERT(m_editor);
|
ASSERT(m_editor);
|
||||||
auto& document = m_editor->document();
|
auto& document = m_editor->document();
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -31,43 +31,44 @@
|
||||||
#include <LibGUI/TextDocument.h>
|
#include <LibGUI/TextDocument.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
namespace GUI {
|
namespace Syntax {
|
||||||
|
|
||||||
enum class SyntaxLanguage {
|
enum class Language {
|
||||||
PlainText,
|
PlainText,
|
||||||
Cpp,
|
Cpp,
|
||||||
JavaScript,
|
JavaScript,
|
||||||
INI,
|
INI,
|
||||||
|
GML,
|
||||||
Shell,
|
Shell,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextStyle {
|
struct TextStyle {
|
||||||
const Color color;
|
const Gfx::Color color;
|
||||||
const bool bold { false };
|
const bool bold { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class SyntaxHighlighter {
|
class Highlighter {
|
||||||
AK_MAKE_NONCOPYABLE(SyntaxHighlighter);
|
AK_MAKE_NONCOPYABLE(Highlighter);
|
||||||
AK_MAKE_NONMOVABLE(SyntaxHighlighter);
|
AK_MAKE_NONMOVABLE(Highlighter);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~SyntaxHighlighter();
|
virtual ~Highlighter();
|
||||||
|
|
||||||
virtual SyntaxLanguage language() const = 0;
|
virtual Language language() const = 0;
|
||||||
virtual void rehighlight(Gfx::Palette) = 0;
|
virtual void rehighlight(Gfx::Palette) = 0;
|
||||||
virtual void highlight_matching_token_pair();
|
virtual void highlight_matching_token_pair();
|
||||||
|
|
||||||
virtual bool is_identifier(void*) const { return false; };
|
virtual bool is_identifier(void*) const { return false; };
|
||||||
virtual bool is_navigatable(void*) const { return false; };
|
virtual bool is_navigatable(void*) const { return false; };
|
||||||
|
|
||||||
void attach(TextEditor& editor);
|
void attach(GUI::TextEditor& editor);
|
||||||
void detach();
|
void detach();
|
||||||
void cursor_did_change();
|
void cursor_did_change();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SyntaxHighlighter() { }
|
Highlighter() { }
|
||||||
|
|
||||||
WeakPtr<TextEditor> m_editor;
|
WeakPtr<GUI::TextEditor> m_editor;
|
||||||
|
|
||||||
struct MatchingTokenPair {
|
struct MatchingTokenPair {
|
||||||
void* open;
|
void* open;
|
Loading…
Add table
Add a link
Reference in a new issue