1use pest::iterators::Pair;
2
3use super::{Position, Rule};
4
5#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Import {
7 pub path: String,
8 pub position: Position,
9}
10
11impl Import {
12 pub fn from_pair(pair: Pair<Rule>, file: &str) -> Self {
13 assert_eq!(pair.as_rule(), Rule::importDirective);
14 let (line, col) = pair.line_col();
15
16 let mut inner = pair.into_inner();
17
18 let input_path = inner.next().unwrap_or_else(|| {
19 panic!("No valid input path given!");
20 });
21
22 let path = input_path.as_str();
23
24 Import {
25 path: path.to_owned(),
26 position: (file.to_owned(), line, col),
27 }
28 }
29
30 pub fn is_wildcard(&self) -> bool {
31 self.path.ends_with("::*")
32 }
33}