ladybird/Userland/Libraries/LibSyntax/Highlighter.h

75 lines
1.5 KiB
C
Raw Normal View History

2020-03-14 00:07:44 +02:00
/*
* Copyright (c) 2020-2021, the SerenityOS developers.
2020-03-14 00:07:44 +02:00
*
* SPDX-License-Identifier: BSD-2-Clause
2020-03-14 00:07:44 +02:00
*/
#pragma once
#include <AK/Noncopyable.h>
#include <AK/WeakPtr.h>
#include <LibGUI/TextDocument.h>
#include <LibGfx/Palette.h>
#include <LibSyntax/HighlighterClient.h>
namespace Syntax {
enum class Language {
2020-03-13 00:51:02 +02:00
Cpp,
GML,
HTML,
INI,
JavaScript,
PlainText,
2021-05-08 18:30:18 -07:00
SQL,
Shell,
2020-03-13 00:51:02 +02:00
};
struct TextStyle {
const Gfx::Color color;
const bool bold { false };
2020-03-12 16:36:25 +02:00
};
class Highlighter {
AK_MAKE_NONCOPYABLE(Highlighter);
AK_MAKE_NONMOVABLE(Highlighter);
public:
virtual ~Highlighter();
virtual Language language() const = 0;
virtual void rehighlight(const Palette&) = 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(HighlighterClient&);
void detach();
void cursor_did_change();
protected:
Highlighter() { }
// FIXME: This should be WeakPtr somehow
HighlighterClient* m_client { nullptr };
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];
};
}