mf2_model/frontend.rs
1//! The parser boundary: what `mf2-syntax` implements, and what an
2//! `ox_mf2_parser` adapter would implement if the D1 gate were not met.
3
4use crate::diagnostic::Diagnostics;
5use crate::message::Message;
6
7/// The result of parsing one message.
8#[derive(Clone, PartialEq, Eq, Debug)]
9pub struct Parsed<'src> {
10 /// `Some` whenever the source has no syntax error — also when it has
11 /// data-model errors, which are then in `diagnostics`.
12 pub message: Option<Message<'src>>,
13 /// Every syntax error the frontend could recover to (with spans); when
14 /// there is none, every data-model error.
15 pub diagnostics: Diagnostics,
16}
17
18/// A parser from MF2 source to the data model.
19pub trait Frontend {
20 /// `&mut self` lets an implementation keep scratch state across calls (the
21 /// gate's "reused" rows); the returned model borrows only the source.
22 fn parse<'src>(&mut self, source: &'src str) -> Parsed<'src>;
23}