105 lines
2.9 KiB
C
105 lines
2.9 KiB
C
#ifndef HL_H_
|
|
|
|
#include <stdio.h>
|
|
#include <uthash.h>
|
|
#include <ctype.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include "chad.h"
|
|
#include "regex.h"
|
|
|
|
// -------------------
|
|
// ### Definitions ###
|
|
// -------------------
|
|
|
|
typedef enum {
|
|
KEYSYMBOL,
|
|
KEYWORD,
|
|
MATCH,
|
|
REGION
|
|
} token_type_t;
|
|
|
|
typedef void (*attribute_callback_t) (const char * string,
|
|
const int length,
|
|
void * attributes);
|
|
|
|
typedef struct {
|
|
char * key;
|
|
attribute_callback_t callback;
|
|
UT_hash_handle hh;
|
|
} display_t;
|
|
|
|
typedef struct {
|
|
void * attributes;
|
|
struct hl_group_t * link;
|
|
} hl_group_t;
|
|
|
|
typedef struct {
|
|
hl_group_t * hl;
|
|
regex_t * syntax;
|
|
token_type_t t;
|
|
char _pad[4];
|
|
} token_t;
|
|
|
|
extern vector_t token_table;
|
|
extern display_t * display_table;
|
|
|
|
extern hl_group_t * keyword_hl;
|
|
extern hl_group_t * preprocessor_hl;
|
|
extern hl_group_t * symbol_hl;
|
|
|
|
extern hl_group_t * special_hl;
|
|
extern hl_group_t * control_hl;
|
|
extern hl_group_t * keyword_hl;
|
|
extern hl_group_t * block_hl;
|
|
extern hl_group_t * separator_hl;
|
|
extern hl_group_t * operator_hl;
|
|
extern hl_group_t * comment_hl;
|
|
extern hl_group_t * string_literal_hl;
|
|
|
|
extern void new_display_mode(display_t * mode);
|
|
extern int free_token(token_t * token);
|
|
extern int append_token(token_t * token);
|
|
|
|
// TODO: ALIGN PROPERLY...
|
|
|
|
extern token_t * new_symbol_token(const char * const c,
|
|
hl_group_t * const g);
|
|
|
|
extern int new_symbol_tokens(const char * const * symbols,
|
|
hl_group_t * const g);
|
|
|
|
extern int new_char_tokens(const char * str,
|
|
hl_group_t * const g);
|
|
|
|
extern token_t * new_keyword_token(const char * const word,
|
|
hl_group_t * const g);
|
|
|
|
extern int new_keyword_tokens(const char * const * words,
|
|
hl_group_t * const g);
|
|
|
|
extern token_t * new_token(const char * const word,
|
|
const token_type_t t,
|
|
hl_group_t * const g);
|
|
|
|
extern token_t * new_region_token(const char * start,
|
|
const char * end,
|
|
hl_group_t * g);
|
|
|
|
// TODO: ALIGN PROPERLY...
|
|
|
|
extern int token_fits(const token_t * const token,
|
|
const char * const to,
|
|
const int string_offset,
|
|
const bool is_start_of_line,
|
|
int * match_offset);
|
|
|
|
extern void render_string(const char * const string,
|
|
const char * const mode);
|
|
|
|
extern int hl_init(void);
|
|
extern int hl_deinit(void);
|
|
|
|
#define HL_H_
|
|
#endif
|