Highlight things
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.0KB

  1. #ifndef HL_H_
  2. #include <stdio.h>
  3. #include <uthash.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6. #include <stdbool.h>
  7. #include "vector.h"
  8. #include "jeger.h"
  9. #define UNUSED(x) ((void)x) /* much like this header */
  10. // -------------------
  11. // ### Definitions ###
  12. // -------------------
  13. typedef enum {
  14. KEYSYMBOL,
  15. KEYWORD,
  16. MATCH,
  17. REGION
  18. } token_type_t;
  19. typedef void (*attribute_callback_t) (const char * string,
  20. const int length,
  21. void * attributes);
  22. typedef struct {
  23. char * key;
  24. attribute_callback_t callback;
  25. UT_hash_handle hh;
  26. } display_t;
  27. typedef struct {
  28. void * attributes;
  29. struct hl_group_t * link;
  30. } hl_group_t;
  31. typedef struct {
  32. hl_group_t * hl;
  33. regex_t * syntax;
  34. token_type_t t;
  35. char _pad[4];
  36. } token_t;
  37. extern vector_t token_table;
  38. extern display_t * display_table;
  39. extern hl_group_t * keyword_hl;
  40. extern hl_group_t * preprocessor_hl;
  41. extern hl_group_t * symbol_hl;
  42. extern hl_group_t * special_hl;
  43. extern hl_group_t * control_hl;
  44. extern hl_group_t * keyword_hl;
  45. extern hl_group_t * block_hl;
  46. extern hl_group_t * separator_hl;
  47. extern hl_group_t * operator_hl;
  48. extern hl_group_t * comment_hl;
  49. extern hl_group_t * string_literal_hl;
  50. extern void new_display_mode(display_t * mode);
  51. extern int free_token(token_t * token);
  52. extern int append_token(token_t * token);
  53. // TODO: ALIGN PROPERLY...
  54. extern token_t * new_symbol_token(const char * const c,
  55. hl_group_t * const g);
  56. extern int new_symbol_tokens(const char * const * symbols,
  57. hl_group_t * const g);
  58. extern int new_char_tokens(const char * str,
  59. hl_group_t * const g);
  60. extern token_t * new_keyword_token(const char * const word,
  61. hl_group_t * const g);
  62. extern int new_keyword_tokens(const char * const * words,
  63. hl_group_t * const g);
  64. extern token_t * new_token(const char * const word,
  65. const token_type_t t,
  66. hl_group_t * const g);
  67. extern token_t * new_region_token(const char * start,
  68. const char * end,
  69. hl_group_t * g);
  70. extern int token_fits(const token_t * const token,
  71. const char * const to,
  72. const int string_offset,
  73. const bool is_start_of_line,
  74. int * match_offset);
  75. extern void render_string(const char * const string,
  76. const char * const mode);
  77. extern int hl_init(void);
  78. extern int hl_deinit(void);
  79. #define HL_H_
  80. #endif