| 1 | |
|---|
| 2 | #----------------------------------------------------------------------------- |
|---|
| 3 | # root productions |
|---|
| 4 | |
|---|
| 5 | document: _empty_line? _paragraph (_empty_line _paragraph)* _document_trailing |
|---|
| 6 | ; |
|---|
| 7 | |
|---|
| 8 | _document_trailing: _empty_line? |
|---|
| 9 | | _empty_line |
|---|
| 10 | NEW_SECTION |
|---|
| 11 | (_empty_line block_definition)* _empty_line? |
|---|
| 12 | ; |
|---|
| 13 | |
|---|
| 14 | _empty_line: EMPTY_LINE+ |
|---|
| 15 | ; |
|---|
| 16 | |
|---|
| 17 | _paragraph: heading_paragraph |
|---|
| 18 | | text_paragraph |
|---|
| 19 | | code_paragraph |
|---|
| 20 | | list_paragraph |
|---|
| 21 | | table_paragraph |
|---|
| 22 | ; |
|---|
| 23 | |
|---|
| 24 | #----------------------------------------------------------------------------- |
|---|
| 25 | # common useful productions {{ |
|---|
| 26 | |
|---|
| 27 | space: ' ' |
|---|
| 28 | | NL |
|---|
| 29 | ; |
|---|
| 30 | |
|---|
| 31 | _printable: _printable_atom+ |
|---|
| 32 | ; |
|---|
| 33 | |
|---|
| 34 | # anything that can appear on its own and would mean literal text (no |
|---|
| 35 | # formatting, no s///, no escape characters \n, no nothing -- just the entered |
|---|
| 36 | # text), in order of appearance in lexer |
|---|
| 37 | _printable_atom: COMMA |
|---|
| 38 | | STRING |
|---|
| 39 | | Q_CHAR |
|---|
| 40 | | WORD |
|---|
| 41 | | NUMBER |
|---|
| 42 | | PUNCT |
|---|
| 43 | | macro_call |
|---|
| 44 | | macro_call_silent |
|---|
| 45 | | block_call |
|---|
| 46 | | MACRO_VALUE |
|---|
| 47 | ; |
|---|
| 48 | |
|---|
| 49 | #----------------------------------------------------------- |
|---|
| 50 | # macros and %blocks support {{ |
|---|
| 51 | |
|---|
| 52 | macro_call: MACRO_CALL ' ' _macro_arguments ']]' |
|---|
| 53 | | MACRO_CALL ' '? ']]' |
|---|
| 54 | ; |
|---|
| 55 | |
|---|
| 56 | macro_call_silent: MACRO_CALL_SILENT ' ' _macro_arguments ']]' |
|---|
| 57 | | MACRO_CALL_SILENT ' '? ']]' |
|---|
| 58 | ; |
|---|
| 59 | |
|---|
| 60 | block_call: BLOCK_CALL ' ' _macro_arguments ']]' |
|---|
| 61 | | BLOCK_CALL ' '? ']]' |
|---|
| 62 | ; |
|---|
| 63 | |
|---|
| 64 | _macro_arguments: macro_arg (_comma macro_arg)* ' '? |
|---|
| 65 | ; |
|---|
| 66 | |
|---|
| 67 | _comma: ' ' ' '* COMMA ' '* |
|---|
| 68 | | COMMA ' '* |
|---|
| 69 | ; |
|---|
| 70 | |
|---|
| 71 | macro_arg: NUMBER |
|---|
| 72 | | STRING |
|---|
| 73 | | MACRO_VALUE |
|---|
| 74 | ; |
|---|
| 75 | |
|---|
| 76 | # }}} |
|---|
| 77 | #----------------------------------------------------------- |
|---|
| 78 | # %blocks definition section {{ |
|---|
| 79 | |
|---|
| 80 | # XXX: tree postprocessing depends on this static structure: |
|---|
| 81 | # BLOCK_CALL, arguments (possibly empty list), body, discard all the rest |
|---|
| 82 | block_definition: BLOCK_CALL block_arguments ']]' ' '? '{{{' block_body '}}}' |
|---|
| 83 | ; |
|---|
| 84 | |
|---|
| 85 | block_arguments: ' ' MACRO_VALUE (_comma MACRO_VALUE)* |
|---|
| 86 | | ' '? |
|---|
| 87 | ; |
|---|
| 88 | |
|---|
| 89 | # TODO: more paragraphs in the block allowed |
|---|
| 90 | block_body: _paragraph |
|---|
| 91 | ; |
|---|
| 92 | |
|---|
| 93 | # }}} |
|---|
| 94 | #----------------------------------------------------------- |
|---|
| 95 | |
|---|
| 96 | _raw_text: _printable (space _printable)* |
|---|
| 97 | ; |
|---|
| 98 | |
|---|
| 99 | #_raw_text_ending_space: _printable (space _printable)* space? |
|---|
| 100 | #; |
|---|
| 101 | |
|---|
| 102 | _non_space_sequence: _non_space_atom+ |
|---|
| 103 | ; |
|---|
| 104 | |
|---|
| 105 | _non_space_atom: _simple_format |
|---|
| 106 | | _printable_atom |
|---|
| 107 | ; |
|---|
| 108 | |
|---|
| 109 | _text_ending_space: _non_space_sequence (space _non_space_sequence)* space? |
|---|
| 110 | ; |
|---|
| 111 | |
|---|
| 112 | _text_single_line_must_end_space: (_non_space_sequence ' ')+ |
|---|
| 113 | ; |
|---|
| 114 | |
|---|
| 115 | # }}} |
|---|
| 116 | #----------------------------------------------------------------------------- |
|---|
| 117 | # text paragraph {{ |
|---|
| 118 | |
|---|
| 119 | text_paragraph: text_paragraph_line (LINE_BREAK text_paragraph_line)* |
|---|
| 120 | ; |
|---|
| 121 | |
|---|
| 122 | text_paragraph_line: _text_ending_space |
|---|
| 123 | ; |
|---|
| 124 | |
|---|
| 125 | # }}} |
|---|
| 126 | #----------------------------------------------------------------------------- |
|---|
| 127 | # formatted text {{ |
|---|
| 128 | |
|---|
| 129 | _simple_format: bold_text |
|---|
| 130 | | italic_text |
|---|
| 131 | | strike_text |
|---|
| 132 | | tt_text |
|---|
| 133 | | link |
|---|
| 134 | | image |
|---|
| 135 | ; |
|---|
| 136 | |
|---|
| 137 | link: '[[' link_target ']]' |
|---|
| 138 | | '[[' link_target space link_description ']]' |
|---|
| 139 | ; |
|---|
| 140 | |
|---|
| 141 | image: '[[!' image_target ']]' |
|---|
| 142 | ; |
|---|
| 143 | |
|---|
| 144 | link_target: _url |
|---|
| 145 | ; |
|---|
| 146 | |
|---|
| 147 | image_target: _url |
|---|
| 148 | ; |
|---|
| 149 | |
|---|
| 150 | _url: _printable |
|---|
| 151 | ; |
|---|
| 152 | |
|---|
| 153 | link_description: _printable (space _printable)* |
|---|
| 154 | | image space? |
|---|
| 155 | ; |
|---|
| 156 | |
|---|
| 157 | bold_text: '**' _raw_text '**' |
|---|
| 158 | ; |
|---|
| 159 | italic_text: '__' _raw_text '__' |
|---|
| 160 | ; |
|---|
| 161 | strike_text: '~~' _raw_text '~~' |
|---|
| 162 | ; |
|---|
| 163 | tt_text: '{{' _raw_text '}}' |
|---|
| 164 | ; |
|---|
| 165 | |
|---|
| 166 | # }}} |
|---|
| 167 | #----------------------------------------------------------------------------- |
|---|
| 168 | # heading paragraph {{ |
|---|
| 169 | |
|---|
| 170 | heading_paragraph: HEADER_S space? _text_ending_space HEADER_E space? |
|---|
| 171 | ; |
|---|
| 172 | |
|---|
| 173 | # }}} |
|---|
| 174 | #----------------------------------------------------------------------------- |
|---|
| 175 | # code paragraph {{ |
|---|
| 176 | |
|---|
| 177 | # well, nothing fancy: lexer did all the job here |
|---|
| 178 | code_paragraph: PRE |
|---|
| 179 | ; |
|---|
| 180 | |
|---|
| 181 | # }}} |
|---|
| 182 | #----------------------------------------------------------------------------- |
|---|
| 183 | # numbered/enumerated paragraph {{ |
|---|
| 184 | |
|---|
| 185 | list_paragraph: _some_list |
|---|
| 186 | ; |
|---|
| 187 | |
|---|
| 188 | _some_list: numbered_list |
|---|
| 189 | | alpha_list |
|---|
| 190 | | bullet_list |
|---|
| 191 | | undecorated_list |
|---|
| 192 | ; |
|---|
| 193 | |
|---|
| 194 | numbered_list: BEGIN_INDENT numbered_list_element+ END_INDENT |
|---|
| 195 | ; |
|---|
| 196 | |
|---|
| 197 | numbered_list_element: LIST_NUMERIC _list_item _some_list? |
|---|
| 198 | ; |
|---|
| 199 | |
|---|
| 200 | alpha_list: BEGIN_INDENT alpha_list_element+ END_INDENT |
|---|
| 201 | ; |
|---|
| 202 | |
|---|
| 203 | alpha_list_element: LIST_ALPHA _list_item _some_list? |
|---|
| 204 | ; |
|---|
| 205 | |
|---|
| 206 | bullet_list: BEGIN_INDENT bullet_list_element+ END_INDENT |
|---|
| 207 | ; |
|---|
| 208 | |
|---|
| 209 | bullet_list_element: LIST_BULLET _list_item _some_list? |
|---|
| 210 | ; |
|---|
| 211 | |
|---|
| 212 | undecorated_list: BEGIN_INDENT undecorated_list_element+ END_INDENT |
|---|
| 213 | ; |
|---|
| 214 | |
|---|
| 215 | undecorated_list_element: LIST_UNDECO _list_item _some_list? |
|---|
| 216 | ; |
|---|
| 217 | |
|---|
| 218 | _list_item: list_item_line (LINE_BREAK_INDENTED list_item_line)* |
|---|
| 219 | ; |
|---|
| 220 | |
|---|
| 221 | list_item_line: _text_ending_space |
|---|
| 222 | ; |
|---|
| 223 | |
|---|
| 224 | # }}} |
|---|
| 225 | #----------------------------------------------------------------------------- |
|---|
| 226 | # table paragraph {{ |
|---|
| 227 | |
|---|
| 228 | table_paragraph: table_row+ |
|---|
| 229 | ; |
|---|
| 230 | |
|---|
| 231 | table_row: TABLE_ROW_START table_cell _trowrest_starting_plain NL |
|---|
| 232 | | TABLE_ROW_H_START header_cell _trowrest_starting_header NL |
|---|
| 233 | ; |
|---|
| 234 | |
|---|
| 235 | _trowrest_starting_plain: TABLE_CELL table_cell _trowrest_starting_plain |
|---|
| 236 | | TABLE_CELL_R header_cell _trowrest_starting_header |
|---|
| 237 | | TABLE_ROW_END |
|---|
| 238 | ; |
|---|
| 239 | |
|---|
| 240 | _trowrest_starting_header: TABLE_CELL_L table_cell _trowrest_starting_plain |
|---|
| 241 | | TABLE_CELL_LR header_cell _trowrest_starting_header |
|---|
| 242 | | TABLE_ROW_H_END |
|---|
| 243 | ; |
|---|
| 244 | |
|---|
| 245 | # <td>..</td> |
|---|
| 246 | table_cell: _table_cell |
|---|
| 247 | ; |
|---|
| 248 | |
|---|
| 249 | # <th>..</th> |
|---|
| 250 | header_cell: _table_cell |
|---|
| 251 | ; |
|---|
| 252 | |
|---|
| 253 | _table_cell: ' ' _text_single_line_must_end_space |
|---|
| 254 | | ' ' |
|---|
| 255 | ; |
|---|
| 256 | |
|---|
| 257 | # }}} |
|---|
| 258 | #----------------------------------------------------------------------------- |
|---|
| 259 | |
|---|