aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: 952be8fe3a64f855433cbfc4c6a9f701ff9414f8 (plain)
  1. #ifndef _AST_H_
  2. #define _AST_H_
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include "buffer.h"
  6. #include "chunk.h"
  7. #include "references.h"
  8. struct cmark_node_inl {
  9. enum {
  10. CMARK_INL_STRING,
  11. CMARK_INL_SOFTBREAK,
  12. CMARK_INL_LINEBREAK,
  13. CMARK_INL_CODE,
  14. CMARK_INL_RAW_HTML,
  15. CMARK_INL_EMPH,
  16. CMARK_INL_STRONG,
  17. CMARK_INL_LINK,
  18. CMARK_INL_IMAGE
  19. } tag;
  20. union {
  21. cmark_chunk literal;
  22. struct cmark_node_inl *inlines;
  23. struct {
  24. struct cmark_node_inl *label;
  25. unsigned char *url;
  26. unsigned char *title;
  27. } linkable;
  28. } content;
  29. struct cmark_node_inl *next;
  30. };
  31. typedef struct cmark_node_inl cmark_node_inl;
  32. // Types for blocks
  33. struct cmark_ListData {
  34. enum {
  35. bullet,
  36. ordered
  37. } list_type;
  38. int marker_offset;
  39. int padding;
  40. int start;
  41. enum {
  42. period,
  43. parens
  44. } delimiter;
  45. unsigned char bullet_char;
  46. bool tight;
  47. };
  48. struct cmark_FencedCodeData {
  49. int fence_length;
  50. int fence_offset;
  51. unsigned char fence_char;
  52. cmark_strbuf info;
  53. };
  54. struct cmark_node_block {
  55. enum {
  56. CMARK_BLOCK_DOCUMENT,
  57. CMARK_BLOCK_BQUOTE,
  58. CMARK_BLOCK_LIST,
  59. CMARK_BLOCK_LIST_ITEM,
  60. CMARK_BLOCK_FENCED_CODE,
  61. CMARK_BLOCK_INDENTED_CODE,
  62. CMARK_BLOCK_HTML,
  63. CMARK_BLOCK_PARAGRAPH,
  64. CMARK_BLOCK_ATX_HEADER,
  65. CMARK_BLOCK_SETEXT_HEADER,
  66. CMARK_BLOCK_HRULE,
  67. CMARK_BLOCK_REFERENCE_DEF
  68. } tag;
  69. int start_line;
  70. int start_column;
  71. int end_line;
  72. bool open;
  73. bool last_line_blank;
  74. struct cmark_node_block* children;
  75. struct cmark_node_block* last_child;
  76. struct cmark_node_block* parent;
  77. struct cmark_node_block* top;
  78. cmark_strbuf string_content;
  79. cmark_node_inl* inline_content;
  80. union {
  81. struct cmark_ListData list;
  82. struct cmark_FencedCodeData code;
  83. struct {
  84. int level;
  85. } header;
  86. struct {
  87. cmark_reference_map *refmap;
  88. } document;
  89. } as;
  90. struct cmark_node_block *next;
  91. struct cmark_node_block *prev;
  92. };
  93. typedef struct cmark_node_block cmark_node_block;
  94. void cmark_free_blocks(cmark_node_block *e);
  95. void cmark_free_inlines(cmark_node_inl* e);
  96. void cmark_free_simple(cmark_node_inl *e);
  97. cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b);
  98. cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title);
  99. cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, cmark_chunk url, int is_email);
  100. cmark_node_inl* cmark_make_inlines(int t, cmark_node_inl* contents);
  101. cmark_node_inl* cmark_make_literal(int t, cmark_chunk s);
  102. cmark_node_inl* cmark_make_simple(int t);
  103. // Macros for creating various kinds of simple.
  104. #define cmark_make_str(s) cmark_make_literal(INL_STRING, s)
  105. #define cmark_make_code(s) cmark_make_literal(INL_CODE, s)
  106. #define cmark_make_raw_html(s) cmark_make_literal(INL_RAW_HTML, s)
  107. #define cmark_make_linebreak() cmark_make_simple(INL_LINEBREAK)
  108. #define cmark_make_softbreak() cmark_make_simple(INL_SOFTBREAK)
  109. #define cmark_make_emph(contents) cmark_make_inlines(INL_EMPH, contents)
  110. #define cmark_make_strong(contents) cmark_make_inlines(INL_STRONG, contents)
  111. #ifndef CMARK_NO_SHORT_NAMES
  112. #define node_inl cmark_node_inl
  113. #define INL_STRING CMARK_INL_STRING
  114. #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
  115. #define INL_LINEBREAK CMARK_INL_LINEBREAK
  116. #define INL_CODE CMARK_INL_CODE
  117. #define INL_RAW_HTML CMARK_INL_RAW_HTML
  118. #define INL_EMPH CMARK_INL_EMPH
  119. #define INL_STRONG CMARK_INL_STRONG
  120. #define INL_LINK CMARK_INL_LINK
  121. #define INL_IMAGE CMARK_INL_IMAGE
  122. #define ListData cmark_ListData
  123. #define FencedCodeData cmark_FencedCodeData
  124. #define node_block cmark_node_block
  125. #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
  126. #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
  127. #define BLOCK_LIST CMARK_BLOCK_LIST
  128. #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
  129. #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
  130. #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
  131. #define BLOCK_HTML CMARK_BLOCK_HTML
  132. #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
  133. #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
  134. #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
  135. #define BLOCK_HRULE CMARK_BLOCK_HRULE
  136. #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
  137. #define free_simple cmark_free_simple
  138. #define free_blocks cmark_free_blocks
  139. #define append_simple cmark_append_simple
  140. #define make_link cmark_make_link
  141. #define make_autolink cmark_make_autolink
  142. #define make_str cmark_make_str
  143. #define make_code cmark_make_code
  144. #define make_raw_html cmark_make_raw_html
  145. #define make_linebreak cmark_make_linebreak
  146. #define make_softbreak cmark_make_softbreak
  147. #define make_emph cmark_make_emph
  148. #define make_strong cmark_make_strong
  149. #define make_simple cmark_make_simple
  150. #define make_simple cmark_make_simple
  151. #define make_simple cmark_make_simple
  152. #endif
  153. #endif