libhighlight.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * Author: g0tsu
  12. * Email: g0tsu at dnmx.0rg
  13. */
  14. #ifndef _HL_LIBHIGHLIGHT_H
  15. #define _HL_LIBHIGHLIGHT_H
  16. #include <stdint.h>
  17. #include <stddef.h>
  18. #include <config.h>
  19. #ifndef CONFIG_USE_HTML
  20. #define CONFIG_USE_HTML 1
  21. #endif
  22. enum {
  23. HL_NODE_SPACE = 1,
  24. HL_NODE_NEWLINE,
  25. HL_NODE_TEXT,
  26. HL_NODE_SCOPE_START,
  27. HL_NODE_SCOPE_END,
  28. HL_NODE_QUOTE,
  29. HL_NODE_SYMBOL,
  30. HL_NODE_FUNCTION,
  31. HL_NODE_FUNCTION_CALL,
  32. HL_NODE_EXPR,
  33. HL_NODE_TYPE,
  34. HL_NODE_DECL,
  35. HL_NODE_DEFINITION,
  36. HL_NODE_COMMENT_START,
  37. HL_NODE_COMMENT_END,
  38. HL_NODE_MCOMMENT_START,
  39. HL_NODE_MCOMMENT_END,
  40. HL_NODE_CHCOMMENT,
  41. HL_NODE_NUMBER
  42. };
  43. typedef struct hl_node {
  44. uint8_t type;
  45. char *text;
  46. int text_len;
  47. struct hl_node *children;
  48. struct hl_node *parent;
  49. struct hl_node *root;
  50. } hl_node;
  51. typedef struct hl_root {
  52. hl_node *node;
  53. size_t size;
  54. size_t text_size;
  55. } hl_root;
  56. typedef struct hl_ctx {
  57. uint8_t last;
  58. uint8_t lock;
  59. uint8_t sh;
  60. } hl_ctx;
  61. hl_root * hl_parser(uint8_t *buffer, size_t len,
  62. void (*user_next_word)(char *, int, hl_node *, hl_ctx *ctx));
  63. hl_root * hl_parser_file(
  64. int fd, void (*user_next_word)(char *, int, hl_node *, hl_ctx *));
  65. void hl_next_word(char *word, int len, hl_node *node, hl_ctx *ctx);
  66. hl_node * hl_node_create();
  67. hl_node * hl_node_insert(hl_node * node);
  68. hl_node * hl_node_at(hl_node * node, int at);
  69. void hl_node_free(hl_node * root);
  70. void hl_root_free(hl_root *root);
  71. #ifdef CONFIG_USE_HTML
  72. char * hl_compile_html(hl_root *root);
  73. #endif
  74. char * hl_compile_term(hl_root *root);
  75. void hl_compile_pp(hl_node *node);
  76. int hl_keyword_expr(char *word, int len);
  77. int hl_keyword_type(char *word, int len);
  78. int hl_keyword_decl(char *word, int len);
  79. int hl_keyword_is_number(char *str, int len);
  80. #endif