Skip to main content

parse

Function parse 

Source
pub fn parse(src: &str, file: &Path) -> ParseResult
Expand description

Parse a Mosaic source string. Always returns a ParseResult; the parser is recoverable per manifest §6 stage 1.

§Examples

use std::path::Path;

use mos_parse::{InlineKind, Item, parse};

let result = parse("= Hello\n", Path::new("main.mos"));

assert!(!result.has_errors());
assert!(matches!(result.tree.items[0], Item::Heading { .. }));
let Item::Heading { inlines, .. } = &result.tree.items[0] else {
    unreachable!();
};
assert_eq!(inlines[0].kind, InlineKind::Text);