1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Parser for the Mosaic source language (`.mos`).
//!
//! See manifest §3 (language design) and §6 stages 1–2 (parse + lower).
//! Currently covers:
//!
//! - `= Heading` / `== Subheading` / `=== Subsubheading`,
//! - paragraphs (newline-joined non-empty line groups),
//! - inline `*emphasis*`, `**strong**`, and `` `inline code` ``,
//! - `#set name(...)` blocks, recorded with span and name but interpreted
//! later by the evaluator,
//! - `#image(...)`, `#figure(...)`, and `#bibliography(...)` directives,
//! sharing the same `key: value` body grammar as `#set` plus an optional
//! leading positional string literal (`#image("path.png")`,
//! `#bibliography("refs.bib")`),
//! - raw `#pre[[...]]` and `#code[[...]]` long-bracket blocks,
//! - `<label>` attached to the preceding block (trailing on a heading or
//! leading on a paragraph), and `@label` cross-references as inline
//! [`InlineKind::Reference`] runs (manifest §3.3 and the MVP 1
//! resolver),
//! - `[@key]` citations as inline [`InlineKind::Citation`] runs. Only
//! the single-key form is recognised in this slice; bibliography
//! loading and rendering are deferred to MVP 4.
//!
//! Anything outside that subset is preserved as text and a recoverable
//! diagnostic is emitted; the parser never panics on user input
//! (manifest §31).
use Path;
use ;
pub use ;
use Parser;
/// Parse a Mosaic source string, emitting recoverable diagnostics to
/// `sink` (manifest §6 stage 1). Returns the [`SyntaxTree`]; the parser
/// never structurally aborts, so the `Err` arm only fires if the sink
/// itself asks to stop.
///
/// # Examples
///
/// ```
/// use std::path::Path;
///
/// use mos_core::CollectingSink;
/// use mos_parse::{InlineKind, Item, parse};
///
/// let mut sink = CollectingSink::new();
/// let result = parse("= Hello\n", Path::new("main.mos"), &mut sink);
/// assert!(result.is_ok(), "parse structurally aborted: {result:?}");
/// if let Ok(tree) = result {
///
/// assert!(!sink.had_error());
/// assert!(matches!(tree.items[0], Item::Heading { .. }));
/// if let Item::Heading { inlines, .. } = &tree.items[0] {
/// assert_eq!(inlines[0].kind, InlineKind::Text);
/// }
/// }
/// ```
///
/// # Errors
///
/// Returns [`DiagnosticAbort`](mos_core::DiagnosticAbort) only if `sink`
/// asks the parse to stop; the in-tree sinks never do.