2020-03-14 00:07:44 +02:00
|
|
|
/*
|
2021-02-07 15:15:10 +01:00
|
|
|
* Copyright (c) 2020-2021, the SerenityOS developers.
|
2020-03-14 00:07:44 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-14 00:07:44 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-02-07 20:07:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
|
#include <AK/WeakPtr.h>
|
|
|
|
|
#include <LibGUI/TextDocument.h>
|
2020-03-16 01:05:06 +02:00
|
|
|
#include <LibGfx/Palette.h>
|
2021-02-07 16:56:02 +01:00
|
|
|
#include <LibSyntax/HighlighterClient.h>
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2021-02-07 15:15:10 +01:00
|
|
|
namespace Syntax {
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2021-02-07 15:15:10 +01:00
|
|
|
enum class Language {
|
2020-03-13 00:51:02 +02:00
|
|
|
Cpp,
|
2021-02-07 15:15:10 +01:00
|
|
|
GML,
|
2021-05-20 23:15:33 +04:30
|
|
|
HTML,
|
|
|
|
|
INI,
|
|
|
|
|
JavaScript,
|
|
|
|
|
PlainText,
|
2021-05-08 18:30:18 -07:00
|
|
|
SQL,
|
2021-05-20 23:15:33 +04:30
|
|
|
Shell,
|
2020-03-13 00:51:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct TextStyle {
|
2021-02-07 15:15:10 +01:00
|
|
|
const Gfx::Color color;
|
2020-12-28 15:51:43 +01:00
|
|
|
const bool bold { false };
|
2020-03-12 16:36:25 +02:00
|
|
|
};
|
|
|
|
|
|
2021-02-07 15:15:10 +01:00
|
|
|
class Highlighter {
|
|
|
|
|
AK_MAKE_NONCOPYABLE(Highlighter);
|
|
|
|
|
AK_MAKE_NONMOVABLE(Highlighter);
|
2020-02-07 20:07:15 +01:00
|
|
|
|
|
|
|
|
public:
|
2021-02-07 15:15:10 +01:00
|
|
|
virtual ~Highlighter();
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2021-02-07 15:15:10 +01:00
|
|
|
virtual Language language() const = 0;
|
2021-02-11 23:52:39 +01:00
|
|
|
virtual void rehighlight(const Palette&) = 0;
|
2020-03-13 00:51:02 +02:00
|
|
|
virtual void highlight_matching_token_pair();
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2020-03-12 17:23:54 +02:00
|
|
|
virtual bool is_identifier(void*) const { return false; };
|
|
|
|
|
virtual bool is_navigatable(void*) const { return false; };
|
|
|
|
|
|
2021-02-07 16:56:02 +01:00
|
|
|
void attach(HighlighterClient&);
|
2020-02-07 20:07:15 +01:00
|
|
|
void detach();
|
|
|
|
|
void cursor_did_change();
|
|
|
|
|
|
|
|
|
|
protected:
|
2021-02-07 15:15:10 +01:00
|
|
|
Highlighter() { }
|
2020-02-07 20:07:15 +01:00
|
|
|
|
2021-02-07 16:56:02 +01:00
|
|
|
// FIXME: This should be WeakPtr somehow
|
|
|
|
|
HighlighterClient* m_client { nullptr };
|
2020-02-07 20:07:15 +01:00
|
|
|
|
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;
|
|
|
|
|
|
2020-02-07 20:07:15 +01:00
|
|
|
struct BuddySpan {
|
|
|
|
|
int index { -1 };
|
|
|
|
|
GUI::TextDocumentSpan span_backup;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool m_has_brace_buddies { false };
|
|
|
|
|
BuddySpan m_brace_buddies[2];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|