1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

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
6 changed files with 24 additions and 26 deletions

View file

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

View file

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

View file

@ -74,7 +74,6 @@ set(SOURCES
ScrollBar.cpp ScrollBar.cpp
ScrollableWidget.cpp ScrollableWidget.cpp
SeparatorWidget.cpp SeparatorWidget.cpp
ShellSyntaxHighlighter.cpp
Shortcut.cpp Shortcut.cpp
Slider.cpp Slider.cpp
SortingProxyModel.cpp SortingProxyModel.cpp
@ -108,4 +107,4 @@ set(GENERATED_SOURCES
) )
serenity_lib(LibGUI gui) 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 NodeVisitor.cpp
Parser.cpp Parser.cpp
Shell.cpp Shell.cpp
SyntaxHighlighter.cpp
) )
serenity_lib(LibShell shell) serenity_lib(LibShell shell)
target_link_libraries(LibShell LibCore LibLine) target_link_libraries(LibShell LibCore LibLine LibSyntax)
set(SOURCES set(SOURCES
main.cpp main.cpp

View file

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

View file

@ -28,12 +28,12 @@
#include <LibSyntax/Highlighter.h> #include <LibSyntax/Highlighter.h>
namespace GUI { namespace Shell {
class ShellSyntaxHighlighter : public Syntax::Highlighter { class SyntaxHighlighter : public Syntax::Highlighter {
public: public:
ShellSyntaxHighlighter() { } SyntaxHighlighter() { }
virtual ~ShellSyntaxHighlighter() override; virtual ~SyntaxHighlighter() override;
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;