| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <QSyntaxHighlighter> |
| 7 |
#include <QTextCharFormat> |
| 8 |
|
| 9 |
#include <optional> |
| 10 |
|
| 11 |
#include "Common/Assembler/AssemblerShared.h" |
| 12 |
|
| 13 |
enum class HighlightFormat |
| 14 |
{ |
| 15 |
Directive, |
| 16 |
Mnemonic, |
| 17 |
Symbol, |
| 18 |
Immediate, |
| 19 |
GPR, |
| 20 |
FPR, |
| 21 |
SPR, |
| 22 |
CRField, |
| 23 |
CRFlag, |
| 24 |
Str, |
| 25 |
HaLa, |
| 26 |
Paren, |
| 27 |
Default, |
| 28 |
Comment, |
| 29 |
Error, |
| 30 |
}; |
| 31 |
|
| 32 |
struct BlockInfo : public QTextBlockUserData |
| 33 |
{ |
| 34 |
std::vector<std::tuple<int, int, HighlightFormat>> block_format; |
| 35 |
std::vector<std::pair<int, int>> parens; |
| 36 |
std::optional<Common::GekkoAssembler::AssemblerError> error; |
| 37 |
bool error_at_eol = false; |
| 38 |
}; |
| 39 |
|
| 40 |
class GekkoSyntaxHighlight : public QSyntaxHighlighter |
| 41 |
{ |
| 42 |
Q_OBJECT; |
| 43 |
|
| 44 |
public: |
| 45 |
explicit GekkoSyntaxHighlight(QTextDocument* document, QTextCharFormat base_format, |
| 46 |
bool dark_scheme); |
| 47 |
|
| 48 |
void HighlightSubstr(int start, int len, HighlightFormat format); |
| 49 |
void SetMode(int mode) { m_mode = mode; } |
| 50 |
void SetCursorLoc(int loc) { m_cursor_loc = loc; } |
| 51 |
|
| 52 |
protected: |
| 53 |
void highlightBlock(const QString& line) override; |
| 54 |
|
| 55 |
private: |
| 56 |
int m_mode = 0; |
| 57 |
int m_cursor_loc = 0; |
| 58 |
QTextCharFormat m_base_format; |
| 59 |
int m_theme_idx = 0; |
| 60 |
}; |