aboutsummaryrefslogtreecommitdiff
path: root/src/ast.h
blob: 5c3d2980c1e5ff3068231c60eeaa2568f67de78f (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. #ifndef CMARK_NO_SHORT_NAMES
  97. #define node_inl cmark_node_inl
  98. #define INL_STRING CMARK_INL_STRING
  99. #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
  100. #define INL_LINEBREAK CMARK_INL_LINEBREAK
  101. #define INL_CODE CMARK_INL_CODE
  102. #define INL_RAW_HTML CMARK_INL_RAW_HTML
  103. #define INL_EMPH CMARK_INL_EMPH
  104. #define INL_STRONG CMARK_INL_STRONG
  105. #define INL_LINK CMARK_INL_LINK
  106. #define INL_IMAGE CMARK_INL_IMAGE
  107. #define ListData cmark_ListData
  108. #define FencedCodeData cmark_FencedCodeData
  109. #define node_block cmark_node_block
  110. #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
  111. #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
  112. #define BLOCK_LIST CMARK_BLOCK_LIST
  113. #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
  114. #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
  115. #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
  116. #define BLOCK_HTML CMARK_BLOCK_HTML
  117. #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
  118. #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
  119. #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
  120. #define BLOCK_HRULE CMARK_BLOCK_HRULE
  121. #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
  122. #define free_inlines cmark_free_inlines
  123. #define free_blocks cmark_free_blocks
  124. #endif
  125. #endif