├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── binding.gyp ├── bindings ├── node │ ├── binding.cc │ └── index.js └── rust │ ├── build.rs │ └── lib.rs ├── corpus └── basic.tst ├── grammar.js ├── package.json ├── queries ├── highlights.scm └── markup.scm └── src ├── grammar.json ├── node-types.json ├── parser.c ├── scanner.c └── tree_sitter └── parser.h /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | package-lock.json 3 | node_modules 4 | build 5 | *.log 6 | /examples/*/ 7 | /target/ 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tree-sitter-org" 3 | description = "org grammar for the tree-sitter parsing library" 4 | version = "1.3.3" 5 | keywords = ["incremental", "parsing", "org"] 6 | categories = ["parsing", "text-editors"] 7 | repository = "https://github.com/milisims/tree-sitter-org" 8 | edition = "2021" 9 | license = "MIT" 10 | 11 | build = "bindings/rust/build.rs" 12 | include = [ 13 | "bindings/rust/*", 14 | "grammar.js", 15 | "queries/*", 16 | "src/*", 17 | ] 18 | 19 | [lib] 20 | path = "bindings/rust/lib.rs" 21 | 22 | [dependencies] 23 | tree-sitter = ">= 0.19, < 0.21" 24 | 25 | [build-dependencies] 26 | cc = "1.0" 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2022 Emilia Simmons 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-sitter-org 2 | 3 | Org grammar for tree-sitter. Here, the goal is to implement a grammar that can 4 | usefully parse org files to be used in any library that uses tree-sitter 5 | parsers. It is not meant to implement emacs' orgmode parser exactly, which is 6 | inherently more dynamic than tree-sitter easily allows. 7 | 8 | ## Overview 9 | 10 | This section is meant to be a quick reference, not a thorough description. 11 | Refer to the tests in `corpus` for examples. 12 | 13 | - Top level node: `(document)` 14 | - Document contains: `(directive)* (body)? (section)*` 15 | - Section contains: `(headline) (plan)? (property_drawer)? (body)?` 16 | - headline contains: `((stars), (item)?, (tag_list)?)` 17 | - body contains: `(element)+` 18 | - element contains: `(directive)* choose(paragraph, drawer, comment, footnote def, list, block, dynamic block, table)` or a bare `(directive)` 19 | - paragraph contains: `(expr)+` 20 | - expr contains: anonymous nodes for 'str', 'num', 'sym', and any ascii symbol that is not letters or numbers. (See top of grammar.js and queries for details) 21 | 22 | Like in many regex systems, `*/+` is read as "0/1 or more", and `?` is 0 or 1. 23 | 24 | ## Example 25 | 26 | ```org 27 | #+TITLE: Example 28 | 29 | Some *marked up* words 30 | 31 | * TODO Title 32 | <2020-06-07 Sun> 33 | 34 | - list a 35 | - [-] list a 36 | - [ ] list b 37 | - [x] list b 38 | - list a 39 | 40 | ** Subsection :tag: 41 | 42 | Text 43 | ``` 44 | 45 | Parses as: 46 | 47 | ``` 48 | (document [0, 0] - [16, 0] 49 | body: (body [0, 0] - [4, 0] 50 | directive: (directive [0, 0] - [1, 0] 51 | name: (expr [0, 2] - [0, 7]) 52 | value: (value [0, 9] - [0, 16] 53 | (expr [0, 9] - [0, 16]))) 54 | (paragraph [2, 0] - [3, 0] 55 | (expr [2, 0] - [2, 4]) 56 | (expr [2, 5] - [2, 12]) 57 | (expr [2, 13] - [2, 16]) 58 | (expr [2, 17] - [2, 22]))) 59 | subsection: (section [4, 0] - [16, 0] 60 | headline: (headline [4, 0] - [5, 0] 61 | stars: (stars [4, 0] - [4, 1]) 62 | item: (item [4, 2] - [4, 12] 63 | (expr [4, 2] - [4, 6]) 64 | (expr [4, 7] - [4, 12]))) 65 | plan: (plan [5, 0] - [6, 0] 66 | (entry [5, 0] - [5, 16] 67 | timestamp: (timestamp [5, 0] - [5, 16] 68 | date: (date [5, 1] - [5, 11]) 69 | day: (day [5, 12] - [5, 15])))) 70 | body: (body [6, 0] - [13, 0] 71 | (list [7, 0] - [12, 0] 72 | (listitem [7, 2] - [8, 0] 73 | bullet: (bullet [7, 2] - [7, 3]) 74 | contents: (paragraph [7, 4] - [8, 0] 75 | (expr [7, 4] - [7, 8]) 76 | (expr [7, 9] - [7, 10]))) 77 | (listitem [8, 2] - [11, 0] 78 | bullet: (bullet [8, 2] - [8, 3]) 79 | checkbox: (checkbox [8, 4] - [8, 7] 80 | status: (expr [8, 5] - [8, 6])) 81 | contents: (paragraph [8, 8] - [9, 0] 82 | (expr [8, 8] - [8, 12]) 83 | (expr [8, 13] - [8, 14])) 84 | contents: (list [9, 0] - [11, 0] 85 | (listitem [9, 4] - [10, 0] 86 | bullet: (bullet [9, 4] - [9, 5]) 87 | checkbox: (checkbox [9, 6] - [9, 9]) 88 | contents: (paragraph [9, 10] - [10, 0] 89 | (expr [9, 10] - [9, 14]) 90 | (expr [9, 15] - [9, 16]))) 91 | (listitem [10, 4] - [11, 0] 92 | bullet: (bullet [10, 4] - [10, 5]) 93 | checkbox: (checkbox [10, 6] - [10, 9] 94 | status: (expr [10, 7] - [10, 8])) 95 | contents: (paragraph [10, 10] - [11, 0] 96 | (expr [10, 10] - [10, 14]) 97 | (expr [10, 15] - [10, 16]))))) 98 | (listitem [11, 2] - [12, 0] 99 | bullet: (bullet [11, 2] - [11, 3]) 100 | contents: (paragraph [11, 4] - [12, 0] 101 | (expr [11, 4] - [11, 8]) 102 | (expr [11, 9] - [11, 10]))))) 103 | subsection: (section [13, 0] - [16, 0] 104 | headline: (headline [13, 0] - [14, 0] 105 | stars: (stars [13, 0] - [13, 2]) 106 | item: (item [13, 3] - [13, 13] 107 | (expr [13, 3] - [13, 13])) 108 | tags: (tag_list [13, 14] - [13, 19] 109 | tag: (tag [13, 15] - [13, 18]))) 110 | body: (body [14, 0] - [16, 0] 111 | (paragraph [15, 0] - [16, 0] 112 | (expr [15, 0] - [15, 4])))))) 113 | ``` 114 | 115 | ## Install 116 | 117 | For manual install, use `make`. 118 | 119 | For neovim, using `nvim-treesitter/nvim-treesitter`, add to your configuration: 120 | 121 | ```lua 122 | local parser_config = require "nvim-treesitter.parsers".get_parser_configs() 123 | parser_config.org = { 124 | install_info = { 125 | url = 'https://github.com/milisims/tree-sitter-org', 126 | revision = 'main', 127 | files = { 'src/parser.c', 'src/scanner.c' }, 128 | }, 129 | filetype = 'org', 130 | } 131 | ``` 132 | 133 | To build the parser using npm and run tests: 134 | 135 | 1. Install node.js as described in the [tree-sitter documentation](https://tree-sitter.github.io/tree-sitter/creating-parsers#dependencies) 136 | 2. Clone this repository: `git clone https://github.com/milisims/tree-sitter-org` and `cd` into it 137 | 3. Install tree-sitter using npm: `npm install` 138 | 4. Run tests: `./node_modules/.bin/tree-sitter generate && ./node_modules/.bin/tree-sitter test` 139 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_org_binding", 5 | "include_dirs": [ 6 | " 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_org(); 8 | 9 | namespace { 10 | 11 | NAN_METHOD(New) {} 12 | 13 | void Init(Local exports, Local module) { 14 | Local tpl = Nan::New(New); 15 | tpl->SetClassName(Nan::New("Language").ToLocalChecked()); 16 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 17 | 18 | Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); 19 | Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); 20 | Nan::SetInternalFieldPointer(instance, 0, tree_sitter_org()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("org").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_org_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /bindings/node/index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports = require("../../build/Release/tree_sitter_org_binding"); 3 | } catch (error1) { 4 | if (error1.code !== 'MODULE_NOT_FOUND') { 5 | throw error1; 6 | } 7 | try { 8 | module.exports = require("../../build/Debug/tree_sitter_org_binding"); 9 | } catch (error2) { 10 | if (error2.code !== 'MODULE_NOT_FOUND') { 11 | throw error2; 12 | } 13 | throw error1 14 | } 15 | } 16 | 17 | try { 18 | module.exports.nodeTypeInfo = require("../../src/node-types.json"); 19 | } catch (_) {} 20 | -------------------------------------------------------------------------------- /bindings/rust/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let src_dir = std::path::Path::new("src"); 3 | 4 | let mut c_config = cc::Build::new(); 5 | c_config.include(src_dir); 6 | c_config 7 | .flag_if_supported("-Wno-unused-parameter") 8 | .flag_if_supported("-Wno-unused-but-set-variable") 9 | .flag_if_supported("-Wno-trigraphs"); 10 | let parser_path = src_dir.join("parser.c"); 11 | c_config.file(&parser_path); 12 | 13 | let scanner_path = src_dir.join("scanner.c"); 14 | c_config.file(&scanner_path); 15 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 16 | 17 | c_config.compile("parser"); 18 | println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 19 | } 20 | -------------------------------------------------------------------------------- /bindings/rust/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides org language support for the [tree-sitter][] parsing library. 2 | //! 3 | //! Typically, you will use the [language][language func] function to add this language to a 4 | //! tree-sitter [Parser][], and then use the parser to parse some code: 5 | //! 6 | //! ``` 7 | //! let code = ""; 8 | //! let mut parser = tree_sitter::Parser::new(); 9 | //! parser.set_language(tree_sitter_org::language()).expect("Error loading org grammar"); 10 | //! let tree = parser.parse(code, None).unwrap(); 11 | //! ``` 12 | //! 13 | //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 14 | //! [language func]: fn.language.html 15 | //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html 16 | //! [tree-sitter]: https://tree-sitter.github.io/ 17 | 18 | use tree_sitter::Language; 19 | 20 | extern "C" { 21 | fn tree_sitter_org() -> Language; 22 | } 23 | 24 | /// Get the tree-sitter [Language][] for this grammar. 25 | /// 26 | /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 27 | pub fn language() -> Language { 28 | unsafe { tree_sitter_org() } 29 | } 30 | 31 | /// The content of the [`node-types.json`][] file for this grammar. 32 | /// 33 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types 34 | pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); 35 | 36 | // Uncomment these to include any queries that this grammar contains 37 | 38 | pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); 39 | // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); 40 | // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); 41 | // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | #[test] 46 | fn test_can_load_grammar() { 47 | let mut parser = tree_sitter::Parser::new(); 48 | parser 49 | .set_language(super::language()) 50 | .expect("Error loading org language"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /corpus/basic.tst: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Body.1 - Paragraph, no newlines 3 | ================================================================================ 4 | a 5 | -------------------------------------------------------------------------------- 6 | 7 | (document 8 | body: (body 9 | (paragraph 10 | (expr)))) 11 | 12 | ================================================================================ 13 | Body.2 - Paragraph, pre newline 14 | ================================================================================ 15 | 16 | a 17 | -------------------------------------------------------------------------------- 18 | 19 | (document 20 | body: (body 21 | (paragraph 22 | (expr)))) 23 | 24 | ================================================================================ 25 | Body.3 - Paragraph, post newline 26 | ================================================================================ 27 | a 28 | 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (document 33 | body: (body 34 | (paragraph 35 | (expr)))) 36 | 37 | ================================================================================ 38 | Body.4 - Paragraph, pre & post newline 39 | ================================================================================ 40 | 41 | 42 | a 43 | 44 | 45 | -------------------------------------------------------------------------------- 46 | 47 | (document 48 | body: (body 49 | (paragraph 50 | (expr)))) 51 | 52 | ================================================================================ 53 | Body.5 - Multiple elements (paragraphs) 54 | ================================================================================ 55 | a 56 | 57 | a 58 | -------------------------------------------------------------------------------- 59 | 60 | (document 61 | body: (body 62 | (paragraph 63 | (expr)) 64 | (paragraph 65 | (expr)))) 66 | 67 | ================================================================================ 68 | Body.6 - Multiple mixed elements 69 | ================================================================================ 70 | a 71 | 72 | # a 73 | -------------------------------------------------------------------------------- 74 | 75 | (document 76 | body: (body 77 | (paragraph 78 | (expr)) 79 | (comment 80 | (expr)))) 81 | 82 | ================================================================================ 83 | Paragraph.1 - Multiline 84 | ================================================================================ 85 | a 86 | a 87 | 88 | -------------------------------------------------------------------------------- 89 | 90 | (document 91 | body: (body 92 | (paragraph 93 | (expr) 94 | (expr)))) 95 | 96 | ================================================================================ 97 | Paragraph.2 - Many multiline 98 | ================================================================================ 99 | a 100 | a 101 | a 102 | a 103 | a 104 | a 105 | a 106 | a 107 | a 108 | a 109 | a 110 | a 111 | 112 | -------------------------------------------------------------------------------- 113 | 114 | (document 115 | body: (body 116 | (paragraph 117 | (expr) 118 | (expr) 119 | (expr) 120 | (expr) 121 | (expr) 122 | (expr) 123 | (expr) 124 | (expr) 125 | (expr) 126 | (expr) 127 | (expr) 128 | (expr)))) 129 | 130 | ================================================================================ 131 | Paragraph.3 - Multiline & separate 132 | ================================================================================ 133 | 134 | a 135 | a 136 | a 137 | 138 | a 139 | 140 | -------------------------------------------------------------------------------- 141 | 142 | (document 143 | body: (body 144 | (paragraph 145 | (expr) 146 | (expr) 147 | (expr)) 148 | (paragraph 149 | (expr)))) 150 | 151 | ================================================================================ 152 | Paragraph.4 - Multi multiline 153 | ================================================================================ 154 | 155 | a 156 | a 157 | a 158 | 159 | a 160 | a 161 | 162 | -------------------------------------------------------------------------------- 163 | 164 | (document 165 | body: (body 166 | (paragraph 167 | (expr) 168 | (expr) 169 | (expr)) 170 | (paragraph 171 | (expr) 172 | (expr)))) 173 | 174 | ================================================================================ 175 | Footnote.1 - Simple 176 | ================================================================================ 177 | [fn:a] b 178 | -------------------------------------------------------------------------------- 179 | 180 | (document 181 | body: (body 182 | (fndef 183 | label: (expr) 184 | description: (description 185 | (expr))))) 186 | 187 | ================================================================================ 188 | Footnote.2 - Brackets 189 | ================================================================================ 190 | [fn:a]] 191 | -------------------------------------------------------------------------------- 192 | 193 | (document 194 | body: (body 195 | (fndef 196 | label: (expr) 197 | description: (description 198 | (expr))))) 199 | 200 | ================================================================================ 201 | Footnote.3 - Precedence 202 | ================================================================================ 203 | [fn:a] b 204 | :d: 205 | :end: 206 | -------------------------------------------------------------------------------- 207 | 208 | (document 209 | body: (body 210 | (fndef 211 | label: (expr) 212 | description: (description 213 | (expr))) 214 | (drawer 215 | name: (expr)))) 216 | 217 | ================================================================================ 218 | Drawer.1 - Basic 219 | ================================================================================ 220 | :name: 221 | :end: 222 | -------------------------------------------------------------------------------- 223 | 224 | (document 225 | body: (body 226 | (drawer 227 | name: (expr)))) 228 | 229 | ================================================================================ 230 | Drawer.2 - Empty 231 | ================================================================================ 232 | :a: 233 | 234 | :END: 235 | -------------------------------------------------------------------------------- 236 | 237 | (document 238 | body: (body 239 | (drawer 240 | name: (expr) 241 | contents: (contents)))) 242 | 243 | ================================================================================ 244 | Drawer.3 - Multiple 245 | ================================================================================ 246 | :a: 247 | 248 | :END: 249 | 250 | :b: 251 | :END: 252 | -------------------------------------------------------------------------------- 253 | 254 | (document 255 | body: (body 256 | (drawer 257 | name: (expr) 258 | contents: (contents)) 259 | (drawer 260 | name: (expr)))) 261 | 262 | ================================================================================ 263 | Drawer.4 Contents 264 | ================================================================================ 265 | :name: 266 | a 267 | :END: 268 | -------------------------------------------------------------------------------- 269 | 270 | (document 271 | body: (body 272 | (drawer 273 | name: (expr) 274 | contents: (contents 275 | (expr))))) 276 | 277 | ================================================================================ 278 | Drawer.5 - Junk 279 | ================================================================================ 280 | :l 281 | -------------------------------------------------------------------------------- 282 | 283 | (document 284 | body: (body 285 | (paragraph 286 | (expr)))) 287 | 288 | ================================================================================ 289 | Drawer.6a - Junk 290 | ================================================================================ 291 | a 292 | :b 293 | -------------------------------------------------------------------------------- 294 | 295 | (document 296 | body: (body 297 | (paragraph 298 | (expr) 299 | (expr)))) 300 | 301 | ================================================================================ 302 | Drawer.6b - Junk 303 | ================================================================================ 304 | [fn:a] b 305 | :c 306 | -------------------------------------------------------------------------------- 307 | 308 | (document 309 | body: (body 310 | (fndef 311 | label: (expr) 312 | description: (description 313 | (expr) 314 | (expr))))) 315 | 316 | ================================================================================ 317 | Drawer.7 - Junk 318 | ================================================================================ 319 | a 320 | :b 321 | c 322 | -------------------------------------------------------------------------------- 323 | 324 | (document 325 | body: (body 326 | (paragraph 327 | (expr) 328 | (expr) 329 | (expr)))) 330 | 331 | ================================================================================ 332 | Drawer.8 - Junk 333 | ================================================================================ 334 | :a 335 | b 336 | -------------------------------------------------------------------------------- 337 | 338 | (document 339 | body: (body 340 | (paragraph 341 | (expr) 342 | (expr)))) 343 | 344 | ================================================================================ 345 | Block.1 - Empty 346 | ================================================================================ 347 | #+BEGIN_A 348 | #+END_B 349 | -------------------------------------------------------------------------------- 350 | 351 | (document 352 | body: (body 353 | (block 354 | name: (expr) 355 | end_name: (expr)))) 356 | 357 | ================================================================================ 358 | Block.2 - Contents 359 | ================================================================================ 360 | #+BEGIN_SRC ABC 361 | a 362 | #+END_ABC 363 | -------------------------------------------------------------------------------- 364 | 365 | (document 366 | body: (body 367 | (block 368 | name: (expr) 369 | parameter: (expr) 370 | contents: (contents 371 | (expr)) 372 | end_name: (expr)))) 373 | 374 | ================================================================================ 375 | Block.3 - In section 376 | ================================================================================ 377 | * a 378 | 379 | #+BEGIN_SRC ABC 380 | a 381 | #+END_ABC 382 | -------------------------------------------------------------------------------- 383 | 384 | (document 385 | subsection: (section 386 | headline: (headline 387 | stars: (stars) 388 | item: (item 389 | (expr))) 390 | body: (body 391 | (block 392 | name: (expr) 393 | parameter: (expr) 394 | contents: (contents 395 | (expr)) 396 | end_name: (expr))))) 397 | 398 | ================================================================================ 399 | Block.4 - lowercase 400 | ================================================================================ 401 | #+begin_b 402 | #+end_b 403 | -------------------------------------------------------------------------------- 404 | 405 | (document 406 | body: (body 407 | (block 408 | name: (expr) 409 | end_name: (expr)))) 410 | 411 | ================================================================================ 412 | DynamicBlock.1 - Empty 413 | ================================================================================ 414 | #+BEGIN: a b 415 | #+END: 416 | -------------------------------------------------------------------------------- 417 | 418 | (document 419 | body: (body 420 | (dynamic_block 421 | name: (expr) 422 | parameter: (expr)))) 423 | 424 | ================================================================================ 425 | DynamicBlock.2 - Contents 426 | ================================================================================ 427 | #+BEGIN: a 428 | c 429 | #+END: 430 | -------------------------------------------------------------------------------- 431 | 432 | (document 433 | body: (body 434 | (dynamic_block 435 | name: (expr) 436 | contents: (contents 437 | (expr))))) 438 | 439 | ================================================================================ 440 | DynamicBlock.3 - End name 441 | ================================================================================ 442 | #+BEGIN: a 443 | #+END: a 444 | -------------------------------------------------------------------------------- 445 | 446 | (document 447 | body: (body 448 | (dynamic_block 449 | name: (expr) 450 | end_name: (expr)))) 451 | 452 | ================================================================================ 453 | Comment.1 - Basic 454 | ================================================================================ 455 | # a 456 | -------------------------------------------------------------------------------- 457 | 458 | (document 459 | body: (body 460 | (comment 461 | (expr)))) 462 | 463 | ================================================================================ 464 | Comment.2 - Two lines 465 | ================================================================================ 466 | # a 467 | # a 468 | -------------------------------------------------------------------------------- 469 | 470 | (document 471 | body: (body 472 | (comment 473 | (expr) 474 | (expr)))) 475 | 476 | ================================================================================ 477 | Comment.3 - Two separate 478 | ================================================================================ 479 | # a 480 | 481 | # a 482 | -------------------------------------------------------------------------------- 483 | 484 | (document 485 | body: (body 486 | (comment 487 | (expr)) 488 | (comment 489 | (expr)))) 490 | 491 | ================================================================================ 492 | List.1a - Basic: dash [-] 493 | ================================================================================ 494 | - a 495 | -------------------------------------------------------------------------------- 496 | 497 | (document 498 | body: (body 499 | (list 500 | (listitem 501 | bullet: (bullet) 502 | contents: (paragraph 503 | (expr)))))) 504 | 505 | ================================================================================ 506 | List.1c - Basic: star [*] 507 | ================================================================================ 508 | * a 509 | -------------------------------------------------------------------------------- 510 | 511 | (document 512 | body: (body 513 | (list 514 | (listitem 515 | bullet: (bullet) 516 | contents: (paragraph 517 | (expr)))))) 518 | 519 | ================================================================================ 520 | List.1d - Basic: count dot [1.] 521 | ================================================================================ 522 | 1. a 523 | -------------------------------------------------------------------------------- 524 | 525 | (document 526 | body: (body 527 | (list 528 | (listitem 529 | bullet: (bullet) 530 | contents: (paragraph 531 | (expr)))))) 532 | 533 | ================================================================================ 534 | List.1e - Basic: count paren [1)] 535 | ================================================================================ 536 | 1) a 537 | -------------------------------------------------------------------------------- 538 | 539 | (document 540 | body: (body 541 | (list 542 | (listitem 543 | bullet: (bullet) 544 | contents: (paragraph 545 | (expr)))))) 546 | 547 | ================================================================================ 548 | List.1f - Basic: letter dot [a.] 549 | ================================================================================ 550 | a. a 551 | -------------------------------------------------------------------------------- 552 | 553 | (document 554 | body: (body 555 | (list 556 | (listitem 557 | bullet: (bullet) 558 | contents: (paragraph 559 | (expr)))))) 560 | 561 | ================================================================================ 562 | List.1g - Basic: letter paren [a)] 563 | ================================================================================ 564 | a) a 565 | -------------------------------------------------------------------------------- 566 | 567 | (document 568 | body: (body 569 | (list 570 | (listitem 571 | bullet: (bullet) 572 | contents: (paragraph 573 | (expr)))))) 574 | 575 | ================================================================================ 576 | List.2a - two items 577 | ================================================================================ 578 | 579 | - a 580 | - a 581 | 582 | -------------------------------------------------------------------------------- 583 | 584 | (document 585 | body: (body 586 | (list 587 | (listitem 588 | bullet: (bullet) 589 | contents: (paragraph 590 | (expr))) 591 | (listitem 592 | bullet: (bullet) 593 | contents: (paragraph 594 | (expr)))))) 595 | 596 | ================================================================================ 597 | List.2d - two items 598 | ================================================================================ 599 | 600 | 1. a 601 | 2. a 602 | 603 | -------------------------------------------------------------------------------- 604 | 605 | (document 606 | body: (body 607 | (list 608 | (listitem 609 | bullet: (bullet) 610 | contents: (paragraph 611 | (expr))) 612 | (listitem 613 | bullet: (bullet) 614 | contents: (paragraph 615 | (expr)))))) 616 | 617 | ================================================================================ 618 | List.2b - two items 619 | ================================================================================ 620 | 621 | - a 622 | 623 | - a 624 | 625 | -------------------------------------------------------------------------------- 626 | 627 | (document 628 | body: (body 629 | (list 630 | (listitem 631 | bullet: (bullet) 632 | contents: (paragraph 633 | (expr))) 634 | (listitem 635 | bullet: (bullet) 636 | contents: (paragraph 637 | (expr)))))) 638 | 639 | ================================================================================ 640 | List.2c - two lists 641 | ================================================================================ 642 | 643 | - a 644 | 645 | 646 | - a 647 | 648 | -------------------------------------------------------------------------------- 649 | 650 | (document 651 | body: (body 652 | (list 653 | (listitem 654 | bullet: (bullet) 655 | contents: (paragraph 656 | (expr)))) 657 | (list 658 | (listitem 659 | bullet: (bullet) 660 | contents: (paragraph 661 | (expr)))))) 662 | 663 | ================================================================================ 664 | List.3a - sublist 665 | ================================================================================ 666 | 667 | - a 668 | a 669 | - b 670 | a 671 | - a 672 | 673 | -------------------------------------------------------------------------------- 674 | 675 | (document 676 | body: (body 677 | (list 678 | (listitem 679 | bullet: (bullet) 680 | contents: (paragraph 681 | (expr) 682 | (expr)) 683 | contents: (list 684 | (listitem 685 | bullet: (bullet) 686 | contents: (paragraph 687 | (expr)))) 688 | contents: (paragraph 689 | (expr))) 690 | (listitem 691 | bullet: (bullet) 692 | contents: (paragraph 693 | (expr)))))) 694 | 695 | ================================================================================ 696 | List.4a - multiline item 697 | ================================================================================ 698 | 699 | - a 700 | b 701 | 702 | -------------------------------------------------------------------------------- 703 | 704 | (document 705 | body: (body 706 | (list 707 | (listitem 708 | bullet: (bullet) 709 | contents: (paragraph 710 | (expr) 711 | (expr)))))) 712 | 713 | ================================================================================ 714 | List.4b - multiline item 715 | ================================================================================ 716 | 717 | - a 718 | 719 | b 720 | 721 | -------------------------------------------------------------------------------- 722 | 723 | (document 724 | body: (body 725 | (list 726 | (listitem 727 | bullet: (bullet) 728 | contents: (paragraph 729 | (expr)) 730 | contents: (paragraph 731 | (expr)))))) 732 | 733 | ================================================================================ 734 | List.5 - dedent 735 | ================================================================================ 736 | 737 | - a 738 | b 739 | - a 740 | 741 | -------------------------------------------------------------------------------- 742 | 743 | (document 744 | body: (body 745 | (list 746 | (listitem 747 | bullet: (bullet) 748 | contents: (paragraph 749 | (expr)))) 750 | (paragraph 751 | (expr)) 752 | (list 753 | (listitem 754 | bullet: (bullet) 755 | contents: (paragraph 756 | (expr)))))) 757 | 758 | ================================================================================ 759 | List.6 - multi dedent 760 | ================================================================================ 761 | 762 | b 763 | - a 764 | - a 765 | b 766 | 767 | -------------------------------------------------------------------------------- 768 | 769 | (document 770 | body: (body 771 | (paragraph 772 | (expr)) 773 | (list 774 | (listitem 775 | bullet: (bullet) 776 | contents: (paragraph 777 | (expr)) 778 | contents: (list 779 | (listitem 780 | bullet: (bullet) 781 | contents: (paragraph 782 | (expr)))))) 783 | (paragraph 784 | (expr)))) 785 | 786 | ================================================================================ 787 | List.7a - change bullet 788 | ================================================================================ 789 | 790 | - a 791 | + a 792 | 793 | -------------------------------------------------------------------------------- 794 | 795 | (document 796 | body: (body 797 | (list 798 | (listitem 799 | bullet: (bullet) 800 | contents: (paragraph 801 | (expr)))) 802 | (list 803 | (listitem 804 | bullet: (bullet) 805 | contents: (paragraph 806 | (expr)))))) 807 | 808 | ================================================================================ 809 | List.8a - Whitespace 810 | ================================================================================ 811 | - 812 | -------------------------------------------------------------------------------- 813 | 814 | (document 815 | body: (body 816 | (list 817 | (listitem 818 | bullet: (bullet))))) 819 | 820 | ================================================================================ 821 | List.8b - Whitespace after text 822 | ================================================================================ 823 | - a 824 | -------------------------------------------------------------------------------- 825 | 826 | (document 827 | body: (body 828 | (list 829 | (listitem 830 | bullet: (bullet) 831 | contents: (paragraph 832 | (expr)))))) 833 | 834 | ================================================================================ 835 | List.9 - newline before sub listitem 836 | ================================================================================ 837 | - a 838 | 839 | - b 840 | -------------------------------------------------------------------------------- 841 | 842 | (document 843 | body: (body 844 | (list 845 | (listitem 846 | bullet: (bullet) 847 | contents: (paragraph 848 | (expr)) 849 | contents: (list 850 | (listitem 851 | bullet: (bullet) 852 | contents: (paragraph 853 | (expr)))))))) 854 | 855 | ================================================================================ 856 | List.10a - Checkbox [ ] 857 | ================================================================================ 858 | - [ ] a 859 | -------------------------------------------------------------------------------- 860 | 861 | (document 862 | body: (body 863 | (list 864 | (listitem 865 | bullet: (bullet) 866 | checkbox: (checkbox) 867 | contents: (paragraph 868 | (expr)))))) 869 | 870 | ================================================================================ 871 | List.10b - Checkbox [x] 872 | ================================================================================ 873 | - [x] a 874 | -------------------------------------------------------------------------------- 875 | 876 | (document 877 | body: (body 878 | (list 879 | (listitem 880 | bullet: (bullet) 881 | checkbox: (checkbox 882 | status: (expr)) 883 | contents: (paragraph 884 | (expr)))))) 885 | 886 | ================================================================================ 887 | List.10c - Checkbox [X] 888 | ================================================================================ 889 | - [X] a 890 | -------------------------------------------------------------------------------- 891 | 892 | (document 893 | body: (body 894 | (list 895 | (listitem 896 | bullet: (bullet) 897 | checkbox: (checkbox 898 | status: (expr)) 899 | contents: (paragraph 900 | (expr)))))) 901 | 902 | ================================================================================ 903 | List.10d - Checkbox [-] 904 | ================================================================================ 905 | - [-] a 906 | -------------------------------------------------------------------------------- 907 | 908 | (document 909 | body: (body 910 | (list 911 | (listitem 912 | bullet: (bullet) 913 | checkbox: (checkbox 914 | status: (expr)) 915 | contents: (paragraph 916 | (expr)))))) 917 | 918 | ================================================================================ 919 | List.10e - Checkbox [done] 920 | ================================================================================ 921 | - [done] a 922 | -------------------------------------------------------------------------------- 923 | 924 | (document 925 | body: (body 926 | (list 927 | (listitem 928 | bullet: (bullet) 929 | checkbox: (checkbox 930 | status: (expr)) 931 | contents: (paragraph 932 | (expr)))))) 933 | 934 | ================================================================================ 935 | List.11a - No Checkbox markup 936 | ================================================================================ 937 | - +[ ] a+ 938 | -------------------------------------------------------------------------------- 939 | 940 | (document 941 | body: (body 942 | (list 943 | (listitem 944 | bullet: (bullet) 945 | contents: (paragraph 946 | (expr) 947 | (expr) 948 | (expr)))))) 949 | 950 | ================================================================================ 951 | List.11b - No Checkbox [ a 952 | ================================================================================ 953 | - [ a 954 | -------------------------------------------------------------------------------- 955 | 956 | (document 957 | body: (body 958 | (list 959 | (listitem 960 | bullet: (bullet) 961 | contents: (paragraph 962 | (expr) 963 | (expr)))))) 964 | 965 | ================================================================================ 966 | List.11c - No Checkbox [ ] 967 | ================================================================================ 968 | - [ ] 969 | -------------------------------------------------------------------------------- 970 | 971 | (document 972 | body: (body 973 | (list 974 | (listitem 975 | bullet: (bullet) 976 | contents: (paragraph 977 | (expr) 978 | (expr)))))) 979 | 980 | ================================================================================ 981 | List.11d - No Checkbox [- 982 | ================================================================================ 983 | - [- a] 984 | -------------------------------------------------------------------------------- 985 | 986 | (document 987 | body: (body 988 | (list 989 | (listitem 990 | bullet: (bullet) 991 | contents: (paragraph 992 | (expr) 993 | (expr)))))) 994 | 995 | ================================================================================ 996 | List.11e - No Checkbox [x 997 | ================================================================================ 998 | - [x b] 999 | -------------------------------------------------------------------------------- 1000 | 1001 | (document 1002 | body: (body 1003 | (list 1004 | (listitem 1005 | bullet: (bullet) 1006 | contents: (paragraph 1007 | (expr) 1008 | (expr)))))) 1009 | 1010 | ================================================================================ 1011 | List.11f - No Checkbox [x1] 1012 | ================================================================================ 1013 | - [x1] 1014 | -------------------------------------------------------------------------------- 1015 | 1016 | (document 1017 | body: (body 1018 | (list 1019 | (listitem 1020 | bullet: (bullet) 1021 | contents: (paragraph 1022 | (expr)))))) 1023 | 1024 | ================================================================================ 1025 | Directive.1 - Document 1026 | ================================================================================ 1027 | #+a: b 1028 | 1029 | -------------------------------------------------------------------------------- 1030 | 1031 | (document 1032 | body: (body 1033 | directive: (directive 1034 | name: (expr) 1035 | value: (value 1036 | (expr))))) 1037 | 1038 | ================================================================================ 1039 | Directive.2 - Bare 1040 | ================================================================================ 1041 | 1042 | #+a: b 1043 | -------------------------------------------------------------------------------- 1044 | 1045 | (document 1046 | body: (body 1047 | directive: (directive 1048 | name: (expr) 1049 | value: (value 1050 | (expr))))) 1051 | 1052 | ================================================================================ 1053 | Directive.3 - Doc & Bare 1054 | ================================================================================ 1055 | #+a: b 1056 | 1057 | #+a: b 1058 | -------------------------------------------------------------------------------- 1059 | 1060 | (document 1061 | body: (body 1062 | directive: (directive 1063 | name: (expr) 1064 | value: (value 1065 | (expr))) 1066 | directive: (directive 1067 | name: (expr) 1068 | value: (value 1069 | (expr))))) 1070 | 1071 | ================================================================================ 1072 | Directive.4a - Attached 1073 | ================================================================================ 1074 | 1075 | #+a: b 1076 | c 1077 | -------------------------------------------------------------------------------- 1078 | 1079 | (document 1080 | body: (body 1081 | (paragraph 1082 | directive: (directive 1083 | name: (expr) 1084 | value: (value 1085 | (expr))) 1086 | (expr)))) 1087 | 1088 | ================================================================================ 1089 | Directive.4b - Attached 1090 | ================================================================================ 1091 | #+a: b 1092 | c 1093 | -------------------------------------------------------------------------------- 1094 | 1095 | (document 1096 | body: (body 1097 | (paragraph 1098 | directive: (directive 1099 | name: (expr) 1100 | value: (value 1101 | (expr))) 1102 | (expr)))) 1103 | 1104 | ================================================================================ 1105 | Directive.5 - No empty lines 1106 | ================================================================================ 1107 | * a 1108 | #+a: b 1109 | c 1110 | -------------------------------------------------------------------------------- 1111 | 1112 | (document 1113 | subsection: (section 1114 | headline: (headline 1115 | stars: (stars) 1116 | item: (item 1117 | (expr))) 1118 | body: (body 1119 | (paragraph 1120 | directive: (directive 1121 | name: (expr) 1122 | value: (value 1123 | (expr))) 1124 | (expr))))) 1125 | 1126 | ================================================================================ 1127 | Directive.6a - List 1128 | ================================================================================ 1129 | 1130 | #+a: b 1131 | - c 1132 | -------------------------------------------------------------------------------- 1133 | 1134 | (document 1135 | body: (body 1136 | (list 1137 | directive: (directive 1138 | name: (expr) 1139 | value: (value 1140 | (expr))) 1141 | (listitem 1142 | bullet: (bullet) 1143 | contents: (paragraph 1144 | (expr)))))) 1145 | 1146 | ================================================================================ 1147 | Directive.6b - Sublist 1148 | ================================================================================ 1149 | 1150 | #+a: b 1151 | - c 1152 | #+a: b 1153 | - c 1154 | 1155 | -------------------------------------------------------------------------------- 1156 | 1157 | (document 1158 | body: (body 1159 | (list 1160 | directive: (directive 1161 | name: (expr) 1162 | value: (value 1163 | (expr))) 1164 | (listitem 1165 | bullet: (bullet) 1166 | contents: (paragraph 1167 | (expr)) 1168 | contents: (list 1169 | directive: (directive 1170 | name: (expr) 1171 | value: (value 1172 | (expr))) 1173 | (listitem 1174 | bullet: (bullet) 1175 | contents: (paragraph 1176 | (expr)))))))) 1177 | 1178 | ================================================================================ 1179 | Directive.7 - Directive unrelated to section 1180 | ================================================================================ 1181 | 1182 | #+a: b 1183 | * c 1184 | -------------------------------------------------------------------------------- 1185 | 1186 | (document 1187 | body: (body 1188 | directive: (directive 1189 | name: (expr) 1190 | value: (value 1191 | (expr)))) 1192 | subsection: (section 1193 | headline: (headline 1194 | stars: (stars) 1195 | item: (item 1196 | (expr))))) 1197 | 1198 | ================================================================================ 1199 | LatexEnv.1a - Basic 1200 | ================================================================================ 1201 | \begin{a*} 1202 | \end{a*} 1203 | 1204 | -------------------------------------------------------------------------------- 1205 | 1206 | (document 1207 | body: (body 1208 | (latex_env 1209 | name: (name) 1210 | (name)))) 1211 | 1212 | ================================================================================ 1213 | LatexEnv.1b - Basic 1214 | ================================================================================ 1215 | \( 1216 | \) 1217 | 1218 | -------------------------------------------------------------------------------- 1219 | 1220 | (document 1221 | body: (body 1222 | (latex_env))) 1223 | 1224 | ================================================================================ 1225 | LatexEnv.1c - Basic 1226 | ================================================================================ 1227 | \[ 1228 | \] 1229 | 1230 | -------------------------------------------------------------------------------- 1231 | 1232 | (document 1233 | body: (body 1234 | (latex_env))) 1235 | 1236 | ================================================================================ 1237 | LatexEnv.2 - Contents 1238 | ================================================================================ 1239 | \begin{a1} 1240 | a 1241 | \end{1a} 1242 | -------------------------------------------------------------------------------- 1243 | 1244 | (document 1245 | body: (body 1246 | (latex_env 1247 | name: (name) 1248 | contents: (contents 1249 | (expr)) 1250 | (name)))) 1251 | 1252 | ================================================================================ 1253 | LatexEnv.2b - Contents 1254 | ================================================================================ 1255 | \( 1256 | a 1257 | \) 1258 | 1259 | -------------------------------------------------------------------------------- 1260 | 1261 | (document 1262 | body: (body 1263 | (latex_env 1264 | contents: (contents 1265 | (expr))))) 1266 | 1267 | ================================================================================ 1268 | LatexEnv.2c - Contents 1269 | ================================================================================ 1270 | \[ 1271 | a 1272 | \] 1273 | 1274 | -------------------------------------------------------------------------------- 1275 | 1276 | (document 1277 | body: (body 1278 | (latex_env 1279 | contents: (contents 1280 | (expr))))) 1281 | 1282 | ================================================================================ 1283 | LatexEnv.3 - Empty 1284 | ================================================================================ 1285 | \begin{a} 1286 | 1287 | \end{a} 1288 | -------------------------------------------------------------------------------- 1289 | 1290 | (document 1291 | body: (body 1292 | (latex_env 1293 | name: (name) 1294 | contents: (contents) 1295 | (name)))) 1296 | 1297 | ================================================================================ 1298 | LatexEnv.4a - Pre nl 1299 | ================================================================================ 1300 | \begin{a} 1301 | 1302 | a 1303 | \end{a} 1304 | -------------------------------------------------------------------------------- 1305 | 1306 | (document 1307 | body: (body 1308 | (latex_env 1309 | name: (name) 1310 | contents: (contents 1311 | (expr)) 1312 | (name)))) 1313 | 1314 | ================================================================================ 1315 | LatexEnv.4b - Post nl 1316 | ================================================================================ 1317 | \begin{a} 1318 | a 1319 | 1320 | \end{a} 1321 | -------------------------------------------------------------------------------- 1322 | 1323 | (document 1324 | body: (body 1325 | (latex_env 1326 | name: (name) 1327 | contents: (contents 1328 | (expr)) 1329 | (name)))) 1330 | 1331 | ================================================================================ 1332 | LatexEnv.4c - Spare nls 1333 | ================================================================================ 1334 | \begin{a} 1335 | 1336 | a 1337 | 1338 | \end{a} 1339 | -------------------------------------------------------------------------------- 1340 | 1341 | (document 1342 | body: (body 1343 | (latex_env 1344 | name: (name) 1345 | contents: (contents 1346 | (expr)) 1347 | (name)))) 1348 | 1349 | ================================================================================ 1350 | LatexEnv.5 - Uppercase 1351 | ================================================================================ 1352 | \begin{a} 1353 | \end{a} 1354 | 1355 | -------------------------------------------------------------------------------- 1356 | 1357 | (document 1358 | body: (body 1359 | (latex_env 1360 | name: (name) 1361 | (name)))) 1362 | 1363 | ================================================================================ 1364 | LatexEnv.6a - Junk 1365 | ================================================================================ 1366 | \( a \) b 1367 | -------------------------------------------------------------------------------- 1368 | 1369 | (document 1370 | body: (body 1371 | (paragraph 1372 | (expr) 1373 | (expr) 1374 | (expr) 1375 | (expr)))) 1376 | 1377 | ================================================================================ 1378 | LatexEnv.6b - Junk 1379 | ================================================================================ 1380 | \( \) 1381 | -------------------------------------------------------------------------------- 1382 | 1383 | (document 1384 | body: (body 1385 | (paragraph 1386 | (expr) 1387 | (expr)))) 1388 | 1389 | ================================================================================ 1390 | Precedence.1 - Paragraph comment 1391 | ================================================================================ 1392 | a 1393 | # a 1394 | -------------------------------------------------------------------------------- 1395 | 1396 | (document 1397 | body: (body 1398 | (paragraph 1399 | (expr)) 1400 | (comment 1401 | (expr)))) 1402 | 1403 | ================================================================================ 1404 | Precedence.2 - Paragraph comment paragraph 1405 | ================================================================================ 1406 | a 1407 | # a 1408 | a 1409 | -------------------------------------------------------------------------------- 1410 | 1411 | (document 1412 | body: (body 1413 | (paragraph 1414 | (expr)) 1415 | (comment 1416 | (expr)) 1417 | (paragraph 1418 | (expr)))) 1419 | 1420 | ================================================================================ 1421 | Precedence.3 - Comment paragraph 1422 | ================================================================================ 1423 | # a 1424 | a 1425 | -------------------------------------------------------------------------------- 1426 | 1427 | (document 1428 | body: (body 1429 | (comment 1430 | (expr)) 1431 | (paragraph 1432 | (expr)))) 1433 | 1434 | ================================================================================ 1435 | Precedence.4 - Paragraph drawer 1436 | ================================================================================ 1437 | a 1438 | :AB: 1439 | c 1440 | :END: 1441 | -------------------------------------------------------------------------------- 1442 | 1443 | (document 1444 | body: (body 1445 | (paragraph 1446 | (expr)) 1447 | (drawer 1448 | name: (expr) 1449 | contents: (contents 1450 | (expr))))) 1451 | 1452 | ================================================================================ 1453 | Precedence.5 - Comment paragraph drawer 1454 | ================================================================================ 1455 | # a 1456 | b 1457 | :c: 1458 | d 1459 | :end: 1460 | -------------------------------------------------------------------------------- 1461 | 1462 | (document 1463 | body: (body 1464 | (comment 1465 | (expr)) 1466 | (paragraph 1467 | (expr)) 1468 | (drawer 1469 | name: (expr) 1470 | contents: (contents 1471 | (expr))))) 1472 | 1473 | ================================================================================ 1474 | Table.1 - 1x1 1475 | ================================================================================ 1476 | |a| 1477 | -------------------------------------------------------------------------------- 1478 | 1479 | (document 1480 | body: (body 1481 | (table 1482 | (row 1483 | (cell 1484 | contents: (contents 1485 | (expr))))))) 1486 | 1487 | ================================================================================ 1488 | Table.2 - 1x2 1489 | ================================================================================ 1490 | |a|b c| 1491 | -------------------------------------------------------------------------------- 1492 | 1493 | (document 1494 | body: (body 1495 | (table 1496 | (row 1497 | (cell 1498 | contents: (contents 1499 | (expr))) 1500 | (cell 1501 | contents: (contents 1502 | (expr) 1503 | (expr))))))) 1504 | 1505 | ================================================================================ 1506 | Table.3 - 2x2 1507 | ================================================================================ 1508 | |a|b| 1509 | |c|d| 1510 | -------------------------------------------------------------------------------- 1511 | 1512 | (document 1513 | body: (body 1514 | (table 1515 | (row 1516 | (cell 1517 | contents: (contents 1518 | (expr))) 1519 | (cell 1520 | contents: (contents 1521 | (expr)))) 1522 | (row 1523 | (cell 1524 | contents: (contents 1525 | (expr))) 1526 | (cell 1527 | contents: (contents 1528 | (expr))))))) 1529 | 1530 | ================================================================================ 1531 | Table.4 - empty cell 1532 | ================================================================================ 1533 | |a|b| 1534 | | |d| 1535 | -------------------------------------------------------------------------------- 1536 | 1537 | (document 1538 | body: (body 1539 | (table 1540 | (row 1541 | (cell 1542 | contents: (contents 1543 | (expr))) 1544 | (cell 1545 | contents: (contents 1546 | (expr)))) 1547 | (row 1548 | (cell) 1549 | (cell 1550 | contents: (contents 1551 | (expr))))))) 1552 | 1553 | ================================================================================ 1554 | Table.5 - empty cells 1555 | ================================================================================ 1556 | || | 1557 | -------------------------------------------------------------------------------- 1558 | 1559 | (document 1560 | body: (body 1561 | (table 1562 | (row 1563 | (cell) 1564 | (cell))))) 1565 | 1566 | ================================================================================ 1567 | Table.6 - simple hr 1568 | ================================================================================ 1569 | |-| 1570 | -------------------------------------------------------------------------------- 1571 | 1572 | (document 1573 | body: (body 1574 | (table 1575 | (hr)))) 1576 | 1577 | ================================================================================ 1578 | Table.7 - words 1579 | ================================================================================ 1580 | |a | b | c| 1581 | |--+---+---| 1582 | |Some words about | something | 1583 | -------------------------------------------------------------------------------- 1584 | 1585 | (document 1586 | body: (body 1587 | (table 1588 | (row 1589 | (cell 1590 | contents: (contents 1591 | (expr))) 1592 | (cell 1593 | contents: (contents 1594 | (expr))) 1595 | (cell 1596 | contents: (contents 1597 | (expr)))) 1598 | (hr) 1599 | (row 1600 | (cell 1601 | contents: (contents 1602 | (expr) 1603 | (expr) 1604 | (expr))) 1605 | (cell 1606 | contents: (contents 1607 | (expr))))))) 1608 | 1609 | ================================================================================ 1610 | Table.8 - Formula 1611 | ================================================================================ 1612 | |a| 1613 | #+TBLFM: ab cd ef gh 1614 | 1615 | -------------------------------------------------------------------------------- 1616 | 1617 | (document 1618 | body: (body 1619 | (table 1620 | (row 1621 | (cell 1622 | contents: (contents 1623 | (expr)))) 1624 | (formula 1625 | formula: (expr) 1626 | formula: (expr) 1627 | formula: (expr) 1628 | formula: (expr))))) 1629 | 1630 | ================================================================================ 1631 | Table.9 - Multiple formula 1632 | ================================================================================ 1633 | |a| 1634 | #+TBLFM: ab cd ef gh1 1635 | #+TBLFM: ab cd ef gh2 1636 | #+TBLFM: ab cd ef gh3 1637 | 1638 | -------------------------------------------------------------------------------- 1639 | 1640 | (document 1641 | body: (body 1642 | (table 1643 | (row 1644 | (cell 1645 | contents: (contents 1646 | (expr)))) 1647 | (formula 1648 | formula: (expr) 1649 | formula: (expr) 1650 | formula: (expr) 1651 | formula: (expr)) 1652 | (formula 1653 | formula: (expr) 1654 | formula: (expr) 1655 | formula: (expr) 1656 | formula: (expr)) 1657 | (formula 1658 | formula: (expr) 1659 | formula: (expr) 1660 | formula: (expr) 1661 | formula: (expr))))) 1662 | 1663 | ================================================================================ 1664 | Table.10 - Multiline 1665 | ================================================================================ 1666 | 1667 | | 1 | 1668 | | 2 | 1669 | | 3 | 1670 | | 4 | 1671 | | 5 | 1672 | | 6 | 1673 | 1674 | -------------------------------------------------------------------------------- 1675 | 1676 | (document 1677 | body: (body 1678 | (table 1679 | (row 1680 | (cell 1681 | contents: (contents 1682 | (expr)))) 1683 | (row 1684 | (cell 1685 | contents: (contents 1686 | (expr)))) 1687 | (row 1688 | (cell 1689 | contents: (contents 1690 | (expr)))) 1691 | (row 1692 | (cell 1693 | contents: (contents 1694 | (expr)))) 1695 | (row 1696 | (cell 1697 | contents: (contents 1698 | (expr)))) 1699 | (row 1700 | (cell 1701 | contents: (contents 1702 | (expr))))))) 1703 | 1704 | ================================================================================ 1705 | Table.11 - Cell contents with '-' 1706 | ================================================================================ 1707 | 1708 | | - | 1709 | 1710 | -------------------------------------------------------------------------------- 1711 | 1712 | (document 1713 | body: (body 1714 | (table 1715 | (row 1716 | (cell 1717 | contents: (contents 1718 | (expr))))))) 1719 | 1720 | ================================================================================ 1721 | Headlines.1a - No eols 1722 | ================================================================================ 1723 | * l1 1724 | -------------------------------------------------------------------------------- 1725 | 1726 | (document 1727 | subsection: (section 1728 | headline: (headline 1729 | stars: (stars) 1730 | item: (item 1731 | (expr))))) 1732 | 1733 | ================================================================================ 1734 | Headlines.1b - pre eol body 1735 | ================================================================================ 1736 | 1737 | * l1 1738 | -------------------------------------------------------------------------------- 1739 | 1740 | (document 1741 | body: (body) 1742 | subsection: (section 1743 | headline: (headline 1744 | stars: (stars) 1745 | item: (item 1746 | (expr))))) 1747 | 1748 | ================================================================================ 1749 | Headlines.1c - Post eols (body) (ts-test strips 1 nl, 2 required here) 1750 | ================================================================================ 1751 | * l1 1752 | 1753 | 1754 | -------------------------------------------------------------------------------- 1755 | 1756 | (document 1757 | subsection: (section 1758 | headline: (headline 1759 | stars: (stars) 1760 | item: (item 1761 | (expr))) 1762 | body: (body))) 1763 | 1764 | ================================================================================ 1765 | Headlines.2 - level 2 1766 | ================================================================================ 1767 | ** l2 1768 | -------------------------------------------------------------------------------- 1769 | 1770 | (document 1771 | subsection: (section 1772 | headline: (headline 1773 | stars: (stars) 1774 | item: (item 1775 | (expr))))) 1776 | 1777 | ================================================================================ 1778 | Headlines.3a - Two sections 1779 | ================================================================================ 1780 | * l1 1781 | * l1 1782 | 1783 | -------------------------------------------------------------------------------- 1784 | 1785 | (document 1786 | subsection: (section 1787 | headline: (headline 1788 | stars: (stars) 1789 | item: (item 1790 | (expr)))) 1791 | subsection: (section 1792 | headline: (headline 1793 | stars: (stars) 1794 | item: (item 1795 | (expr))))) 1796 | 1797 | ================================================================================ 1798 | Headlines.3b - Two sections, body 1799 | ================================================================================ 1800 | * l1 1801 | 1802 | * l1 1803 | -------------------------------------------------------------------------------- 1804 | 1805 | (document 1806 | subsection: (section 1807 | headline: (headline 1808 | stars: (stars) 1809 | item: (item 1810 | (expr))) 1811 | body: (body)) 1812 | subsection: (section 1813 | headline: (headline 1814 | stars: (stars) 1815 | item: (item 1816 | (expr))))) 1817 | 1818 | ================================================================================ 1819 | Headlines.4 - Subsection 1820 | ================================================================================ 1821 | * l1 1822 | ** l2 1823 | 1824 | -------------------------------------------------------------------------------- 1825 | 1826 | (document 1827 | subsection: (section 1828 | headline: (headline 1829 | stars: (stars) 1830 | item: (item 1831 | (expr))) 1832 | subsection: (section 1833 | headline: (headline 1834 | stars: (stars) 1835 | item: (item 1836 | (expr)))))) 1837 | 1838 | ================================================================================ 1839 | Headlines.4a - Subsection bodies 1840 | ================================================================================ 1841 | * l1 1842 | 1843 | ** l2 1844 | 1845 | 1846 | -------------------------------------------------------------------------------- 1847 | 1848 | (document 1849 | subsection: (section 1850 | headline: (headline 1851 | stars: (stars) 1852 | item: (item 1853 | (expr))) 1854 | body: (body) 1855 | subsection: (section 1856 | headline: (headline 1857 | stars: (stars) 1858 | item: (item 1859 | (expr))) 1860 | body: (body)))) 1861 | 1862 | ================================================================================ 1863 | Headlines.5 - Subsection & continued section 1864 | ================================================================================ 1865 | * l1 1866 | ** l2 1867 | * l1 1868 | -------------------------------------------------------------------------------- 1869 | 1870 | (document 1871 | subsection: (section 1872 | headline: (headline 1873 | stars: (stars) 1874 | item: (item 1875 | (expr))) 1876 | subsection: (section 1877 | headline: (headline 1878 | stars: (stars) 1879 | item: (item 1880 | (expr))))) 1881 | subsection: (section 1882 | headline: (headline 1883 | stars: (stars) 1884 | item: (item 1885 | (expr))))) 1886 | 1887 | ================================================================================ 1888 | Headlines.6 - Top high level section 1889 | ================================================================================ 1890 | *** l3 1891 | * l1 1892 | -------------------------------------------------------------------------------- 1893 | 1894 | (document 1895 | subsection: (section 1896 | headline: (headline 1897 | stars: (stars) 1898 | item: (item 1899 | (expr)))) 1900 | subsection: (section 1901 | headline: (headline 1902 | stars: (stars) 1903 | item: (item 1904 | (expr))))) 1905 | 1906 | ================================================================================ 1907 | Headlines.7a - Item/tag junk 1908 | ================================================================================ 1909 | * a: b 1910 | -------------------------------------------------------------------------------- 1911 | 1912 | (document 1913 | subsection: (section 1914 | headline: (headline 1915 | stars: (stars) 1916 | item: (item 1917 | (expr) 1918 | (expr))))) 1919 | 1920 | ================================================================================ 1921 | Headlines.7b - Item/tag junk 1922 | ================================================================================ 1923 | * a: b: 1924 | -------------------------------------------------------------------------------- 1925 | 1926 | (document 1927 | subsection: (section 1928 | headline: (headline 1929 | stars: (stars) 1930 | item: (item 1931 | (expr) 1932 | (expr))))) 1933 | 1934 | ================================================================================ 1935 | Headlines.8a - Tag 1936 | ================================================================================ 1937 | * a :b: 1938 | -------------------------------------------------------------------------------- 1939 | 1940 | (document 1941 | subsection: (section 1942 | headline: (headline 1943 | stars: (stars) 1944 | item: (item 1945 | (expr)) 1946 | tags: (tag_list 1947 | tag: (tag))))) 1948 | 1949 | ================================================================================ 1950 | Headlines.8b - Multitag 1951 | ================================================================================ 1952 | * a :b:c: 1953 | -------------------------------------------------------------------------------- 1954 | 1955 | (document 1956 | subsection: (section 1957 | headline: (headline 1958 | stars: (stars) 1959 | item: (item 1960 | (expr)) 1961 | tags: (tag_list 1962 | tag: (tag) 1963 | tag: (tag))))) 1964 | 1965 | ================================================================================ 1966 | Headlines.8c - Junk 1967 | ================================================================================ 1968 | * a :b: c: 1969 | -------------------------------------------------------------------------------- 1970 | 1971 | (document 1972 | subsection: (section 1973 | headline: (headline 1974 | stars: (stars) 1975 | item: (item 1976 | (expr) 1977 | (expr) 1978 | (expr))))) 1979 | 1980 | ================================================================================ 1981 | Headlines.8d - Junk 1982 | ================================================================================ 1983 | * :a: b 1984 | -------------------------------------------------------------------------------- 1985 | 1986 | (document 1987 | subsection: (section 1988 | headline: (headline 1989 | stars: (stars) 1990 | item: (item 1991 | (expr) 1992 | (expr))))) 1993 | 1994 | ================================================================================ 1995 | Headlines.8e - Junk 1996 | ================================================================================ 1997 | * :a b: 1998 | -------------------------------------------------------------------------------- 1999 | 2000 | (document 2001 | subsection: (section 2002 | headline: (headline 2003 | stars: (stars) 2004 | item: (item 2005 | (expr) 2006 | (expr))))) 2007 | 2008 | ================================================================================ 2009 | Section.1 - paragraph not a plan 2010 | ================================================================================ 2011 | * a 2012 | b 2013 | -------------------------------------------------------------------------------- 2014 | 2015 | (document 2016 | subsection: (section 2017 | headline: (headline 2018 | stars: (stars) 2019 | item: (item 2020 | (expr))) 2021 | body: (body 2022 | (paragraph 2023 | (expr))))) 2024 | 2025 | ================================================================================ 2026 | Properties.1 - one char name 2027 | ================================================================================ 2028 | * b 2029 | :PROPERTIES: 2030 | :a: c b 2031 | :END: 2032 | -------------------------------------------------------------------------------- 2033 | 2034 | (document 2035 | subsection: (section 2036 | headline: (headline 2037 | stars: (stars) 2038 | item: (item 2039 | (expr))) 2040 | property_drawer: (property_drawer 2041 | (property 2042 | name: (expr) 2043 | value: (value 2044 | (expr) 2045 | (expr)))))) 2046 | 2047 | ================================================================================ 2048 | Properties.2 - simple 2049 | ================================================================================ 2050 | * C 2051 | :PROPERTIES: 2052 | :ab: 3 2053 | :END: 2054 | 2055 | -------------------------------------------------------------------------------- 2056 | 2057 | (document 2058 | subsection: (section 2059 | headline: (headline 2060 | stars: (stars) 2061 | item: (item 2062 | (expr))) 2063 | property_drawer: (property_drawer 2064 | (property 2065 | name: (expr) 2066 | value: (value 2067 | (expr)))))) 2068 | 2069 | ================================================================================ 2070 | Properties.3 - Lowercase 2071 | ================================================================================ 2072 | * a 2073 | :properties: 2074 | :a: b 2075 | :end: 2076 | 2077 | -------------------------------------------------------------------------------- 2078 | 2079 | (document 2080 | subsection: (section 2081 | headline: (headline 2082 | stars: (stars) 2083 | item: (item 2084 | (expr))) 2085 | property_drawer: (property_drawer 2086 | (property 2087 | name: (expr) 2088 | value: (value 2089 | (expr)))))) 2090 | 2091 | ================================================================================ 2092 | Plan.1 - Basic 2093 | ================================================================================ 2094 | * a 2095 | <1-1-1 a> 2096 | -------------------------------------------------------------------------------- 2097 | 2098 | (document 2099 | subsection: (section 2100 | headline: (headline 2101 | stars: (stars) 2102 | item: (item 2103 | (expr))) 2104 | plan: (plan 2105 | (entry 2106 | timestamp: (timestamp 2107 | date: (date) 2108 | day: (day)))))) 2109 | 2110 | ================================================================================ 2111 | Plan.2 - Repeater 2112 | ================================================================================ 2113 | * a 2114 | <1-1-1 a +1h> 2115 | -------------------------------------------------------------------------------- 2116 | 2117 | (document 2118 | subsection: (section 2119 | headline: (headline 2120 | stars: (stars) 2121 | item: (item 2122 | (expr))) 2123 | plan: (plan 2124 | (entry 2125 | timestamp: (timestamp 2126 | date: (date) 2127 | day: (day) 2128 | repeat: (repeat)))))) 2129 | 2130 | ================================================================================ 2131 | Plan.3 - Delay 2132 | ================================================================================ 2133 | * a 2134 | <1-1-1 a -1d> 2135 | -------------------------------------------------------------------------------- 2136 | 2137 | (document 2138 | subsection: (section 2139 | headline: (headline 2140 | stars: (stars) 2141 | item: (item 2142 | (expr))) 2143 | plan: (plan 2144 | (entry 2145 | timestamp: (timestamp 2146 | date: (date) 2147 | day: (day) 2148 | delay: (delay)))))) 2149 | 2150 | ================================================================================ 2151 | Plan.4 - Repdel 2152 | ================================================================================ 2153 | * a 2154 | <1-1-1 a +1w -1m> 2155 | -------------------------------------------------------------------------------- 2156 | 2157 | (document 2158 | subsection: (section 2159 | headline: (headline 2160 | stars: (stars) 2161 | item: (item 2162 | (expr))) 2163 | plan: (plan 2164 | (entry 2165 | timestamp: (timestamp 2166 | date: (date) 2167 | day: (day) 2168 | repeat: (repeat) 2169 | delay: (delay)))))) 2170 | 2171 | ================================================================================ 2172 | Plan.5 - Time 2173 | ================================================================================ 2174 | * a 2175 | <1-1-1 a 1:11> 2176 | -------------------------------------------------------------------------------- 2177 | 2178 | (document 2179 | subsection: (section 2180 | headline: (headline 2181 | stars: (stars) 2182 | item: (item 2183 | (expr))) 2184 | plan: (plan 2185 | (entry 2186 | timestamp: (timestamp 2187 | date: (date) 2188 | day: (day) 2189 | time: (time)))))) 2190 | 2191 | ================================================================================ 2192 | Plan.6 - Time range 2193 | ================================================================================ 2194 | * a 2195 | <1-1-1 1:11-11:11> 2196 | 2197 | -------------------------------------------------------------------------------- 2198 | 2199 | (document 2200 | subsection: (section 2201 | headline: (headline 2202 | stars: (stars) 2203 | item: (item 2204 | (expr))) 2205 | plan: (plan 2206 | (entry 2207 | timestamp: (timestamp 2208 | date: (date) 2209 | duration: (duration)))))) 2210 | 2211 | ================================================================================ 2212 | Plan.7 - Date range 2213 | ================================================================================ 2214 | * a 2215 | <1-1-1>--<1-1-1> 2216 | -------------------------------------------------------------------------------- 2217 | 2218 | (document 2219 | subsection: (section 2220 | headline: (headline 2221 | stars: (stars) 2222 | item: (item 2223 | (expr))) 2224 | plan: (plan 2225 | (entry 2226 | timestamp: (timestamp 2227 | date: (date) 2228 | date: (date)))))) 2229 | 2230 | ================================================================================ 2231 | Plan.8a - Junk 2232 | ================================================================================ 2233 | * a 2234 | [if there are letters only] 2235 | -------------------------------------------------------------------------------- 2236 | 2237 | (document 2238 | subsection: (section 2239 | headline: (headline 2240 | stars: (stars) 2241 | item: (item 2242 | (expr))) 2243 | body: (body 2244 | (paragraph 2245 | (expr) 2246 | (expr) 2247 | (expr) 2248 | (expr) 2249 | (expr))))) 2250 | 2251 | ================================================================================ 2252 | Plan.8b - Junk 2253 | ================================================================================ 2254 | * a 2255 | 2256 | -------------------------------------------------------------------------------- 2257 | 2258 | (document 2259 | subsection: (section 2260 | headline: (headline 2261 | stars: (stars) 2262 | item: (item 2263 | (expr))) 2264 | body: (body 2265 | (paragraph 2266 | (expr))))) 2267 | 2268 | ================================================================================ 2269 | Plan.9 - TsExpression 2270 | ================================================================================ 2271 | * a 2272 | <%%(b)> [%%c] 2273 | -------------------------------------------------------------------------------- 2274 | 2275 | (document 2276 | subsection: (section 2277 | headline: (headline 2278 | stars: (stars) 2279 | item: (item 2280 | (expr))) 2281 | plan: (plan 2282 | (entry 2283 | timestamp: (timestamp 2284 | (tsexp 2285 | (expr)))) 2286 | (entry 2287 | timestamp: (timestamp 2288 | (tsexp 2289 | (expr))))))) 2290 | 2291 | ================================================================================ 2292 | Plan.10 - inactive 2293 | ================================================================================ 2294 | * h 2295 | [1111-11-11 Day] 2296 | -------------------------------------------------------------------------------- 2297 | 2298 | (document 2299 | subsection: (section 2300 | headline: (headline 2301 | stars: (stars) 2302 | item: (item 2303 | (expr))) 2304 | plan: (plan 2305 | (entry 2306 | timestamp: (timestamp 2307 | date: (date) 2308 | day: (day)))))) 2309 | 2310 | ================================================================================ 2311 | Plan.11 - scheduled 2312 | ================================================================================ 2313 | * headline 2314 | a: <1111-11-11 Day> 2315 | 2316 | -------------------------------------------------------------------------------- 2317 | 2318 | (document 2319 | subsection: (section 2320 | headline: (headline 2321 | stars: (stars) 2322 | item: (item 2323 | (expr))) 2324 | plan: (plan 2325 | (entry 2326 | name: (entry_name) 2327 | timestamp: (timestamp 2328 | date: (date) 2329 | day: (day)))))) 2330 | 2331 | ================================================================================ 2332 | Plan.12 - multi 2333 | ================================================================================ 2334 | * headline 2335 | DEADLINE: <1111-11-11 Day> <1111-11-11 Day> CLOSED: [1111-11-11 Day] 2336 | 2337 | -------------------------------------------------------------------------------- 2338 | 2339 | (document 2340 | subsection: (section 2341 | headline: (headline 2342 | stars: (stars) 2343 | item: (item 2344 | (expr))) 2345 | plan: (plan 2346 | (entry 2347 | name: (entry_name) 2348 | timestamp: (timestamp 2349 | date: (date) 2350 | day: (day))) 2351 | (entry 2352 | timestamp: (timestamp 2353 | date: (date) 2354 | day: (day))) 2355 | (entry 2356 | name: (entry_name) 2357 | timestamp: (timestamp 2358 | date: (date) 2359 | day: (day)))))) 2360 | 2361 | ================================================================================ 2362 | Plan.13 - Lowercase 2363 | ================================================================================ 2364 | * headline 2365 | scheduled: <1111-11-11 Day> 2366 | 2367 | -------------------------------------------------------------------------------- 2368 | 2369 | (document 2370 | subsection: (section 2371 | headline: (headline 2372 | stars: (stars) 2373 | item: (item 2374 | (expr))) 2375 | plan: (plan 2376 | (entry 2377 | name: (entry_name) 2378 | timestamp: (timestamp 2379 | date: (date) 2380 | day: (day)))))) 2381 | 2382 | ================================================================================ 2383 | Plan.14 - paragraph conflict 2384 | ================================================================================ 2385 | * hl 2386 | A: [[b][c]] 2387 | 2388 | -------------------------------------------------------------------------------- 2389 | 2390 | (document 2391 | subsection: (section 2392 | headline: (headline 2393 | stars: (stars) 2394 | item: (item 2395 | (expr))) 2396 | body: (body 2397 | (paragraph 2398 | (expr) 2399 | (expr))))) 2400 | 2401 | ================================================================================ 2402 | Plan.14a - Successful 2403 | ================================================================================ 2404 | * hl 2405 | A: [1-2-3] 2406 | 2407 | -------------------------------------------------------------------------------- 2408 | 2409 | (document 2410 | subsection: (section 2411 | headline: (headline 2412 | stars: (stars) 2413 | item: (item 2414 | (expr))) 2415 | plan: (plan 2416 | (entry 2417 | name: (entry_name) 2418 | timestamp: (timestamp 2419 | date: (date)))))) 2420 | 2421 | ================================================================================ 2422 | Plan.15 - Expr 2423 | ================================================================================ 2424 | * a 2425 | <1-1-1 *123> 2426 | -------------------------------------------------------------------------------- 2427 | 2428 | (document 2429 | subsection: (section 2430 | headline: (headline 2431 | stars: (stars) 2432 | item: (item 2433 | (expr))) 2434 | plan: (plan 2435 | (entry 2436 | timestamp: (timestamp 2437 | date: (date) 2438 | (expr)))))) 2439 | 2440 | ================================================================================ 2441 | Plan.16 - Link 2442 | ================================================================================ 2443 | * a 2444 | [[b]] 2445 | -------------------------------------------------------------------------------- 2446 | 2447 | (document 2448 | subsection: (section 2449 | headline: (headline 2450 | stars: (stars) 2451 | item: (item 2452 | (expr))) 2453 | body: (body 2454 | (paragraph 2455 | (expr))))) 2456 | 2457 | ================================================================================ 2458 | Plan.17 - Tab 2459 | ================================================================================ 2460 | * a 2461 | a: <2-2-2> 2462 | -------------------------------------------------------------------------------- 2463 | 2464 | (document 2465 | subsection: (section 2466 | headline: (headline 2467 | stars: (stars) 2468 | item: (item 2469 | (expr))) 2470 | plan: (plan 2471 | (entry 2472 | name: (entry_name) 2473 | timestamp: (timestamp 2474 | date: (date)))))) 2475 | -------------------------------------------------------------------------------- /grammar.js: -------------------------------------------------------------------------------- 1 | asciiSymbols = [ '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', 2 | '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', 3 | '\\', '^', '_', '`', '{', '|', '}', '~' ] 4 | 5 | org_grammar = { 6 | name: 'org', 7 | // Treat newlines explicitly, all other whitespace is extra 8 | extras: _ => [/[ \f\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/], 9 | 10 | externals: $ => [ 11 | $._liststart, 12 | $._listend, 13 | $._listitemend, 14 | $.bullet, 15 | $._stars, 16 | $._sectionend, 17 | $._eof, // Basically just '\0', but allows multiple to be matched 18 | ], 19 | 20 | inline: $ => [ 21 | $._nl, 22 | $._eol, 23 | $._ts_contents, 24 | $._directive_list, 25 | $._body_contents, 26 | ], 27 | 28 | precedences: _ => [ 29 | ['document_directive', 'body_directive'], 30 | ['special', 'immediate', 'non-immediate'], 31 | ], 32 | 33 | conflicts: $ => [ 34 | 35 | // stars 'headline_token1' item_repeat1 • ':' … 36 | // Should we start the tag? 37 | [$.item], 38 | 39 | [$._tag_expr_start, $.expr], 40 | 41 | // _multiline_text • ':' … 42 | // Is the ':' continued multiline text or is it a drawer? 43 | [$.paragraph], 44 | [$.fndef], 45 | // ':' 'str' … 46 | // Continue the conflict from above 47 | [$.expr, $.drawer], 48 | 49 | // headline 'entry_token1' ':' • '<' … 50 | [$.entry, $.expr], 51 | 52 | ], 53 | 54 | rules: { 55 | 56 | document: $ => seq( 57 | optional(field('body', $.body)), 58 | repeat(field('subsection', $.section)), 59 | ), 60 | 61 | // Set up to prevent lexing conflicts of having two paragraphs in a row 62 | body: $ => $._body_contents, 63 | 64 | _body_contents: $ => choice( 65 | repeat1($._nl), 66 | seq(repeat($._nl), $._multis), 67 | seq( 68 | repeat($._nl), 69 | repeat1(seq( 70 | choice( 71 | seq($._multis, $._nl), 72 | seq(optional(choice($.paragraph, $.fndef)), $._element), 73 | ), 74 | repeat($._nl), 75 | )), 76 | optional($._multis) 77 | ), 78 | ), 79 | 80 | // Can't have multiple in a row 81 | _multis: $ => choice( 82 | $.paragraph, 83 | $._directive_list, 84 | $.fndef, 85 | ), 86 | 87 | _element: $ => choice( 88 | $.comment, 89 | // Have attached directive: 90 | $.drawer, 91 | $.list, 92 | $.block, 93 | $.dynamic_block, 94 | $.table, 95 | $.latex_env, 96 | ), 97 | 98 | section: $ => seq( 99 | field('headline', $.headline), 100 | optional(field('plan', $.plan)), 101 | optional(field('property_drawer', $.property_drawer)), 102 | optional(field('body', $.body)), 103 | repeat(field('subsection', $.section)), 104 | $._sectionend, 105 | ), 106 | 107 | stars: $ => seq($._stars, /\*+/), 108 | 109 | headline: $ => seq( 110 | field('stars', $.stars), 111 | /[ \t]+/, // so it's not part of (item) 112 | optional(field('item', $.item)), 113 | optional(field('tags', $.tag_list)), 114 | $._eol, 115 | ), 116 | 117 | item: $ => repeat1($.expr), 118 | 119 | tag_list: $ => prec.dynamic(1, seq( 120 | $._tag_expr_start, 121 | repeat1(seq( 122 | field('tag', alias($._noc_expr, $.tag)), 123 | token.immediate(prec('special', ':')), 124 | )), 125 | )), 126 | 127 | // This is in another node to ensure a conflict with headline (item) 128 | _tag_expr_start: _ => token(prec('non-immediate', ':')), 129 | 130 | property_drawer: $ => seq( 131 | caseInsensitive(':properties:'), 132 | repeat1($._nl), 133 | repeat(seq($.property, repeat1($._nl))), 134 | prec.dynamic(1, caseInsensitive(':end:')), 135 | $._eol, 136 | ), 137 | 138 | property: $ => seq( 139 | ':', 140 | field('name', alias($._immediate_expr, $.expr)), 141 | token.immediate(':'), 142 | field('value', optional(alias($._expr_line, $.value))) 143 | ), 144 | 145 | plan: $ => seq(repeat1($.entry), prec.dynamic(1, $._eol)), 146 | 147 | entry: $ => seq( 148 | optional(seq( 149 | field('name', alias(token(prec('non-immediate', /\p{L}+/)), $.entry_name)), 150 | token.immediate(prec('immediate', ':')) 151 | )), 152 | field('timestamp', $.timestamp) 153 | ), 154 | 155 | timestamp: $ => choice( 156 | seq(token(prec('non-immediate', '<')), $._ts_contents, '>'), 157 | seq(token(prec('non-immediate', '<')), $._ts_contents, '>--<', $._ts_contents, '>'), 158 | seq(token(prec('non-immediate', '[')), $._ts_contents, ']'), 159 | seq(token(prec('non-immediate', '[')), $._ts_contents, ']'), 160 | seq(token(prec('non-immediate', '[')), $._ts_contents, ']--[', $._ts_contents, ']'), 161 | seq('<%%', $.tsexp, token(prec('special', '>'))), 162 | seq('[%%', $.tsexp, token(prec('special', ']'))), 163 | ), 164 | tsexp: $ => repeat1(alias($._ts_expr, $.expr)), 165 | 166 | _ts_contents: $ => seq( 167 | repeat($._ts_element), 168 | field('date', $.date), 169 | repeat($._ts_element), 170 | ), 171 | 172 | date: $ => /\p{N}{1,4}-\p{N}{1,4}-\p{N}{1,4}/, 173 | 174 | _ts_element: $ => choice( 175 | field('day', alias(/\p{L}[^\]>\p{Z}\t\n\r]*/, $.day)), 176 | field('time', alias(/\p{N}?\p{N}[:.]\p{N}\p{N}( ?\p{L}{1,2})?/, $.time)), 177 | field('duration', alias(/\p{N}?\p{N}[:.]\p{N}\p{N}( ?\p{L}{1,2})?-\p{N}?\p{N}[:.]\p{N}\p{N}( ?\p{L}{1,2})?/, $.duration)), 178 | field('repeat', alias(/[.+]?\+\p{N}+\p{L}/, $.repeat)), 179 | field('delay', alias(/--?\p{N}+\p{L}/, $.delay)), 180 | alias(prec(-1, /[^\[<\]>\p{Z}\t\n\r]+/), $.expr), 181 | ), 182 | 183 | paragraph: $ => seq(optional($._directive_list), $._multiline_text), 184 | 185 | fndef: $ => seq( 186 | optional($._directive_list), 187 | seq( 188 | caseInsensitive('[fn:'), 189 | field('label', alias(/[^\p{Z}\t\n\r\]]+/, $.expr)), 190 | ']', 191 | ), 192 | field('description', alias($._multiline_text, $.description)) 193 | ), 194 | 195 | _directive_list: $ => repeat1(field('directive', $.directive)), 196 | directive: $ => seq( 197 | '#+', 198 | field('name', alias($._immediate_expr, $.expr)), 199 | token.immediate(':'), 200 | field('value', optional(alias($._expr_line, $.value))), 201 | $._eol, 202 | ), 203 | 204 | comment: $ => prec.right(repeat1(seq(/#[^+\n\r]/, repeat($.expr), $._eol))), 205 | 206 | drawer: $ => seq( 207 | optional($._directive_list), 208 | token(prec('non-immediate', ':')), 209 | field('name', alias($._noc_expr, $.expr)), 210 | token.immediate(prec('special', ':')), 211 | $._nl, 212 | optional(field('contents', $.contents)), 213 | prec.dynamic(1, caseInsensitive(':end:')), 214 | $._eol, 215 | ), 216 | 217 | block: $ => seq( 218 | optional($._directive_list), 219 | caseInsensitive('#+begin_'), 220 | field('name', $.expr), 221 | optional(repeat1(field('parameter', $.expr))), 222 | $._nl, 223 | optional(field('contents', $.contents)), 224 | caseInsensitive('#+end_'), 225 | field('end_name',alias($._immediate_expr, $.expr)), 226 | $._eol, 227 | ), 228 | 229 | dynamic_block: $ => seq( 230 | optional($._directive_list), 231 | caseInsensitive('#+begin:'), 232 | field('name', $.expr), 233 | repeat(field('parameter', $.expr)), 234 | $._nl, 235 | optional(field('contents', $.contents)), 236 | caseInsensitive('#+end:'), 237 | optional(field('end_name', $.expr)), 238 | $._eol, 239 | ), 240 | 241 | list: $ => seq( 242 | optional($._directive_list), 243 | $._liststart, // captures indent length and bullet type 244 | repeat(seq($.listitem, $._listitemend, repeat($._nl))), 245 | seq($.listitem, $._listend) 246 | ), 247 | 248 | listitem: $ => seq( 249 | field('bullet', $.bullet), 250 | optional(field('checkbox', $.checkbox)), 251 | choice( 252 | $._eof, 253 | field('contents', $._body_contents), 254 | ), 255 | ), 256 | 257 | checkbox: $ => choice( 258 | '[ ]', 259 | seq( 260 | token(prec('non-immediate', '[')), 261 | field('status', alias($._checkbox_status_expr, $.expr)), 262 | token.immediate(prec('special', ']')), 263 | ), 264 | ), 265 | 266 | table: $ => prec.right(seq( 267 | optional($._directive_list), 268 | repeat1(choice($.row, $.hr)), 269 | repeat($.formula), 270 | )), 271 | 272 | row: $ => prec(1, seq( 273 | repeat1($.cell), 274 | optional(token(prec(1, '|'))), 275 | $._eol, 276 | )), 277 | 278 | cell: $ => seq( 279 | token(prec(1, '|')), // Table > paragraph (expr) 280 | optional(field('contents', alias($._expr_line, $.contents))), 281 | ), 282 | hr: $ => seq( 283 | token(prec(1, '|')), 284 | repeat1(seq(token.immediate(prec(1, /[-+]+/)), optional('|'))), 285 | $._eol, 286 | ), 287 | 288 | formula: $ => seq( 289 | caseInsensitive('#+tblfm:'), 290 | field('formula', optional($._expr_line)), 291 | $._eol, 292 | ), 293 | 294 | latex_env: $ => seq( 295 | optional($._directive_list), 296 | choice( 297 | seq( 298 | caseInsensitive('\\begin{'), 299 | field('name', alias(/[\p{L}\p{N}*]+/, $.name)), 300 | token.immediate('}'), 301 | $._nl, 302 | optional(field('contents', $.contents)), 303 | caseInsensitive('\\end{'), 304 | alias(/[\p{L}\p{N}*]+/, $.name), 305 | token.immediate('}'), 306 | ), 307 | seq( 308 | token(seq(caseInsensitive('\\['), choice('\n', '\r'))), 309 | optional(field('contents', $.contents)), 310 | caseInsensitive('\\]'), 311 | ), 312 | seq( 313 | token(seq(caseInsensitive('\\('), choice('\n', '\r'))), 314 | optional(field('contents', $.contents)), 315 | caseInsensitive('\\)'), 316 | ), 317 | ), 318 | $._eol, 319 | ), 320 | 321 | contents: $ => seq( 322 | optional($._expr_line), 323 | repeat1($._nl), 324 | repeat(seq($._expr_line, repeat1($._nl))), 325 | ), 326 | 327 | _nl: _ => choice('\n', '\r'), 328 | _eol: $ => choice('\n', '\r', $._eof), 329 | 330 | _expr_line: $ => repeat1($.expr), 331 | _multiline_text: $ => repeat1(seq(repeat1($.expr), $._eol)), 332 | 333 | _immediate_expr: $ => repeat1(expr('immediate', token.immediate)), 334 | _noc_expr: $ => repeat1(expr('immediate', token.immediate, ':')), 335 | 336 | _checkbox_status_expr: $ => expr('immediate', token.immediate, ']'), 337 | 338 | _ts_expr: $ => seq( 339 | expr('non-immediate', token, '>]'), 340 | repeat(expr('immediate', token.immediate, '>]')) 341 | ), 342 | 343 | expr: $ => seq( 344 | expr('non-immediate', token), 345 | repeat(expr('immediate', token.immediate)) 346 | ), 347 | 348 | } 349 | }; 350 | 351 | function expr(pr, tfunc, skip = '') { 352 | skip = skip.split("") 353 | return choice( 354 | ...asciiSymbols.filter(c => !skip.includes(c)).map(c => tfunc(prec(pr, c))), 355 | alias(tfunc(prec(pr, /\p{L}+/)), 'str'), 356 | alias(tfunc(prec(pr, /\p{N}+/)), 'num'), 357 | alias(tfunc(prec(pr, /[^\p{Z}\p{L}\p{N}\t\n\r]/)), 'sym'), 358 | // for checkboxes: ugly, but makes them work.. 359 | // alias(tfunc(prec(pr, 'x')), 'str'), 360 | // alias(tfunc(prec(pr, 'X')), 'str'), 361 | ) 362 | } 363 | 364 | function caseInsensitive(str) { 365 | return alias(new RegExp(str 366 | .split('') 367 | .map(caseInsensitiveChar) 368 | .join('') 369 | ), str.toLowerCase()) 370 | } 371 | 372 | function caseInsensitiveChar(char) { 373 | if (/[a-zA-Z]/.test(char)) 374 | return `[${char.toUpperCase()}${char.toLowerCase()}]`; 375 | return char.replace(/[\[\]^$.|?*+()\\\{\}]/, '\\$&'); 376 | } 377 | 378 | module.exports = grammar(org_grammar); 379 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-sitter-org", 3 | "version": "1.3.3", 4 | "description": "Org grammar for tree-sitter", 5 | "main": "bindings/node", 6 | "keywords": [ 7 | "parser", 8 | "lexer" 9 | ], 10 | "dependencies": { 11 | "nan": "^2.15.0", 12 | "prebuild-install": "^5.3.3" 13 | }, 14 | "devDependencies": { 15 | "prebuild": "^10.0.0", 16 | "tree-sitter-cli": "^0.19.5" 17 | }, 18 | "scripts": { 19 | "install": "prebuild-install || node-gyp rebuild", 20 | "pre-build": "prebuild --all --strip --verbose", 21 | "pre-build:upload": "prebuild --upload-all", 22 | "test": "tree-sitter test && script/parse-examples.sh", 23 | "test-windows": "tree-sitter test" 24 | }, 25 | "repository": "https://github.com/milisims/tree-sitter-org", 26 | "author": "Emilia Simmons", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/milisims/tree-sitter-org/issues" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /queries/highlights.scm: -------------------------------------------------------------------------------- 1 | ; A Note on anonymous nodes (represented in a query file as strings). As of 2 | ; right now, anonymous nodes can not be anchored. 3 | ; See https://github.com/tree-sitter/tree-sitter/issues/1461 4 | 5 | ; Example highlighting for headlines. The headlines here will be matched 6 | ; cyclically, easily extended to match however your heart desires. 7 | (headline (stars) @OrgStars1 (#match? @OrgStars1 "^(\\*{3})*\\*$") (item) @OrgHeadlineLevel1) 8 | (headline (stars) @OrgStars2 (#match? @OrgStars2 "^(\\*{3})*\\*\\*$") (item) @OrgHeadlineLevel2) 9 | (headline (stars) @OrgStars3 (#match? @OrgStars3 "^(\\*{3})*\\*\\*\\*$") (item) @OrgHeadlineLevel3) 10 | 11 | ; This one should be generated after scanning for configuration, using 12 | ; something like #any-of? for keywords, but could use a match if allowing 13 | ; markup on todo keywords is desirable. 14 | (item . (expr) @OrgKeywordTodo (#eq? @OrgKeywordTodo "TODO")) 15 | (item . (expr) @OrgKeywordDone (#eq? @OrgKeywordDone "DONE")) 16 | 17 | ; Not sure about this one with the anchors. 18 | (item . (expr)? . (expr "[" "#" @OrgPriority [ "num" "str" ] @OrgPriority "]") @OrgPriorityCookie (#match? @OrgPriorityCookie "\[#.\]")) 19 | 20 | ; Match cookies in a headline or listitem. If you want the numbers 21 | ; differently highlighted from the borders, add a capture name to "num". 22 | ; ([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "/" "num"? @OrgCookieNum "]" ) @OrgProgressCookie (#match? @OrgProgressCookie "^\[\d*/\d*\]$")) 23 | ; ([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "%" "]" ) @OrgPercentCookie (#match? @OrgPercentCookie "^\[\d*%\]$")) 24 | 25 | (tag_list (tag) @OrgTag) @OrgTagList 26 | 27 | (property_drawer) @OrgPropertyDrawer 28 | 29 | ; Properties are :name: vale, so to color the ':' we can either add them 30 | ; directly, or highlight the property separately from the name and value. If 31 | ; priorities are set properly, it should be simple to achieve. 32 | (property name: (expr) @OrgPropertyName (value)? @OrgPropertyValue) @OrgProperty 33 | 34 | ; Simple examples, but can also match (day), (date), (time), etc. 35 | (timestamp "[") @OrgTimestampInactive 36 | (timestamp "<" 37 | (day)? @OrgTimestampDay 38 | (date)? @OrgTimestampDate 39 | (time)? @OrgTimestampTime 40 | (repeat)? @OrgTimestampRepeat 41 | (delay)? @OrgTimestampDelay 42 | ) @OrgTimestampActive 43 | 44 | ; Like OrgProperty, easy to choose how the '[fn:LABEL] DESCRIPTION' are highlighted 45 | (fndef label: (expr) @OrgFootnoteLabel (description) @OrgFootnoteDescription) @OrgFootnoteDefinition 46 | 47 | ; Again like OrgProperty to change the styling of '#+' and ':'. Note that they 48 | ; can also be added in the query directly as anonymous nodes to style differently. 49 | (directive name: (expr) @OrgDirectiveName (value)? @OrgDirectiveValue) @OrgDirective 50 | 51 | (comment) @OrgComment 52 | 53 | ; At the moment, these three elements use one regex for the whole name. 54 | ; So (name) -> :name:, ideally this will not be the case, so it follows the 55 | ; patterns listed above, but that's the current status. Conflict issues. 56 | (drawer name: (expr) @OrgDrawerName (contents)? @OrgDrawerContents) @OrgDrawer 57 | (block name: (expr) @OrgBlockName (contents)? @OrgBlockContents) @OrgBlock 58 | (dynamic_block name: (expr) @OrgDynamicBlockName (contents)? @OrgDynamicBlockContents) @OrgDynamicBlock 59 | 60 | ; Can match different styles with a (#match?) or (#eq?) predicate if desired 61 | (bullet) @OrgListBullet 62 | 63 | ; Get different colors for different statuses as follows 64 | (checkbox) @OrgCheckbox 65 | (checkbox status: (expr "-") @OrgCheckInProgress) 66 | (checkbox status: (expr "str") @OrgCheckDone (#any-of? @OrgCheckDone "x" "X")) 67 | (checkbox status: (expr) @Error (#not-any-of? @Error "x" "X" "-")) 68 | 69 | ; If you want the ruler one color and the separators a different color, 70 | ; something like this would do it: 71 | ; (hr "|" @OrgTableHRBar) @OrgTableHorizontalRuler 72 | (hr) @OrgTableHorizontalRuler 73 | 74 | ; Can do all sorts of fun highlighting here.. 75 | (cell (contents . (expr "=")) @OrgCellFormula (#match? @OrgCellFormula "^\d+([.,]\d+)*$")) 76 | 77 | ; Dollars, floats, etc. Strings.. all options to play with 78 | (cell (contents . (expr "num") @OrgCellNumber (#match? @OrgCellNumber "^\d+([.,]\d+)*$") .)) 79 | -------------------------------------------------------------------------------- /queries/markup.scm: -------------------------------------------------------------------------------- 1 | (paragraph [ 2 | ((expr "*" @bold.start) (expr "*" @bold.end)) 3 | (expr "*" @bold.start "*" @bold.end) 4 | ((expr "~" @code.start) (expr "~" @code.end)) 5 | (expr "~" @code.start "~" @code.end) 6 | ((expr "/" @italic.start) (expr "/" @italic.end)) 7 | (expr "/" @italic.start "/" @italic.end) 8 | ((expr "_" @underline.start) (expr "_" @underline.end)) 9 | (expr "_" @underline.start "_" @underline.end) 10 | ((expr "=" @verbatim.start) (expr "=" @verbatim.end)) 11 | (expr "=" @verbatim.start "=" @verbatim.end) 12 | ((expr "+" @strikethrough.start) (expr "+" @strikethrough.end)) 13 | (expr "+" @strikethrough.start "+" @strikethrough.end) 14 | ]) 15 | 16 | ; headline item 17 | (item [ 18 | ((expr "*" @bold.start) (expr "*" @bold.end)) 19 | (expr "*" @bold.start "*" @bold.end) 20 | ((expr "~" @code.start) (expr "~" @code.end)) 21 | (expr "~" @code.start "~" @code.end) 22 | ((expr "/" @italic.start) (expr "/" @italic.end)) 23 | (expr "/" @italic.start "/" @italic.end) 24 | ((expr "_" @underline.start) (expr "_" @underline.end)) 25 | (expr "_" @underline.start "_" @underline.end) 26 | ((expr "=" @verbatim.start) (expr "=" @verbatim.end)) 27 | (expr "=" @verbatim.start "=" @verbatim.end) 28 | ((expr "+" @strikethrough.start) (expr "+" @strikethrough.end)) 29 | (expr "+" @strikethrough.start "+" @strikethrough.end) 30 | ]) 31 | 32 | -------------------------------------------------------------------------------- /src/node-types.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "block", 4 | "named": true, 5 | "fields": { 6 | "contents": { 7 | "multiple": false, 8 | "required": false, 9 | "types": [ 10 | { 11 | "type": "contents", 12 | "named": true 13 | } 14 | ] 15 | }, 16 | "directive": { 17 | "multiple": true, 18 | "required": false, 19 | "types": [ 20 | { 21 | "type": "directive", 22 | "named": true 23 | } 24 | ] 25 | }, 26 | "end_name": { 27 | "multiple": false, 28 | "required": true, 29 | "types": [ 30 | { 31 | "type": "expr", 32 | "named": true 33 | } 34 | ] 35 | }, 36 | "name": { 37 | "multiple": false, 38 | "required": true, 39 | "types": [ 40 | { 41 | "type": "expr", 42 | "named": true 43 | } 44 | ] 45 | }, 46 | "parameter": { 47 | "multiple": true, 48 | "required": false, 49 | "types": [ 50 | { 51 | "type": "expr", 52 | "named": true 53 | } 54 | ] 55 | } 56 | } 57 | }, 58 | { 59 | "type": "body", 60 | "named": true, 61 | "fields": { 62 | "directive": { 63 | "multiple": true, 64 | "required": false, 65 | "types": [ 66 | { 67 | "type": "directive", 68 | "named": true 69 | } 70 | ] 71 | } 72 | }, 73 | "children": { 74 | "multiple": true, 75 | "required": false, 76 | "types": [ 77 | { 78 | "type": "block", 79 | "named": true 80 | }, 81 | { 82 | "type": "comment", 83 | "named": true 84 | }, 85 | { 86 | "type": "drawer", 87 | "named": true 88 | }, 89 | { 90 | "type": "dynamic_block", 91 | "named": true 92 | }, 93 | { 94 | "type": "fndef", 95 | "named": true 96 | }, 97 | { 98 | "type": "latex_env", 99 | "named": true 100 | }, 101 | { 102 | "type": "list", 103 | "named": true 104 | }, 105 | { 106 | "type": "paragraph", 107 | "named": true 108 | }, 109 | { 110 | "type": "table", 111 | "named": true 112 | } 113 | ] 114 | } 115 | }, 116 | { 117 | "type": "cell", 118 | "named": true, 119 | "fields": { 120 | "contents": { 121 | "multiple": false, 122 | "required": false, 123 | "types": [ 124 | { 125 | "type": "contents", 126 | "named": true 127 | } 128 | ] 129 | } 130 | } 131 | }, 132 | { 133 | "type": "checkbox", 134 | "named": true, 135 | "fields": { 136 | "status": { 137 | "multiple": false, 138 | "required": false, 139 | "types": [ 140 | { 141 | "type": "expr", 142 | "named": true 143 | } 144 | ] 145 | } 146 | } 147 | }, 148 | { 149 | "type": "comment", 150 | "named": true, 151 | "fields": {}, 152 | "children": { 153 | "multiple": true, 154 | "required": false, 155 | "types": [ 156 | { 157 | "type": "expr", 158 | "named": true 159 | } 160 | ] 161 | } 162 | }, 163 | { 164 | "type": "contents", 165 | "named": true, 166 | "fields": {}, 167 | "children": { 168 | "multiple": true, 169 | "required": false, 170 | "types": [ 171 | { 172 | "type": "expr", 173 | "named": true 174 | } 175 | ] 176 | } 177 | }, 178 | { 179 | "type": "description", 180 | "named": true, 181 | "fields": {}, 182 | "children": { 183 | "multiple": true, 184 | "required": false, 185 | "types": [ 186 | { 187 | "type": "expr", 188 | "named": true 189 | } 190 | ] 191 | } 192 | }, 193 | { 194 | "type": "directive", 195 | "named": true, 196 | "fields": { 197 | "name": { 198 | "multiple": false, 199 | "required": true, 200 | "types": [ 201 | { 202 | "type": "expr", 203 | "named": true 204 | } 205 | ] 206 | }, 207 | "value": { 208 | "multiple": false, 209 | "required": false, 210 | "types": [ 211 | { 212 | "type": "value", 213 | "named": true 214 | } 215 | ] 216 | } 217 | } 218 | }, 219 | { 220 | "type": "document", 221 | "named": true, 222 | "fields": { 223 | "body": { 224 | "multiple": false, 225 | "required": false, 226 | "types": [ 227 | { 228 | "type": "body", 229 | "named": true 230 | } 231 | ] 232 | }, 233 | "subsection": { 234 | "multiple": true, 235 | "required": false, 236 | "types": [ 237 | { 238 | "type": "section", 239 | "named": true 240 | } 241 | ] 242 | } 243 | } 244 | }, 245 | { 246 | "type": "drawer", 247 | "named": true, 248 | "fields": { 249 | "contents": { 250 | "multiple": false, 251 | "required": false, 252 | "types": [ 253 | { 254 | "type": "contents", 255 | "named": true 256 | } 257 | ] 258 | }, 259 | "directive": { 260 | "multiple": true, 261 | "required": false, 262 | "types": [ 263 | { 264 | "type": "directive", 265 | "named": true 266 | } 267 | ] 268 | }, 269 | "name": { 270 | "multiple": false, 271 | "required": true, 272 | "types": [ 273 | { 274 | "type": "expr", 275 | "named": true 276 | } 277 | ] 278 | } 279 | } 280 | }, 281 | { 282 | "type": "dynamic_block", 283 | "named": true, 284 | "fields": { 285 | "contents": { 286 | "multiple": false, 287 | "required": false, 288 | "types": [ 289 | { 290 | "type": "contents", 291 | "named": true 292 | } 293 | ] 294 | }, 295 | "directive": { 296 | "multiple": true, 297 | "required": false, 298 | "types": [ 299 | { 300 | "type": "directive", 301 | "named": true 302 | } 303 | ] 304 | }, 305 | "end_name": { 306 | "multiple": false, 307 | "required": false, 308 | "types": [ 309 | { 310 | "type": "expr", 311 | "named": true 312 | } 313 | ] 314 | }, 315 | "name": { 316 | "multiple": false, 317 | "required": true, 318 | "types": [ 319 | { 320 | "type": "expr", 321 | "named": true 322 | } 323 | ] 324 | }, 325 | "parameter": { 326 | "multiple": true, 327 | "required": false, 328 | "types": [ 329 | { 330 | "type": "expr", 331 | "named": true 332 | } 333 | ] 334 | } 335 | } 336 | }, 337 | { 338 | "type": "entry", 339 | "named": true, 340 | "fields": { 341 | "name": { 342 | "multiple": false, 343 | "required": false, 344 | "types": [ 345 | { 346 | "type": "entry_name", 347 | "named": true 348 | } 349 | ] 350 | }, 351 | "timestamp": { 352 | "multiple": false, 353 | "required": true, 354 | "types": [ 355 | { 356 | "type": "timestamp", 357 | "named": true 358 | } 359 | ] 360 | } 361 | } 362 | }, 363 | { 364 | "type": "expr", 365 | "named": true, 366 | "fields": {} 367 | }, 368 | { 369 | "type": "fndef", 370 | "named": true, 371 | "fields": { 372 | "description": { 373 | "multiple": false, 374 | "required": true, 375 | "types": [ 376 | { 377 | "type": "description", 378 | "named": true 379 | } 380 | ] 381 | }, 382 | "directive": { 383 | "multiple": true, 384 | "required": false, 385 | "types": [ 386 | { 387 | "type": "directive", 388 | "named": true 389 | } 390 | ] 391 | }, 392 | "label": { 393 | "multiple": false, 394 | "required": true, 395 | "types": [ 396 | { 397 | "type": "expr", 398 | "named": true 399 | } 400 | ] 401 | } 402 | } 403 | }, 404 | { 405 | "type": "formula", 406 | "named": true, 407 | "fields": { 408 | "formula": { 409 | "multiple": true, 410 | "required": false, 411 | "types": [ 412 | { 413 | "type": "expr", 414 | "named": true 415 | } 416 | ] 417 | } 418 | } 419 | }, 420 | { 421 | "type": "headline", 422 | "named": true, 423 | "fields": { 424 | "item": { 425 | "multiple": false, 426 | "required": false, 427 | "types": [ 428 | { 429 | "type": "item", 430 | "named": true 431 | } 432 | ] 433 | }, 434 | "stars": { 435 | "multiple": false, 436 | "required": true, 437 | "types": [ 438 | { 439 | "type": "stars", 440 | "named": true 441 | } 442 | ] 443 | }, 444 | "tags": { 445 | "multiple": false, 446 | "required": false, 447 | "types": [ 448 | { 449 | "type": "tag_list", 450 | "named": true 451 | } 452 | ] 453 | } 454 | } 455 | }, 456 | { 457 | "type": "hr", 458 | "named": true, 459 | "fields": {} 460 | }, 461 | { 462 | "type": "item", 463 | "named": true, 464 | "fields": {}, 465 | "children": { 466 | "multiple": true, 467 | "required": true, 468 | "types": [ 469 | { 470 | "type": "expr", 471 | "named": true 472 | } 473 | ] 474 | } 475 | }, 476 | { 477 | "type": "latex_env", 478 | "named": true, 479 | "fields": { 480 | "contents": { 481 | "multiple": false, 482 | "required": false, 483 | "types": [ 484 | { 485 | "type": "contents", 486 | "named": true 487 | } 488 | ] 489 | }, 490 | "directive": { 491 | "multiple": true, 492 | "required": false, 493 | "types": [ 494 | { 495 | "type": "directive", 496 | "named": true 497 | } 498 | ] 499 | }, 500 | "name": { 501 | "multiple": false, 502 | "required": false, 503 | "types": [ 504 | { 505 | "type": "name", 506 | "named": true 507 | } 508 | ] 509 | } 510 | }, 511 | "children": { 512 | "multiple": false, 513 | "required": false, 514 | "types": [ 515 | { 516 | "type": "name", 517 | "named": true 518 | } 519 | ] 520 | } 521 | }, 522 | { 523 | "type": "list", 524 | "named": true, 525 | "fields": { 526 | "directive": { 527 | "multiple": true, 528 | "required": false, 529 | "types": [ 530 | { 531 | "type": "directive", 532 | "named": true 533 | } 534 | ] 535 | } 536 | }, 537 | "children": { 538 | "multiple": true, 539 | "required": true, 540 | "types": [ 541 | { 542 | "type": "listitem", 543 | "named": true 544 | } 545 | ] 546 | } 547 | }, 548 | { 549 | "type": "listitem", 550 | "named": true, 551 | "fields": { 552 | "bullet": { 553 | "multiple": false, 554 | "required": true, 555 | "types": [ 556 | { 557 | "type": "bullet", 558 | "named": true 559 | } 560 | ] 561 | }, 562 | "checkbox": { 563 | "multiple": false, 564 | "required": false, 565 | "types": [ 566 | { 567 | "type": "checkbox", 568 | "named": true 569 | } 570 | ] 571 | }, 572 | "contents": { 573 | "multiple": true, 574 | "required": false, 575 | "types": [ 576 | { 577 | "type": "\n", 578 | "named": false 579 | }, 580 | { 581 | "type": "\r", 582 | "named": false 583 | }, 584 | { 585 | "type": "block", 586 | "named": true 587 | }, 588 | { 589 | "type": "comment", 590 | "named": true 591 | }, 592 | { 593 | "type": "directive", 594 | "named": true 595 | }, 596 | { 597 | "type": "drawer", 598 | "named": true 599 | }, 600 | { 601 | "type": "dynamic_block", 602 | "named": true 603 | }, 604 | { 605 | "type": "fndef", 606 | "named": true 607 | }, 608 | { 609 | "type": "latex_env", 610 | "named": true 611 | }, 612 | { 613 | "type": "list", 614 | "named": true 615 | }, 616 | { 617 | "type": "paragraph", 618 | "named": true 619 | }, 620 | { 621 | "type": "table", 622 | "named": true 623 | } 624 | ] 625 | }, 626 | "directive": { 627 | "multiple": true, 628 | "required": false, 629 | "types": [ 630 | { 631 | "type": "directive", 632 | "named": true 633 | } 634 | ] 635 | } 636 | } 637 | }, 638 | { 639 | "type": "paragraph", 640 | "named": true, 641 | "fields": { 642 | "directive": { 643 | "multiple": true, 644 | "required": false, 645 | "types": [ 646 | { 647 | "type": "directive", 648 | "named": true 649 | } 650 | ] 651 | } 652 | }, 653 | "children": { 654 | "multiple": true, 655 | "required": false, 656 | "types": [ 657 | { 658 | "type": "expr", 659 | "named": true 660 | } 661 | ] 662 | } 663 | }, 664 | { 665 | "type": "plan", 666 | "named": true, 667 | "fields": {}, 668 | "children": { 669 | "multiple": true, 670 | "required": true, 671 | "types": [ 672 | { 673 | "type": "entry", 674 | "named": true 675 | } 676 | ] 677 | } 678 | }, 679 | { 680 | "type": "property", 681 | "named": true, 682 | "fields": { 683 | "name": { 684 | "multiple": false, 685 | "required": true, 686 | "types": [ 687 | { 688 | "type": "expr", 689 | "named": true 690 | } 691 | ] 692 | }, 693 | "value": { 694 | "multiple": false, 695 | "required": false, 696 | "types": [ 697 | { 698 | "type": "value", 699 | "named": true 700 | } 701 | ] 702 | } 703 | } 704 | }, 705 | { 706 | "type": "property_drawer", 707 | "named": true, 708 | "fields": {}, 709 | "children": { 710 | "multiple": true, 711 | "required": false, 712 | "types": [ 713 | { 714 | "type": "property", 715 | "named": true 716 | } 717 | ] 718 | } 719 | }, 720 | { 721 | "type": "row", 722 | "named": true, 723 | "fields": {}, 724 | "children": { 725 | "multiple": true, 726 | "required": true, 727 | "types": [ 728 | { 729 | "type": "cell", 730 | "named": true 731 | } 732 | ] 733 | } 734 | }, 735 | { 736 | "type": "section", 737 | "named": true, 738 | "fields": { 739 | "body": { 740 | "multiple": false, 741 | "required": false, 742 | "types": [ 743 | { 744 | "type": "body", 745 | "named": true 746 | } 747 | ] 748 | }, 749 | "headline": { 750 | "multiple": false, 751 | "required": true, 752 | "types": [ 753 | { 754 | "type": "headline", 755 | "named": true 756 | } 757 | ] 758 | }, 759 | "plan": { 760 | "multiple": false, 761 | "required": false, 762 | "types": [ 763 | { 764 | "type": "plan", 765 | "named": true 766 | } 767 | ] 768 | }, 769 | "property_drawer": { 770 | "multiple": false, 771 | "required": false, 772 | "types": [ 773 | { 774 | "type": "property_drawer", 775 | "named": true 776 | } 777 | ] 778 | }, 779 | "subsection": { 780 | "multiple": true, 781 | "required": false, 782 | "types": [ 783 | { 784 | "type": "section", 785 | "named": true 786 | } 787 | ] 788 | } 789 | } 790 | }, 791 | { 792 | "type": "stars", 793 | "named": true, 794 | "fields": {} 795 | }, 796 | { 797 | "type": "table", 798 | "named": true, 799 | "fields": { 800 | "directive": { 801 | "multiple": true, 802 | "required": false, 803 | "types": [ 804 | { 805 | "type": "directive", 806 | "named": true 807 | } 808 | ] 809 | } 810 | }, 811 | "children": { 812 | "multiple": true, 813 | "required": true, 814 | "types": [ 815 | { 816 | "type": "formula", 817 | "named": true 818 | }, 819 | { 820 | "type": "hr", 821 | "named": true 822 | }, 823 | { 824 | "type": "row", 825 | "named": true 826 | } 827 | ] 828 | } 829 | }, 830 | { 831 | "type": "tag", 832 | "named": true, 833 | "fields": {} 834 | }, 835 | { 836 | "type": "tag_list", 837 | "named": true, 838 | "fields": { 839 | "tag": { 840 | "multiple": true, 841 | "required": true, 842 | "types": [ 843 | { 844 | "type": "tag", 845 | "named": true 846 | } 847 | ] 848 | } 849 | } 850 | }, 851 | { 852 | "type": "timestamp", 853 | "named": true, 854 | "fields": { 855 | "date": { 856 | "multiple": true, 857 | "required": false, 858 | "types": [ 859 | { 860 | "type": "date", 861 | "named": true 862 | } 863 | ] 864 | }, 865 | "day": { 866 | "multiple": true, 867 | "required": false, 868 | "types": [ 869 | { 870 | "type": "day", 871 | "named": true 872 | } 873 | ] 874 | }, 875 | "delay": { 876 | "multiple": true, 877 | "required": false, 878 | "types": [ 879 | { 880 | "type": "delay", 881 | "named": true 882 | } 883 | ] 884 | }, 885 | "duration": { 886 | "multiple": true, 887 | "required": false, 888 | "types": [ 889 | { 890 | "type": "duration", 891 | "named": true 892 | } 893 | ] 894 | }, 895 | "repeat": { 896 | "multiple": true, 897 | "required": false, 898 | "types": [ 899 | { 900 | "type": "repeat", 901 | "named": true 902 | } 903 | ] 904 | }, 905 | "time": { 906 | "multiple": true, 907 | "required": false, 908 | "types": [ 909 | { 910 | "type": "time", 911 | "named": true 912 | } 913 | ] 914 | } 915 | }, 916 | "children": { 917 | "multiple": true, 918 | "required": false, 919 | "types": [ 920 | { 921 | "type": "expr", 922 | "named": true 923 | }, 924 | { 925 | "type": "tsexp", 926 | "named": true 927 | } 928 | ] 929 | } 930 | }, 931 | { 932 | "type": "tsexp", 933 | "named": true, 934 | "fields": {}, 935 | "children": { 936 | "multiple": true, 937 | "required": true, 938 | "types": [ 939 | { 940 | "type": "expr", 941 | "named": true 942 | } 943 | ] 944 | } 945 | }, 946 | { 947 | "type": "value", 948 | "named": true, 949 | "fields": {}, 950 | "children": { 951 | "multiple": true, 952 | "required": true, 953 | "types": [ 954 | { 955 | "type": "expr", 956 | "named": true 957 | } 958 | ] 959 | } 960 | }, 961 | { 962 | "type": "\n", 963 | "named": false 964 | }, 965 | { 966 | "type": "\r", 967 | "named": false 968 | }, 969 | { 970 | "type": "!", 971 | "named": false 972 | }, 973 | { 974 | "type": "\"", 975 | "named": false 976 | }, 977 | { 978 | "type": "#", 979 | "named": false 980 | }, 981 | { 982 | "type": "#+", 983 | "named": false 984 | }, 985 | { 986 | "type": "#+begin:", 987 | "named": false 988 | }, 989 | { 990 | "type": "#+begin_", 991 | "named": false 992 | }, 993 | { 994 | "type": "#+end:", 995 | "named": false 996 | }, 997 | { 998 | "type": "#+end_", 999 | "named": false 1000 | }, 1001 | { 1002 | "type": "#+tblfm:", 1003 | "named": false 1004 | }, 1005 | { 1006 | "type": "$", 1007 | "named": false 1008 | }, 1009 | { 1010 | "type": "%", 1011 | "named": false 1012 | }, 1013 | { 1014 | "type": "&", 1015 | "named": false 1016 | }, 1017 | { 1018 | "type": "'", 1019 | "named": false 1020 | }, 1021 | { 1022 | "type": "(", 1023 | "named": false 1024 | }, 1025 | { 1026 | "type": ")", 1027 | "named": false 1028 | }, 1029 | { 1030 | "type": "*", 1031 | "named": false 1032 | }, 1033 | { 1034 | "type": "+", 1035 | "named": false 1036 | }, 1037 | { 1038 | "type": ",", 1039 | "named": false 1040 | }, 1041 | { 1042 | "type": "-", 1043 | "named": false 1044 | }, 1045 | { 1046 | "type": ".", 1047 | "named": false 1048 | }, 1049 | { 1050 | "type": "/", 1051 | "named": false 1052 | }, 1053 | { 1054 | "type": ":", 1055 | "named": false 1056 | }, 1057 | { 1058 | "type": ":end:", 1059 | "named": false 1060 | }, 1061 | { 1062 | "type": ":properties:", 1063 | "named": false 1064 | }, 1065 | { 1066 | "type": ";", 1067 | "named": false 1068 | }, 1069 | { 1070 | "type": "<", 1071 | "named": false 1072 | }, 1073 | { 1074 | "type": "<%%", 1075 | "named": false 1076 | }, 1077 | { 1078 | "type": "=", 1079 | "named": false 1080 | }, 1081 | { 1082 | "type": ">", 1083 | "named": false 1084 | }, 1085 | { 1086 | "type": ">--<", 1087 | "named": false 1088 | }, 1089 | { 1090 | "type": "?", 1091 | "named": false 1092 | }, 1093 | { 1094 | "type": "@", 1095 | "named": false 1096 | }, 1097 | { 1098 | "type": "[", 1099 | "named": false 1100 | }, 1101 | { 1102 | "type": "[ ]", 1103 | "named": false 1104 | }, 1105 | { 1106 | "type": "[%%", 1107 | "named": false 1108 | }, 1109 | { 1110 | "type": "[fn:", 1111 | "named": false 1112 | }, 1113 | { 1114 | "type": "\\", 1115 | "named": false 1116 | }, 1117 | { 1118 | "type": "\\)", 1119 | "named": false 1120 | }, 1121 | { 1122 | "type": "\\]", 1123 | "named": false 1124 | }, 1125 | { 1126 | "type": "\\begin{", 1127 | "named": false 1128 | }, 1129 | { 1130 | "type": "\\end{", 1131 | "named": false 1132 | }, 1133 | { 1134 | "type": "]", 1135 | "named": false 1136 | }, 1137 | { 1138 | "type": "]--[", 1139 | "named": false 1140 | }, 1141 | { 1142 | "type": "^", 1143 | "named": false 1144 | }, 1145 | { 1146 | "type": "_", 1147 | "named": false 1148 | }, 1149 | { 1150 | "type": "`", 1151 | "named": false 1152 | }, 1153 | { 1154 | "type": "bullet", 1155 | "named": true 1156 | }, 1157 | { 1158 | "type": "date", 1159 | "named": true 1160 | }, 1161 | { 1162 | "type": "day", 1163 | "named": true 1164 | }, 1165 | { 1166 | "type": "delay", 1167 | "named": true 1168 | }, 1169 | { 1170 | "type": "duration", 1171 | "named": true 1172 | }, 1173 | { 1174 | "type": "entry_name", 1175 | "named": true 1176 | }, 1177 | { 1178 | "type": "name", 1179 | "named": true 1180 | }, 1181 | { 1182 | "type": "num", 1183 | "named": false 1184 | }, 1185 | { 1186 | "type": "repeat", 1187 | "named": true 1188 | }, 1189 | { 1190 | "type": "str", 1191 | "named": false 1192 | }, 1193 | { 1194 | "type": "sym", 1195 | "named": false 1196 | }, 1197 | { 1198 | "type": "time", 1199 | "named": true 1200 | }, 1201 | { 1202 | "type": "{", 1203 | "named": false 1204 | }, 1205 | { 1206 | "type": "|", 1207 | "named": false 1208 | }, 1209 | { 1210 | "type": "}", 1211 | "named": false 1212 | }, 1213 | { 1214 | "type": "~", 1215 | "named": false 1216 | } 1217 | ] -------------------------------------------------------------------------------- /src/scanner.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) 7 | 8 | #define VEC_RESIZE(vec, _cap) \ 9 | { \ 10 | (vec)->data = realloc((vec)->data, (_cap) * sizeof((vec)->data[0])); \ 11 | assert((vec)->data != NULL); \ 12 | (vec)->cap = (_cap); \ 13 | } 14 | 15 | #define VEC_PUSH(vec, el) \ 16 | { \ 17 | if ((vec)->cap == (vec)->len) { \ 18 | VEC_RESIZE((vec), MAX(16, (vec)->len * 2)); \ 19 | } \ 20 | (vec)->data[(vec)->len++] = (el); \ 21 | } 22 | 23 | #define VEC_POP(vec) (vec)->len--; 24 | 25 | #define VEC_BACK(vec) ((vec)->data[(vec)->len - 1]) 26 | 27 | #define VEC_FREE(vec) \ 28 | { \ 29 | if ((vec)->data != NULL) \ 30 | free((vec)->data); \ 31 | } 32 | 33 | #define VEC_CLEAR(vec) \ 34 | { (vec)->len = 0; } 35 | 36 | enum TokenType { 37 | LISTSTART, 38 | LISTEND, 39 | LISTITEMEND, 40 | BULLET, 41 | HLSTARS, 42 | SECTIONEND, 43 | ENDOFFILE, 44 | }; 45 | 46 | typedef enum { 47 | NOTABULLET, 48 | DASH, 49 | PLUS, 50 | STAR, 51 | LOWERDOT, 52 | UPPERDOT, 53 | LOWERPAREN, 54 | UPPERPAREN, 55 | NUMDOT, 56 | NUMPAREN, 57 | } Bullet; 58 | 59 | typedef struct { 60 | uint32_t len; 61 | uint32_t cap; 62 | int16_t *data; 63 | } stack; 64 | 65 | typedef struct { 66 | stack *indent_length_stack; 67 | stack *bullet_stack; 68 | stack *section_stack; 69 | } Scanner; 70 | 71 | static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); } 72 | 73 | static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); } 74 | 75 | unsigned serialize(Scanner *scanner, char *buffer) { 76 | size_t i = 0; 77 | 78 | size_t indent_count = scanner->indent_length_stack->len - 1; 79 | if (indent_count > UINT8_MAX) 80 | indent_count = UINT8_MAX; 81 | buffer[i++] = indent_count; 82 | 83 | int iter = 1; 84 | for (; iter < scanner->indent_length_stack->len && 85 | i < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; 86 | ++iter) { 87 | buffer[i++] = scanner->indent_length_stack->data[iter]; 88 | } 89 | 90 | iter = 1; 91 | for (; iter < scanner->bullet_stack->len && 92 | i < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; 93 | ++iter) { 94 | buffer[i++] = scanner->bullet_stack->data[iter]; 95 | } 96 | 97 | iter = 1; 98 | for (; iter < scanner->section_stack->len && 99 | i < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; 100 | ++iter) { 101 | buffer[i++] = scanner->section_stack->data[iter]; 102 | } 103 | 104 | return i; 105 | } 106 | 107 | void deserialize(Scanner *scanner, const char *buffer, unsigned length) { 108 | VEC_CLEAR(scanner->section_stack); 109 | VEC_PUSH(scanner->section_stack, 0); 110 | VEC_CLEAR(scanner->indent_length_stack); 111 | VEC_PUSH(scanner->indent_length_stack, -1); 112 | VEC_CLEAR(scanner->bullet_stack); 113 | VEC_PUSH(scanner->bullet_stack, NOTABULLET); 114 | 115 | if (length == 0) 116 | return; 117 | 118 | size_t i = 0; 119 | 120 | size_t indent_count = (uint8_t)buffer[i++]; 121 | 122 | for (; i <= indent_count; i++) 123 | VEC_PUSH(scanner->indent_length_stack, buffer[i]); 124 | for (; i <= 2 * indent_count; i++) 125 | VEC_PUSH(scanner->bullet_stack, buffer[i]); 126 | for (; i < length; i++) 127 | VEC_PUSH(scanner->section_stack, buffer[i]); 128 | } 129 | 130 | static bool dedent(Scanner *scanner, TSLexer *lexer) { 131 | VEC_POP(scanner->indent_length_stack); 132 | VEC_POP(scanner->bullet_stack); 133 | lexer->result_symbol = LISTEND; 134 | return true; 135 | } 136 | 137 | static bool in_error_recovery(const bool *valid_symbols) { 138 | return (valid_symbols[LISTSTART] && valid_symbols[LISTEND] && 139 | valid_symbols[LISTITEMEND] && valid_symbols[BULLET] && 140 | valid_symbols[HLSTARS] && valid_symbols[SECTIONEND] && 141 | valid_symbols[ENDOFFILE]); 142 | } 143 | 144 | Bullet getbullet(TSLexer *lexer) { 145 | if (lexer->lookahead == '-') { 146 | advance(lexer); 147 | if (iswspace(lexer->lookahead)) 148 | return DASH; 149 | } else if (lexer->lookahead == '+') { 150 | advance(lexer); 151 | if (iswspace(lexer->lookahead)) 152 | return PLUS; 153 | } else if (lexer->lookahead == '*') { 154 | advance(lexer); 155 | if (iswspace(lexer->lookahead)) 156 | return STAR; 157 | } else if ('a' <= lexer->lookahead && lexer->lookahead <= 'z') { 158 | advance(lexer); 159 | if (lexer->lookahead == '.') { 160 | advance(lexer); 161 | if (iswspace(lexer->lookahead)) 162 | return LOWERDOT; 163 | } else if (lexer->lookahead == ')') { 164 | advance(lexer); 165 | if (iswspace(lexer->lookahead)) 166 | return LOWERPAREN; 167 | } 168 | } else if ('A' <= lexer->lookahead && lexer->lookahead <= 'Z') { 169 | advance(lexer); 170 | if (lexer->lookahead == '.') { 171 | advance(lexer); 172 | if (iswspace(lexer->lookahead)) 173 | return UPPERDOT; 174 | } else if (lexer->lookahead == ')') { 175 | advance(lexer); 176 | if (iswspace(lexer->lookahead)) 177 | return UPPERPAREN; 178 | } 179 | } else if ('0' <= lexer->lookahead && lexer->lookahead <= '9') { 180 | do { 181 | advance(lexer); 182 | } while ('0' <= lexer->lookahead && lexer->lookahead <= '9'); 183 | if (lexer->lookahead == '.') { 184 | advance(lexer); 185 | if (iswspace(lexer->lookahead)) 186 | return NUMDOT; 187 | } else if (lexer->lookahead == ')') { 188 | advance(lexer); 189 | if (iswspace(lexer->lookahead)) 190 | return NUMPAREN; 191 | } 192 | } 193 | return NOTABULLET; 194 | } 195 | 196 | bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) { 197 | if (in_error_recovery(valid_symbols)) 198 | return false; 199 | 200 | // - Section ends 201 | int16_t indent_length = 0; 202 | lexer->mark_end(lexer); 203 | for (;;) { 204 | if (lexer->lookahead == ' ') { 205 | indent_length++; 206 | } else if (lexer->lookahead == '\t') { 207 | indent_length += 8; 208 | } else if (lexer->lookahead == '\0') { 209 | if (valid_symbols[LISTEND]) { 210 | lexer->result_symbol = LISTEND; 211 | } else if (valid_symbols[SECTIONEND]) { 212 | lexer->result_symbol = SECTIONEND; 213 | } else if (valid_symbols[ENDOFFILE]) { 214 | lexer->result_symbol = ENDOFFILE; 215 | } else 216 | return false; 217 | 218 | return true; 219 | } else { 220 | break; 221 | } 222 | skip(lexer); 223 | } 224 | 225 | // - Listiem ends 226 | // Listend -> end of a line, looking for: 227 | // 1. dedent 228 | // 2. same indent, not a bullet 229 | // 3. two eols 230 | int16_t newlines = 0; 231 | if (valid_symbols[LISTEND] || valid_symbols[LISTITEMEND]) { 232 | for (;;) { 233 | if (lexer->lookahead == ' ') { 234 | indent_length++; 235 | } else if (lexer->lookahead == '\t') { 236 | indent_length += 8; 237 | } else if (lexer->lookahead == '\0') { 238 | return dedent(scanner, lexer); 239 | } else if (lexer->lookahead == '\n') { 240 | if (++newlines > 1) 241 | return dedent(scanner, lexer); 242 | indent_length = 0; 243 | } else { 244 | break; 245 | } 246 | skip(lexer); 247 | } 248 | 249 | if (indent_length < VEC_BACK(scanner->indent_length_stack)) { 250 | return dedent(scanner, lexer); 251 | } else if (indent_length == VEC_BACK(scanner->indent_length_stack)) { 252 | if (getbullet(lexer) == VEC_BACK(scanner->bullet_stack)) { 253 | lexer->result_symbol = LISTITEMEND; 254 | return true; 255 | } 256 | return dedent(scanner, lexer); 257 | } 258 | } 259 | 260 | // - Col=0 star 261 | if (indent_length == 0 && lexer->lookahead == '*') { 262 | lexer->mark_end(lexer); 263 | int16_t stars = 1; 264 | skip(lexer); 265 | while (lexer->lookahead == '*') { 266 | stars++; 267 | skip(lexer); 268 | } 269 | 270 | if (valid_symbols[SECTIONEND] && iswspace(lexer->lookahead) && 271 | stars > 0 && stars <= VEC_BACK(scanner->section_stack)) { 272 | VEC_POP(scanner->section_stack); 273 | lexer->result_symbol = SECTIONEND; 274 | return true; 275 | } else if (valid_symbols[HLSTARS] && iswspace(lexer->lookahead)) { 276 | VEC_PUSH(scanner->section_stack, stars); 277 | lexer->result_symbol = HLSTARS; 278 | return true; 279 | } 280 | return false; 281 | } 282 | 283 | // - Liststart and bullets 284 | if ((valid_symbols[LISTSTART] || valid_symbols[BULLET]) && newlines == 0) { 285 | Bullet bullet = getbullet(lexer); 286 | 287 | if (valid_symbols[BULLET] && 288 | bullet == VEC_BACK(scanner->bullet_stack) && 289 | indent_length == VEC_BACK(scanner->indent_length_stack)) { 290 | lexer->mark_end(lexer); 291 | lexer->result_symbol = BULLET; 292 | return true; 293 | } else if (valid_symbols[LISTSTART] && bullet != NOTABULLET && 294 | indent_length > VEC_BACK(scanner->indent_length_stack)) { 295 | VEC_PUSH(scanner->indent_length_stack, indent_length); 296 | VEC_PUSH(scanner->bullet_stack, bullet); 297 | lexer->result_symbol = LISTSTART; 298 | return true; 299 | } 300 | } 301 | 302 | return false; // default 303 | } 304 | 305 | void *tree_sitter_org_external_scanner_create() { 306 | Scanner *scanner = (Scanner *)calloc(1, sizeof(Scanner)); 307 | scanner->indent_length_stack = (stack *)calloc(1, sizeof(stack)); 308 | scanner->bullet_stack = (stack *)calloc(1, sizeof(stack)); 309 | scanner->section_stack = (stack *)calloc(1, sizeof(stack)); 310 | deserialize(scanner, NULL, 0); 311 | return scanner; 312 | } 313 | 314 | bool tree_sitter_org_external_scanner_scan(void *payload, TSLexer *lexer, 315 | const bool *valid_symbols) { 316 | Scanner *scanner = (Scanner *)payload; 317 | return scan(scanner, lexer, valid_symbols); 318 | } 319 | 320 | unsigned tree_sitter_org_external_scanner_serialize(void *payload, 321 | char *buffer) { 322 | Scanner *scanner = (Scanner *)payload; 323 | return serialize(scanner, buffer); 324 | } 325 | 326 | void tree_sitter_org_external_scanner_deserialize(void *payload, 327 | const char *buffer, 328 | unsigned length) { 329 | Scanner *scanner = (Scanner *)payload; 330 | deserialize(scanner, buffer, length); 331 | } 332 | 333 | void tree_sitter_org_external_scanner_destroy(void *payload) { 334 | Scanner *scanner = (Scanner *)payload; 335 | VEC_FREE(scanner->indent_length_stack); 336 | VEC_FREE(scanner->bullet_stack); 337 | VEC_FREE(scanner->section_stack); 338 | free(scanner->indent_length_stack); 339 | free(scanner->bullet_stack); 340 | free(scanner->section_stack); 341 | free(scanner); 342 | } 343 | -------------------------------------------------------------------------------- /src/tree_sitter/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_PARSER_H_ 2 | #define TREE_SITTER_PARSER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define ts_builtin_sym_error ((TSSymbol)-1) 13 | #define ts_builtin_sym_end 0 14 | #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 15 | 16 | typedef uint16_t TSStateId; 17 | 18 | #ifndef TREE_SITTER_API_H_ 19 | typedef uint16_t TSSymbol; 20 | typedef uint16_t TSFieldId; 21 | typedef struct TSLanguage TSLanguage; 22 | #endif 23 | 24 | typedef struct { 25 | TSFieldId field_id; 26 | uint8_t child_index; 27 | bool inherited; 28 | } TSFieldMapEntry; 29 | 30 | typedef struct { 31 | uint16_t index; 32 | uint16_t length; 33 | } TSFieldMapSlice; 34 | 35 | typedef struct { 36 | bool visible; 37 | bool named; 38 | bool supertype; 39 | } TSSymbolMetadata; 40 | 41 | typedef struct TSLexer TSLexer; 42 | 43 | struct TSLexer { 44 | int32_t lookahead; 45 | TSSymbol result_symbol; 46 | void (*advance)(TSLexer *, bool); 47 | void (*mark_end)(TSLexer *); 48 | uint32_t (*get_column)(TSLexer *); 49 | bool (*is_at_included_range_start)(const TSLexer *); 50 | bool (*eof)(const TSLexer *); 51 | }; 52 | 53 | typedef enum { 54 | TSParseActionTypeShift, 55 | TSParseActionTypeReduce, 56 | TSParseActionTypeAccept, 57 | TSParseActionTypeRecover, 58 | } TSParseActionType; 59 | 60 | typedef union { 61 | struct { 62 | uint8_t type; 63 | TSStateId state; 64 | bool extra; 65 | bool repetition; 66 | } shift; 67 | struct { 68 | uint8_t type; 69 | uint8_t child_count; 70 | TSSymbol symbol; 71 | int16_t dynamic_precedence; 72 | uint16_t production_id; 73 | } reduce; 74 | uint8_t type; 75 | } TSParseAction; 76 | 77 | typedef struct { 78 | uint16_t lex_state; 79 | uint16_t external_lex_state; 80 | } TSLexMode; 81 | 82 | typedef union { 83 | TSParseAction action; 84 | struct { 85 | uint8_t count; 86 | bool reusable; 87 | } entry; 88 | } TSParseActionEntry; 89 | 90 | struct TSLanguage { 91 | uint32_t version; 92 | uint32_t symbol_count; 93 | uint32_t alias_count; 94 | uint32_t token_count; 95 | uint32_t external_token_count; 96 | uint32_t state_count; 97 | uint32_t large_state_count; 98 | uint32_t production_id_count; 99 | uint32_t field_count; 100 | uint16_t max_alias_sequence_length; 101 | const uint16_t *parse_table; 102 | const uint16_t *small_parse_table; 103 | const uint32_t *small_parse_table_map; 104 | const TSParseActionEntry *parse_actions; 105 | const char * const *symbol_names; 106 | const char * const *field_names; 107 | const TSFieldMapSlice *field_map_slices; 108 | const TSFieldMapEntry *field_map_entries; 109 | const TSSymbolMetadata *symbol_metadata; 110 | const TSSymbol *public_symbol_map; 111 | const uint16_t *alias_map; 112 | const TSSymbol *alias_sequences; 113 | const TSLexMode *lex_modes; 114 | bool (*lex_fn)(TSLexer *, TSStateId); 115 | bool (*keyword_lex_fn)(TSLexer *, TSStateId); 116 | TSSymbol keyword_capture_token; 117 | struct { 118 | const bool *states; 119 | const TSSymbol *symbol_map; 120 | void *(*create)(void); 121 | void (*destroy)(void *); 122 | bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); 123 | unsigned (*serialize)(void *, char *); 124 | void (*deserialize)(void *, const char *, unsigned); 125 | } external_scanner; 126 | const TSStateId *primary_state_ids; 127 | }; 128 | 129 | /* 130 | * Lexer Macros 131 | */ 132 | 133 | #define START_LEXER() \ 134 | bool result = false; \ 135 | bool skip = false; \ 136 | bool eof = false; \ 137 | int32_t lookahead; \ 138 | goto start; \ 139 | next_state: \ 140 | lexer->advance(lexer, skip); \ 141 | start: \ 142 | skip = false; \ 143 | lookahead = lexer->lookahead; 144 | 145 | #define ADVANCE(state_value) \ 146 | { \ 147 | state = state_value; \ 148 | goto next_state; \ 149 | } 150 | 151 | #define SKIP(state_value) \ 152 | { \ 153 | skip = true; \ 154 | state = state_value; \ 155 | goto next_state; \ 156 | } 157 | 158 | #define ACCEPT_TOKEN(symbol_value) \ 159 | result = true; \ 160 | lexer->result_symbol = symbol_value; \ 161 | lexer->mark_end(lexer); 162 | 163 | #define END_STATE() return result; 164 | 165 | /* 166 | * Parse Table Macros 167 | */ 168 | 169 | #define SMALL_STATE(id) id - LARGE_STATE_COUNT 170 | 171 | #define STATE(id) id 172 | 173 | #define ACTIONS(id) id 174 | 175 | #define SHIFT(state_value) \ 176 | {{ \ 177 | .shift = { \ 178 | .type = TSParseActionTypeShift, \ 179 | .state = state_value \ 180 | } \ 181 | }} 182 | 183 | #define SHIFT_REPEAT(state_value) \ 184 | {{ \ 185 | .shift = { \ 186 | .type = TSParseActionTypeShift, \ 187 | .state = state_value, \ 188 | .repetition = true \ 189 | } \ 190 | }} 191 | 192 | #define SHIFT_EXTRA() \ 193 | {{ \ 194 | .shift = { \ 195 | .type = TSParseActionTypeShift, \ 196 | .extra = true \ 197 | } \ 198 | }} 199 | 200 | #define REDUCE(symbol_val, child_count_val, ...) \ 201 | {{ \ 202 | .reduce = { \ 203 | .type = TSParseActionTypeReduce, \ 204 | .symbol = symbol_val, \ 205 | .child_count = child_count_val, \ 206 | __VA_ARGS__ \ 207 | }, \ 208 | }} 209 | 210 | #define RECOVER() \ 211 | {{ \ 212 | .type = TSParseActionTypeRecover \ 213 | }} 214 | 215 | #define ACCEPT_INPUT() \ 216 | {{ \ 217 | .type = TSParseActionTypeAccept \ 218 | }} 219 | 220 | #ifdef __cplusplus 221 | } 222 | #endif 223 | 224 | #endif // TREE_SITTER_PARSER_H_ 225 | --------------------------------------------------------------------------------