60 lines
1.2 KiB
C++
60 lines
1.2 KiB
C++
#ifndef SYNTAX_DECL_H
|
|
#define SYNTAX_DECL_H
|
|
|
|
#include "io/knot.h"
|
|
#include "io/sysio.h"
|
|
#include "pch.h"
|
|
#include "syntax/trie.h"
|
|
|
|
#define MAX_LINES_LOOKAROUND 512
|
|
|
|
struct Highlight {
|
|
uint32_t fg{0xFFFFFF};
|
|
uint32_t bg{0x000000};
|
|
uint8_t flags{0};
|
|
};
|
|
|
|
enum struct TokenKind : uint8_t {
|
|
#define ADD(name) name,
|
|
#include "syntax/tokens.def"
|
|
#undef ADD
|
|
Count
|
|
};
|
|
|
|
constexpr size_t TOKEN_KIND_COUNT = static_cast<size_t>(TokenKind::Count);
|
|
|
|
const std::unordered_map<std::string, TokenKind> kind_map = {
|
|
#define ADD(name) {#name, TokenKind::name},
|
|
#include "syntax/tokens.def"
|
|
#undef ADD
|
|
};
|
|
|
|
extern std::array<Highlight, TOKEN_KIND_COUNT> highlights;
|
|
|
|
struct Token {
|
|
uint32_t start;
|
|
uint32_t end;
|
|
TokenKind type;
|
|
};
|
|
|
|
struct StateBase {
|
|
virtual ~StateBase() = default;
|
|
virtual std::unique_ptr<StateBase> clone() const = 0;
|
|
};
|
|
|
|
struct CustomState : StateBase {
|
|
std::string value;
|
|
explicit CustomState(std::string v) : value(std::move(v)) {}
|
|
std::unique_ptr<StateBase> clone() const override {
|
|
return std::make_unique<CustomState>(value);
|
|
}
|
|
};
|
|
|
|
struct LineData {
|
|
std::unique_ptr<StateBase> out_state;
|
|
std::vector<Token> tokens;
|
|
std::unique_ptr<StateBase> in_state;
|
|
};
|
|
|
|
#endif
|