Skip to main content

meta_language/
network_projection.rs

1use crate::link_network::{Link, LinkType};
2
3/// View of a links network with lower-level data optionally stripped away.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum NetworkProjection {
6    /// Full lossless network, including all source-preservation links.
7    Lossless,
8    /// Concrete syntax view, including tokens, trivia, fields, and spans.
9    ConcreteSyntax,
10    /// Abstract syntax view, excluding lossless token and trivia links.
11    AbstractSyntax,
12    /// Meaning-focused view, keeping semantic, concept, type, and language links.
13    Semantic,
14}
15
16impl NetworkProjection {
17    /// Human-readable projection name.
18    #[must_use]
19    pub const fn label(self) -> &'static str {
20        match self {
21            Self::Lossless => "lossless",
22            Self::ConcreteSyntax => "concrete syntax",
23            Self::AbstractSyntax => "abstract syntax",
24            Self::Semantic => "semantic",
25        }
26    }
27
28    pub(crate) fn includes(self, link: &Link) -> bool {
29        match self {
30            Self::Lossless => true,
31            Self::ConcreteSyntax => link.metadata().link_type() != Some(LinkType::Semantic),
32            Self::AbstractSyntax => !matches!(
33                link.metadata().link_type(),
34                Some(LinkType::Token | LinkType::Trivia)
35            ),
36            Self::Semantic => matches!(
37                link.metadata().link_type(),
38                Some(LinkType::Semantic | LinkType::Concept | LinkType::Type | LinkType::Language)
39            ),
40        }
41    }
42}