libhl/src2/Highlight.h
2023-08-16 17:30:29 +02:00

62 lines
842 B
C++

#include <map>
#include <vector>
#include <stdio.h>
typedef enum {
BOLD,
ITALICS,
UNDERLINE,
END
} attr_t;
typedef void (*attr_callback_t)(void);
void bold_on(void){
fputs("\033[1m", stdout);
}
void bold_off(void){
fputs("\033[0m", stdout);
}
attr_callback_t attr_callbacks[END*2] = {
(attr_callback_t)bold_on,
(attr_callback_t)bold_off,
};
typedef int color;
struct hl_t {
attr_t attrs;
color fg_color;
color bg_color;
//? font;
};
struct hl_group {
char* name;
std::map<char*, hl_t> o;
hl_group* link;
};
typedef enum {
KEYWORD,
MATCH,
REGION
} token_t;
struct token{
hl_group* hl;
token_t t;
char* syntax;
};
std::vector<token*> token_table;
token* newtoken(char* syntax, token_t t, hl_group* g){
token* mt = new (token){
.hl = g,
.t = t,
.syntax = syntax
};
token_table.push_back(mt);
return mt;
}