aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: b4427c0d6448786d5c9fa532937296e651a6b144 (plain)
  1. #ifndef CMARK_AST_H
  2. #define CMARK_AST_H
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include "buffer.h"
  6. #include "chunk.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #define CMARK_VERSION "0.1"
  11. #define CMARK_CODE_INDENT 4
  12. #define REFMAP_SIZE 16
  13. #define CMARK_MAX_LINK_LABEL_LENGTH 1000
  14. struct cmark_node_inl {
  15. enum {
  16. CMARK_INL_STRING,
  17. CMARK_INL_SOFTBREAK,
  18. CMARK_INL_LINEBREAK,
  19. CMARK_INL_CODE,
  20. CMARK_INL_RAW_HTML,
  21. CMARK_INL_EMPH,
  22. CMARK_INL_STRONG,
  23. CMARK_INL_LINK,
  24. CMARK_INL_IMAGE
  25. } tag;
  26. union {
  27. cmark_chunk literal;
  28. struct cmark_node_inl *inlines;
  29. struct {
  30. struct cmark_node_inl *label;
  31. unsigned char *url;
  32. unsigned char *title;
  33. } linkable;
  34. } content;
  35. struct cmark_node_inl *next;
  36. };
  37. struct cmark_reference {
  38. struct cmark_reference *next;
  39. unsigned char *label;
  40. unsigned char *url;
  41. unsigned char *title;
  42. unsigned int hash;
  43. };
  44. typedef struct cmark_reference cmark_reference;
  45. struct cmark_reference_map {
  46. cmark_reference *table[REFMAP_SIZE];
  47. };
  48. typedef struct cmark_reference_map cmark_reference_map;
  49. // Types for blocks
  50. struct cmark_ListData {
  51. enum {
  52. bullet,
  53. ordered
  54. } list_type;
  55. int marker_offset;
  56. int padding;
  57. int start;
  58. enum {
  59. period,
  60. parens
  61. } delimiter;
  62. unsigned char bullet_char;
  63. bool tight;
  64. };
  65. struct cmark_FencedCodeData {
  66. int fence_length;
  67. int fence_offset;
  68. unsigned char fence_char;
  69. cmark_strbuf info;
  70. };
  71. struct cmark_node_block {
  72. enum {
  73. CMARK_BLOCK_DOCUMENT,
  74. CMARK_BLOCK_BQUOTE,
  75. CMARK_BLOCK_LIST,
  76. CMARK_BLOCK_LIST_ITEM,
  77. CMARK_BLOCK_FENCED_CODE,
  78. CMARK_BLOCK_INDENTED_CODE,
  79. CMARK_BLOCK_HTML,
  80. CMARK_BLOCK_PARAGRAPH,
  81. CMARK_BLOCK_ATX_HEADER,
  82. CMARK_BLOCK_SETEXT_HEADER,
  83. CMARK_BLOCK_HRULE,
  84. CMARK_BLOCK_REFERENCE_DEF
  85. } tag;
  86. int start_line;
  87. int start_column;
  88. int end_line;
  89. bool open;
  90. bool last_line_blank;
  91. struct cmark_node_block* children;
  92. struct cmark_node_block* last_child;
  93. struct cmark_node_block* parent;
  94. struct cmark_node_block* top;
  95. cmark_strbuf string_content;
  96. struct cmark_node_inl* inline_content;
  97. union {
  98. struct cmark_ListData list;
  99. struct cmark_FencedCodeData code;
  100. struct {
  101. int level;
  102. } header;
  103. struct {
  104. cmark_reference_map *refmap;
  105. } document;
  106. } as;
  107. struct cmark_node_block *next;
  108. struct cmark_node_block *prev;
  109. };
  110. struct cmark_doc_parser {
  111. struct cmark_node_block* head;
  112. struct cmark_node_block* current;
  113. int line_number;
  114. cmark_strbuf *curline;
  115. };
  116. #ifndef CMARK_NO_SHORT_NAMES
  117. #define node_inl cmark_node_inl
  118. #define INL_STRING CMARK_INL_STRING
  119. #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
  120. #define INL_LINEBREAK CMARK_INL_LINEBREAK
  121. #define INL_CODE CMARK_INL_CODE
  122. #define INL_RAW_HTML CMARK_INL_RAW_HTML
  123. #define INL_EMPH CMARK_INL_EMPH
  124. #define INL_STRONG CMARK_INL_STRONG
  125. #define INL_LINK CMARK_INL_LINK
  126. #define INL_IMAGE CMARK_INL_IMAGE
  127. #define ListData cmark_ListData
  128. #define FencedCodeData cmark_FencedCodeData
  129. #define node_block cmark_node_block
  130. #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
  131. #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
  132. #define BLOCK_LIST CMARK_BLOCK_LIST
  133. #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
  134. #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
  135. #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
  136. #define BLOCK_HTML CMARK_BLOCK_HTML
  137. #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
  138. #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
  139. #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
  140. #define BLOCK_HRULE CMARK_BLOCK_HRULE
  141. #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
  142. #endif
  143. #ifdef __cplusplus
  144. }
  145. #endif
  146. #endif