libhl/include/hl.h

106 lines
2.9 KiB
C
Raw Normal View History

2023-08-29 13:09:55 -04:00
#ifndef HL_H_
2023-08-24 06:24:46 -04:00
#include <stdio.h>
#include <uthash.h>
#include <ctype.h>
#include <string.h>
2023-08-28 15:58:20 -04:00
#include <stdbool.h>
#include "chad.h"
2023-09-18 16:43:57 -04:00
#include "vector.h"
#include "jeger.h"
2023-08-21 10:13:24 -04:00
// -------------------
// ### Definitions ###
// -------------------
typedef enum {
KEYSYMBOL,
KEYWORD,
MATCH,
REGION
} token_type_t;
2023-08-28 18:19:40 -04:00
typedef void (*attribute_callback_t) (const char * string,
const int length,
void * attributes);
2023-08-23 21:37:40 -04:00
typedef struct {
2023-08-23 19:58:38 -04:00
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;
2023-08-23 22:11:46 -04:00
regex_t * syntax;
2023-08-27 18:49:36 -04:00
token_type_t t;
char _pad[4];
} token_t;
2023-08-27 18:49:36 -04:00
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;
2023-08-29 13:09:55 -04:00
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;
2023-08-27 18:49:36 -04:00
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);
2023-08-28 18:19:40 -04:00
2023-08-27 18:49:36 -04:00
extern int new_symbol_tokens(const char * const * symbols,
2023-08-28 18:19:40 -04:00
hl_group_t * const g);
extern int new_char_tokens(const char * str,
hl_group_t * const g);
2023-08-27 18:49:36 -04:00
extern token_t * new_keyword_token(const char * const word,
2023-08-28 18:19:40 -04:00
hl_group_t * const g);
2023-08-27 18:49:36 -04:00
extern int new_keyword_tokens(const char * const * words,
2023-09-18 15:34:20 -04:00
hl_group_t * const g);
2023-08-28 18:19:40 -04:00
2023-08-27 18:49:36 -04:00
extern token_t * new_token(const char * const word,
const token_type_t t,
hl_group_t * const g);
2023-08-29 13:09:55 -04:00
extern token_t * new_region_token(const char * start,
const char * end,
hl_group_t * g);
2023-08-27 18:49:36 -04:00
// TODO: ALIGN PROPERLY...
2023-09-18 15:34:20 -04:00
extern int token_fits(const token_t * const token,
const char * const to,
const int string_offset,
2023-08-29 10:23:10 -04:00
const bool is_start_of_line,
2023-09-18 15:34:20 -04:00
int * match_offset);
2023-08-27 18:49:36 -04:00
extern void render_string(const char * const string,
2023-09-18 15:34:20 -04:00
const char * const mode);
2023-08-27 18:49:36 -04:00
extern int hl_init(void);
extern int hl_deinit(void);
2023-08-29 13:09:55 -04:00
#define HL_H_
#endif