pub fn parse(
src: &str,
file: &Path,
sink: &mut dyn DiagnosticSink,
) -> DiagnosticResult<SyntaxTree>Expand description
Parse a Mosaic source string into a SyntaxTree.
Recoverable diagnostics are emitted to sink (manifest §6 stage 1). 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 only if sink
asks the parse to stop; the in-tree sinks never do.