View raw

1 (** Org — OCaml Org Mode parser library. 2 3 This is the top-level module for the [org] library. It re-exports the public 4 API and sub-modules, providing a convenient namespace for consumers: 5 6 {[ 7 let doc = Org.parse input 8 let headings = doc.Org.Ast.headings 9 ]} *) 10 11 (** {1 Public sub-modules} *) 12 13 module Ast = Ast 14 module Config = Config 15 16 (** {1 Internal sub-modules} 17 18 These are exposed for testing and advanced use. They are not part of the 19 stable public API and may change without notice. *) 20 21 (**/**) 22 23 module Private = struct 24 module Lexer = Lexer 25 module Inline_lexer = Inline_lexer 26 module Parse = Parse 27 module Parser = Parser 28 module Token = Token 29 module Raw_ast = Raw_ast 30 module Prescan = Prescan 31 end 32 33 (**/**) 34 35 (** {1 Parsing entry points} *) 36 37 let version = "0.1.0" 38 39 (** Parse an Org Mode document string into a semantic AST. 40 41 This is the primary entry point. It: 1. Pre-scans for file-local 42 declarations (#+TODO etc.) 2. Lexes the input into structural tokens 3. 43 Parses tokens into a raw document tree (Menhir) 4. Normalizes the raw tree 44 into the semantic AST 45 46 Malformed input degrades gracefully — the parser always produces a 47 best-effort document without raising exceptions for syntax errors. 48 49 @param config 50 Optional document configuration. When omitted, the input is pre-scanned 51 for #+TODO declarations automatically. *) 52 let parse ?config input = 53 let config = match config with Some c -> c | None -> Prescan.scan input in 54 let raw = Parse.document ~config input in 55 Normalize.normalize config raw 56