Skip to main content

meta_language/
verification.rs

1use crate::link_network::LinkId;
2use crate::source::SourceSpan;
3
4/// Verification issue kind for a full-match check.
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub enum VerificationIssueKind {
7    /// A link explicitly marks a parse error.
8    ErrorLink,
9    /// A link marks source text missing from the parse.
10    MissingLink,
11    /// A link contains a parse error below it.
12    HasErrorLink,
13}
14
15/// One verification issue tied to a link.
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct VerificationIssue {
18    link_id: LinkId,
19    kind: VerificationIssueKind,
20    span: Option<SourceSpan>,
21}
22
23impl VerificationIssue {
24    pub(crate) const fn new(
25        link_id: LinkId,
26        kind: VerificationIssueKind,
27        span: Option<SourceSpan>,
28    ) -> Self {
29        Self {
30            link_id,
31            kind,
32            span,
33        }
34    }
35
36    /// Link that caused the issue.
37    #[must_use]
38    pub const fn link_id(&self) -> LinkId {
39        self.link_id
40    }
41
42    /// Issue kind.
43    #[must_use]
44    pub const fn kind(&self) -> VerificationIssueKind {
45        self.kind
46    }
47
48    /// Source span attached to the issue link, when available.
49    #[must_use]
50    pub const fn span(&self) -> Option<SourceSpan> {
51        self.span
52    }
53}
54
55/// Result of verifying that a source region fully matches a language.
56#[derive(Clone, Debug, PartialEq, Eq)]
57pub struct VerificationReport {
58    issues: Vec<VerificationIssue>,
59}
60
61impl VerificationReport {
62    pub(crate) const fn new(issues: Vec<VerificationIssue>) -> Self {
63        Self { issues }
64    }
65
66    /// Whether the verified region has no error or missing links.
67    #[must_use]
68    pub fn is_clean(&self) -> bool {
69        self.issues.is_empty()
70    }
71
72    /// Verification issues found in the region.
73    #[must_use]
74    pub fn issues(&self) -> &[VerificationIssue] {
75        &self.issues
76    }
77}