Skip to main content

meta_language/
configuration.rs

1/// Trivia attachment strategy.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum TriviaAttachmentPolicy {
4    /// Attach trivia to the containing syntax link.
5    ContainmentLink,
6    /// Attach trivia to the token link.
7    TokenLink,
8    /// Emit both attachment links when they can coexist.
9    Both,
10}
11
12/// Region detection strategy for mixed-language parsing.
13#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum RegionDetectionPolicy {
15    /// Use explicit region names such as fenced-code language tags.
16    NameDriven,
17    /// Use content sniffing.
18    ContentDriven,
19    /// Use name-driven detection first and content-driven detection as a fallback.
20    Both,
21}
22
23/// Configuration for parse-to-network operations.
24#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub struct ParseConfiguration {
26    trivia_attachment_policy: TriviaAttachmentPolicy,
27    region_detection_policy: RegionDetectionPolicy,
28}
29
30impl ParseConfiguration {
31    /// Creates parse configuration with the supplied trivia policy.
32    #[must_use]
33    pub const fn new(trivia_attachment_policy: TriviaAttachmentPolicy) -> Self {
34        Self {
35            trivia_attachment_policy,
36            region_detection_policy: RegionDetectionPolicy::Both,
37        }
38    }
39
40    /// Returns configuration with a mixed-language region detection policy.
41    #[must_use]
42    pub const fn with_region_detection_policy(
43        mut self,
44        region_detection_policy: RegionDetectionPolicy,
45    ) -> Self {
46        self.region_detection_policy = region_detection_policy;
47        self
48    }
49
50    /// Trivia attachment policy.
51    #[must_use]
52    pub const fn trivia_attachment_policy(self) -> TriviaAttachmentPolicy {
53        self.trivia_attachment_policy
54    }
55
56    /// Mixed-language region detection policy.
57    #[must_use]
58    pub const fn region_detection_policy(self) -> RegionDetectionPolicy {
59        self.region_detection_policy
60    }
61}
62
63impl Default for ParseConfiguration {
64    fn default() -> Self {
65        Self::new(TriviaAttachmentPolicy::Both)
66    }
67}