Highlight things
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

105 lines
2.9KB

  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 "chad.h"
  8. #include "regex.h"
  9. // -------------------
  10. // ### Definitions ###
  11. // -------------------
  12. typedef enum {
  13. KEYSYMBOL,
  14. KEYWORD,
  15. MATCH,
  16. REGION
  17. } token_type_t;
  18. typedef void (*attribute_callback_t) (const char * string,
  19. const int length,
  20. void * attributes);
  21. typedef struct {
  22. char * key;
  23. attribute_callback_t callback;
  24. UT_hash_handle hh;
  25. } display_t;
  26. typedef struct {
  27. void * attributes;
  28. struct hl_group_t * link;
  29. } hl_group_t;
  30. typedef struct {
  31. hl_group_t * hl;
  32. regex_t * syntax;
  33. token_type_t t;
  34. char _pad[4];
  35. } token_t;
  36. extern vector_t token_table;
  37. extern display_t * display_table;
  38. extern hl_group_t * keyword_hl;
  39. extern hl_group_t * preprocessor_hl;
  40. extern hl_group_t * symbol_hl;
  41. extern hl_group_t * special_hl;
  42. extern hl_group_t * control_hl;
  43. extern hl_group_t * keyword_hl;
  44. extern hl_group_t * block_hl;
  45. extern hl_group_t * separator_hl;
  46. extern hl_group_t * operator_hl;
  47. extern hl_group_t * comment_hl;
  48. extern hl_group_t * string_literal_hl;
  49. extern void new_display_mode(display_t * mode);
  50. extern int free_token(token_t * token);
  51. extern int append_token(token_t * token);
  52. // TODO: ALIGN PROPERLY...
  53. extern token_t * new_symbol_token(const char * const c,
  54. hl_group_t * const g);
  55. extern int new_symbol_tokens(const char * const * symbols,
  56. hl_group_t * const g);
  57. extern int new_char_tokens(const char * str,
  58. hl_group_t * const g);
  59. extern token_t * new_keyword_token(const char * const word,
  60. hl_group_t * const g);
  61. extern int new_keyword_tokens(const char * const * words,
  62. hl_group_t * const g);
  63. extern token_t * new_token(const char * const word,
  64. const token_type_t t,
  65. hl_group_t * const g);
  66. extern token_t * new_region_token(const char * start,
  67. const char * end,
  68. hl_group_t * g);
  69. // TODO: ALIGN PROPERLY...
  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