sqruff_lib_core/parser/segments/
meta.rs1use std::fmt::Debug;
2
3use ahash::AHashSet;
4
5use super::base::ErasedSegment;
6use crate::dialects::syntax::{SyntaxKind, SyntaxSet};
7use crate::errors::SQLParseError;
8use crate::parser::context::ParseContext;
9use crate::parser::match_result::MatchResult;
10use crate::parser::matchable::{Matchable, MatchableTrait};
11
12pub type Indent = MetaSegment;
13
14#[derive(Debug, Clone, PartialEq)]
15pub struct MetaSegment {
16 id: u32,
17 pub(crate) kind: SyntaxKind,
18}
19
20impl MetaSegment {
21 pub fn from_kind(kind: SyntaxKind) -> Self {
22 Self { kind, id: 0 }
23 }
24
25 pub fn indent() -> Self {
26 Self::from_kind(SyntaxKind::Indent)
27 }
28
29 pub fn dedent() -> Self {
30 Self::from_kind(SyntaxKind::Dedent)
31 }
32
33 pub fn implicit_indent() -> Self {
34 Self::from_kind(SyntaxKind::Implicit)
35 }
36}
37
38impl MatchableTrait for MetaSegment {
39 fn elements(&self) -> &[Matchable] {
40 &[]
41 }
42
43 fn simple(
44 &self,
45 _parse_context: &ParseContext,
46 _crumbs: Option<Vec<&str>>,
47 ) -> Option<(AHashSet<String>, SyntaxSet)> {
48 None
49 }
50
51 fn match_segments(
52 &self,
53 _segments: &[ErasedSegment],
54 _idx: u32,
55 _parse_context: &mut ParseContext,
56 ) -> Result<MatchResult, SQLParseError> {
57 panic!(
58 "{} has no match method, it should only be used in a Sequence!",
59 std::any::type_name::<Self>()
60 );
61 }
62}