Skip to main content

sqruff_lib_core/parser/
types.rs

1use super::matchable::Matchable;
2use super::segments::generator::SegmentGenerator;
3
4#[derive(Debug, Clone)]
5pub enum DialectElementType {
6    Matchable(Matchable),
7    SegmentGenerator(SegmentGenerator),
8}
9
10impl From<Matchable> for DialectElementType {
11    fn from(value: Matchable) -> Self {
12        DialectElementType::Matchable(value)
13    }
14}
15
16impl From<SegmentGenerator> for DialectElementType {
17    fn from(value: SegmentGenerator) -> Self {
18        DialectElementType::SegmentGenerator(value)
19    }
20}
21
22/// ParseMode defines the potential parse modes used in grammars
23/// to determine how they handle unmatched segments.
24///
25/// The default behavior is to only claim what they can match. However,
26/// occasionally allowing more eager matching (e.g., in the content of
27/// bracketed expressions) can provide more helpful feedback to the user.
28#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
29pub enum ParseMode {
30    /// Strict mode only returns a match if the full content matches.
31    /// In this mode, if a match is not successful, then no match is returned,
32    /// and unparsable sections are never raised.
33    ///
34    /// Note: This is the default for all grammars.
35    Strict,
36
37    /// Greedy mode will always return a match, provided there is at least
38    /// one code element before any terminators. Terminators are not included
39    /// in the match but are searched for before matching any content. Segments
40    /// that are part of any terminator (or beyond) are not available for
41    /// matching by any content.
42    ///
43    /// Note: This replicates the `GreedyUntil` semantics.
44    Greedy,
45
46    /// A variant of "GREEDY" mode. This mode behaves like "STRICT" if nothing
47    /// matches, but behaves like "GREEDY" once something has matched.
48    ///
49    /// Note: This replicates the `StartsWith` semantics.
50    GreedyOnceStarted,
51    // Additional parsing modes can be added here as necessary.
52}