1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 18:57:36 +00:00

LibGUI+LibCpp: Move C++ syntax highlighter to LibCpp

This makes LibGUI not depend on LibCpp.
This commit is contained in:
Andreas Kling 2021-02-07 14:40:36 +01:00
parent b1f1f5afcf
commit ff2438e0ce
9 changed files with 23 additions and 23 deletions

View file

@ -2,6 +2,7 @@ set(SOURCES
AST.cpp
Lexer.cpp
Parser.cpp
SyntaxHighlighter.cpp
)
serenity_lib(LibCpp cpp)

View file

@ -26,14 +26,14 @@
#include <AK/Debug.h>
#include <LibCpp/Lexer.h>
#include <LibGUI/CppSyntaxHighlighter.h>
#include <LibCpp/SyntaxHighlighter.h>
#include <LibGUI/TextEditor.h>
#include <LibGfx/Font.h>
#include <LibGfx/Palette.h>
namespace GUI {
namespace Cpp {
static TextStyle style_for_token_type(Gfx::Palette palette, Cpp::Token::Type type)
static GUI::TextStyle style_for_token_type(const Gfx::Palette& palette, Cpp::Token::Type type)
{
switch (type) {
case Cpp::Token::Type::Keyword:
@ -63,19 +63,19 @@ static TextStyle style_for_token_type(Gfx::Palette palette, Cpp::Token::Type typ
}
}
bool CppSyntaxHighlighter::is_identifier(void* token) const
bool SyntaxHighlighter::is_identifier(void* token) const
{
auto cpp_token = static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token));
return cpp_token == Cpp::Token::Type::Identifier;
}
bool CppSyntaxHighlighter::is_navigatable(void* token) const
bool SyntaxHighlighter::is_navigatable(void* token) const
{
auto cpp_token = static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token));
return cpp_token == Cpp::Token::Type::IncludePath;
}
void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
void SyntaxHighlighter::rehighlight(Gfx::Palette palette)
{
ASSERT(m_editor);
auto text = m_editor->text();
@ -103,7 +103,7 @@ void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
m_editor->update();
}
Vector<SyntaxHighlighter::MatchingTokenPair> CppSyntaxHighlighter::matching_token_pairs() const
Vector<SyntaxHighlighter::MatchingTokenPair> SyntaxHighlighter::matching_token_pairs() const
{
static Vector<SyntaxHighlighter::MatchingTokenPair> pairs;
if (pairs.is_empty()) {
@ -114,12 +114,12 @@ Vector<SyntaxHighlighter::MatchingTokenPair> CppSyntaxHighlighter::matching_toke
return pairs;
}
bool CppSyntaxHighlighter::token_types_equal(void* token1, void* token2) const
bool SyntaxHighlighter::token_types_equal(void* token1, void* token2) const
{
return static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token1)) == static_cast<Cpp::Token::Type>(reinterpret_cast<size_t>(token2));
}
CppSyntaxHighlighter::~CppSyntaxHighlighter()
SyntaxHighlighter::~SyntaxHighlighter()
{
}

View file

@ -28,17 +28,17 @@
#include <LibGUI/SyntaxHighlighter.h>
namespace GUI {
namespace Cpp {
class CppSyntaxHighlighter final : public SyntaxHighlighter {
class SyntaxHighlighter final : public GUI::SyntaxHighlighter {
public:
CppSyntaxHighlighter() { }
virtual ~CppSyntaxHighlighter() override;
SyntaxHighlighter() { }
virtual ~SyntaxHighlighter() override;
virtual bool is_identifier(void*) const override;
virtual bool is_navigatable(void*) const override;
virtual SyntaxLanguage language() const override { return SyntaxLanguage::Cpp; }
virtual GUI::SyntaxLanguage language() const override { return GUI::SyntaxLanguage::Cpp; }
virtual void rehighlight(Gfx::Palette) override;
protected:

View file

@ -22,7 +22,6 @@ set(SOURCES
ComboBox.cpp
Command.cpp
ControlBoxButton.cpp
CppSyntaxHighlighter.cpp
Desktop.cpp
Dialog.cpp
DisplayLink.cpp
@ -111,4 +110,4 @@ set(GENERATED_SOURCES
)
serenity_lib(LibGUI gui)
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibCpp LibShell LibRegex LibJS)
target_link_libraries(LibGUI LibCore LibGfx LibIPC LibThread LibShell LibRegex LibJS)