ladybird/Libraries/LibGUI/SyntaxHighlighter.h

61 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include <AK/Noncopyable.h>
#include <AK/WeakPtr.h>
#include <LibGUI/TextDocument.h>
namespace GUI {
2020-03-12 16:36:25 +02:00
enum class SyntaxLanguage {
PlainText,
2020-03-13 00:51:02 +02:00
Cpp,
Javascript
};
struct TextStyle {
Color color;
const Gfx::Font* font { nullptr };
2020-03-12 16:36:25 +02:00
};
class SyntaxHighlighter {
AK_MAKE_NONCOPYABLE(SyntaxHighlighter);
AK_MAKE_NONMOVABLE(SyntaxHighlighter);
public:
virtual ~SyntaxHighlighter();
2020-03-12 16:36:25 +02:00
virtual SyntaxLanguage language() const = 0;
virtual void rehighlight() = 0;
2020-03-13 00:51:02 +02:00
virtual void highlight_matching_token_pair();
virtual bool is_identifier(void*) const { return false; };
virtual bool is_navigatable(void*) const { return false; };
void attach(TextEditor& editor);
void detach();
void cursor_did_change();
protected:
SyntaxHighlighter() {}
WeakPtr<TextEditor> m_editor;
2020-03-13 00:51:02 +02:00
struct MatchingTokenPair {
void* open;
void* close;
};
virtual Vector<MatchingTokenPair> matching_token_pairs() const = 0;
virtual bool token_types_equal(void*, void*) const = 0;
struct BuddySpan {
int index { -1 };
GUI::TextDocumentSpan span_backup;
};
bool m_has_brace_buddies { false };
BuddySpan m_brace_buddies[2];
};
}