Shell: Move Shell syntax highlighter LibShell

This commit is contained in:
Andreas Kling 2021-02-07 17:07:33 +01:00
parent ddbf20ecf6
commit 50308f6fda
Notes: sideshowbarker 2024-07-18 22:32:23 +09:00
6 changed files with 24 additions and 26 deletions

View File

@ -47,7 +47,6 @@
#include <LibGUI/MenuBar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/RegularEditingEngine.h>
#include <LibGUI/ShellSyntaxHighlighter.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/StatusBar.h>
#include <LibGUI/TextBox.h>
@ -59,6 +58,7 @@
#include <LibJS/SyntaxHighlighter.h>
#include <LibMarkdown/Document.h>
#include <LibWeb/OutOfProcessWebView.h>
#include <Shell/SyntaxHighlighter.h>
#include <string.h>
TextEditorWidget::TextEditorWidget()
@ -497,7 +497,7 @@ TextEditorWidget::TextEditorWidget()
syntax_menu.add_action(*m_ini_highlight);
m_shell_highlight = GUI::Action::create_checkable("Shell File", [&](auto&) {
m_editor->set_syntax_highlighter(make<GUI::ShellSyntaxHighlighter>());
m_editor->set_syntax_highlighter(make<Shell::SyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_shell_highlight);

View File

@ -41,7 +41,6 @@
#include <LibGUI/Label.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h>
#include <LibGUI/ShellSyntaxHighlighter.h>
#include <LibGUI/Window.h>
#include <LibJS/SyntaxHighlighter.h>
#include <LibMarkdown/Document.h>
@ -49,6 +48,7 @@
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/HTMLHeadElement.h>
#include <LibWeb/OutOfProcessWebView.h>
#include <Shell/SyntaxHighlighter.h>
#include <fcntl.h>
namespace HackStudio {
@ -430,7 +430,7 @@ void Editor::set_document(GUI::TextDocument& doc)
set_syntax_highlighter(make<GUI::IniSyntaxHighlighter>());
break;
case Language::Shell:
set_syntax_highlighter(make<GUI::ShellSyntaxHighlighter>());
set_syntax_highlighter(make<Shell::SyntaxHighlighter>());
m_language_client = get_language_client<LanguageClients::Shell::ServerConnection>(project().root_path());
break;
default:

View File

@ -74,7 +74,6 @@ set(SOURCES
ScrollBar.cpp
ScrollableWidget.cpp
SeparatorWidget.cpp
ShellSyntaxHighlighter.cpp
Shortcut.cpp
Slider.cpp
SortingProxyModel.cpp
@ -108,4 +107,4 @@ set(GENERATED_SOURCES
)
serenity_lib(LibGUI gui)
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibShell LibRegex LibSyntax)
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibRegex LibSyntax)

View File

@ -6,10 +6,11 @@ set(SOURCES
NodeVisitor.cpp
Parser.cpp
Shell.cpp
SyntaxHighlighter.cpp
)
serenity_lib(LibShell shell)
target_link_libraries(LibShell LibCore LibLine)
target_link_libraries(LibShell LibCore LibLine LibSyntax)
set(SOURCES
main.cpp

View File

@ -25,16 +25,14 @@
*/
#include <AK/TemporaryChange.h>
#include <LibGUI/ShellSyntaxHighlighter.h>
#include <LibGUI/TextEditor.h>
#include <LibGfx/Font.h>
#include <LibGfx/Palette.h>
#include <Shell/NodeVisitor.h>
#include <Shell/Parser.h>
#include <Shell/SyntaxHighlighter.h>
namespace GUI {
using namespace Shell;
namespace Shell {
enum class AugmentedTokenKind : u32 {
__TokenTypeCount = (u32)AST::Node::Kind::__Count,
@ -44,7 +42,7 @@ enum class AugmentedTokenKind : u32 {
class HighlightVisitor : public AST::NodeVisitor {
public:
HighlightVisitor(Vector<GUI::TextDocumentSpan>& spans, const Gfx::Palette& palette, const TextDocument& document)
HighlightVisitor(Vector<GUI::TextDocumentSpan>& spans, const Gfx::Palette& palette, const GUI::TextDocument& document)
: m_spans(spans)
, m_palette(palette)
, m_document(document)
@ -77,12 +75,12 @@ private:
return new_line;
}
void set_offset_range_end(TextRange& range, const AST::Position::Line& line, size_t offset = 1)
void set_offset_range_end(GUI::TextRange& range, const AST::Position::Line& line, size_t offset = 1)
{
auto new_line = offset_line(line, offset);
range.set_end({ new_line.line_number, new_line.line_column });
}
void set_offset_range_start(TextRange& range, const AST::Position::Line& line, size_t offset = 1)
void set_offset_range_start(GUI::TextRange& range, const AST::Position::Line& line, size_t offset = 1)
{
auto new_line = offset_line(line, offset);
range.set_start({ new_line.line_number, new_line.line_column });
@ -476,11 +474,11 @@ private:
Vector<GUI::TextDocumentSpan>& m_spans;
const Gfx::Palette& m_palette;
const TextDocument& m_document;
const GUI::TextDocument& m_document;
bool m_is_first_in_command { false };
};
bool ShellSyntaxHighlighter::is_identifier(void* token) const
bool SyntaxHighlighter::is_identifier(void* token) const
{
if (!token)
return false;
@ -491,7 +489,7 @@ bool ShellSyntaxHighlighter::is_identifier(void* token) const
|| kind == (size_t)AST::Node::Kind::Tilde;
}
bool ShellSyntaxHighlighter::is_navigatable(void* token) const
bool SyntaxHighlighter::is_navigatable(void* token) const
{
if (!token)
return false;
@ -500,7 +498,7 @@ bool ShellSyntaxHighlighter::is_navigatable(void* token) const
return (size_t)kind == (size_t)AST::Node::Kind::BarewordLiteral;
}
void ShellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
void SyntaxHighlighter::rehighlight(Gfx::Palette palette)
{
auto text = m_client->get_text();
@ -522,9 +520,9 @@ void ShellSyntaxHighlighter::rehighlight(Gfx::Palette palette)
m_client->do_update();
}
Vector<Syntax::Highlighter::MatchingTokenPair> ShellSyntaxHighlighter::matching_token_pairs() const
Vector<Syntax::Highlighter::MatchingTokenPair> SyntaxHighlighter::matching_token_pairs() const
{
static Vector<Syntax::Highlighter::MatchingTokenPair> pairs;
static Vector<MatchingTokenPair> pairs;
if (pairs.is_empty()) {
pairs.append({
(void*)static_cast<size_t>(AugmentedTokenKind::OpenParen),
@ -534,12 +532,12 @@ Vector<Syntax::Highlighter::MatchingTokenPair> ShellSyntaxHighlighter::matching_
return pairs;
}
bool ShellSyntaxHighlighter::token_types_equal(void* token0, void* token1) const
bool SyntaxHighlighter::token_types_equal(void* token0, void* token1) const
{
return token0 == token1;
}
ShellSyntaxHighlighter::~ShellSyntaxHighlighter()
SyntaxHighlighter::~SyntaxHighlighter()
{
}

View File

@ -28,12 +28,12 @@
#include <LibSyntax/Highlighter.h>
namespace GUI {
namespace Shell {
class ShellSyntaxHighlighter : public Syntax::Highlighter {
class SyntaxHighlighter : public Syntax::Highlighter {
public:
ShellSyntaxHighlighter() { }
virtual ~ShellSyntaxHighlighter() override;
SyntaxHighlighter() { }
virtual ~SyntaxHighlighter() override;
virtual bool is_identifier(void*) const override;
virtual bool is_navigatable(void*) const override;