View raw

1 (** Public semantic AST types for Org Mode documents. 2 3 This module defines the strongly-typed abstract syntax tree produced by 4 parsing an Org Mode document. The types are designed to be semantic: they 5 represent the meaning of Org constructs rather than their exact surface 6 syntax. 7 8 The AST is read-only and uses closed variants for known constructs. *) 9 10 (** {1 Inline objects} *) 11 12 (** A link target. *) 13 type link_target = 14 | Url of string 15 | File of string 16 | Internal of string 17 | Protocol of string * string 18 19 (** {1 Timestamps} *) 20 21 type date = { 22 year : int; 23 month : int; 24 day : int; 25 dayname : string option; 26 hour : int option; 27 minute : int option; 28 } 29 30 type repeater_mark = Plus | Double_plus | Dot_plus | Minus | Double_minus 31 type duration_unit = Hour | Day | Week | Month | Year 32 33 type repeater_or_delay = { 34 mark : repeater_mark; 35 value : int; 36 unit_ : duration_unit; 37 } 38 39 type timestamp = 40 | Active of date * repeater_or_delay option 41 | Inactive of date * repeater_or_delay option 42 | Active_range of date * date 43 | Inactive_range of date * date 44 45 (** {1 Planning} *) 46 47 type planning = { 48 deadline : timestamp option; 49 scheduled : timestamp option; 50 closed : timestamp option; 51 } 52 53 (** {1 Properties} *) 54 55 type property = { prop_name : string; prop_value : string option } 56 57 (** {1 Affiliated keywords} *) 58 59 type affiliated = { 60 aff_name : string; 61 aff_optional : string option; 62 aff_value : string; 63 } 64 65 (** {1 Inline objects} *) 66 67 type inline = 68 | Plain of string 69 | Bold of inline list 70 | Italic of inline list 71 | Underline of inline list 72 | Strikethrough of inline list 73 | Code of string 74 | Verbatim of string 75 | Link of link 76 | Timestamp of timestamp 77 | Line_break 78 79 and link = { target : link_target; description : inline list option } 80 81 (** {1 Lists} *) 82 83 type list_kind = Ordered | Unordered | Descriptive 84 type checkbox = Checked | Unchecked | Partial 85 86 (** {1 Tables} *) 87 88 type table_cell = inline list 89 type table_row = Table_row_standard of table_cell list | Table_row_rule 90 type table = { rows : table_row list } 91 92 (** {1 Blocks} *) 93 94 type src_block = { 95 src_language : string option; 96 src_switches : string option; 97 src_arguments : string option; 98 src_value : string; 99 src_affiliated : affiliated list; 100 } 101 102 (** {1 Keywords} *) 103 104 type keyword = { kw_key : string; kw_value : string } 105 106 (** {1 Elements} *) 107 108 type element = 109 | Paragraph of inline list * affiliated list 110 | Plain_list of list_kind * list_item list 111 | Table of table 112 | Block of block 113 | Drawer of string * element list 114 | Keyword of keyword 115 | Comment of string list 116 | Fixed_width of string list 117 | Horizontal_rule 118 119 and list_item = { 120 li_bullet : string; 121 li_counter_set : int option; 122 li_checkbox : checkbox option; 123 li_tag : inline list option; 124 li_contents : element list; 125 } 126 127 and block = 128 | Src_block of src_block 129 | Example_block of { 130 ex_value : string; 131 ex_switches : string option; 132 ex_affiliated : affiliated list; 133 } 134 | Export_block of { 135 exp_backend : string; 136 exp_value : string; 137 exp_affiliated : affiliated list; 138 } 139 | Comment_block of { cb_value : string; cb_affiliated : affiliated list } 140 | Quote_block of { 141 qt_contents : element list; 142 qt_affiliated : affiliated list; 143 } 144 | Center_block of { 145 cn_contents : element list; 146 cn_affiliated : affiliated list; 147 } 148 | Verse_block of { 149 vs_contents : inline list; 150 vs_affiliated : affiliated list; 151 } 152 | Custom_block of { 153 cst_name : string; 154 cst_params : string option; 155 cst_contents : element list; 156 cst_affiliated : affiliated list; 157 } 158 159 (** {1 Headings} *) 160 161 type heading = { 162 level : int; 163 todo : string option; 164 priority : char option; 165 commented : bool; 166 title : inline list; 167 tags : string list; 168 planning : planning option; 169 properties : property list; 170 contents : element list; 171 children : heading list; 172 } 173 174 (** {1 Directives} *) 175 176 type directive = { dir_key : string; dir_value : string } 177 178 (** {1 Document} *) 179 180 type document = { 181 directives : directive list; 182 preamble : element list; 183 headings : heading list; 184 } 185