aldrin_parser/ast/
import_stmt.rs

1use super::{Comment, Ident, Prelude};
2use crate::error::ImportNotFound;
3use crate::grammar::Rule;
4use crate::validate::Validate;
5use crate::warning::UnusedImport;
6use crate::Span;
7use pest::iterators::Pair;
8
9#[derive(Debug, Clone)]
10pub struct ImportStmt {
11    span: Span,
12    comment: Vec<Comment>,
13    schema_name: Ident,
14}
15
16impl ImportStmt {
17    pub(crate) fn parse(pair: Pair<Rule>) -> Self {
18        assert_eq!(pair.as_rule(), Rule::import_stmt);
19
20        let span = Span::from_pair(&pair);
21        let mut pairs = pair.into_inner();
22        let mut prelude = Prelude::regular(&mut pairs);
23
24        pairs.next().unwrap(); // Skip keyword
25
26        let pair = pairs.next().unwrap();
27        let schema_name = Ident::parse(pair);
28
29        Self {
30            span,
31            comment: prelude.take_comment(),
32            schema_name,
33        }
34    }
35
36    pub(crate) fn validate(&self, validate: &mut Validate) {
37        ImportNotFound::validate(self, validate);
38        UnusedImport::validate(self, validate);
39    }
40
41    pub fn span(&self) -> Span {
42        self.span
43    }
44
45    pub fn comment(&self) -> &[Comment] {
46        &self.comment
47    }
48
49    pub fn schema_name(&self) -> &Ident {
50        &self.schema_name
51    }
52}