2022-03-07 21:08:56 +01:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-05-07 21:39:22 +02:00
|
|
|
use crate::{span, ModuleId, Span};
|
2021-11-30 07:14:05 +01:00
|
|
|
use std::collections::HashSet;
|
2021-09-26 20:39:19 +02:00
|
|
|
|
2022-06-04 08:47:36 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2021-09-26 20:39:19 +02:00
|
|
|
pub enum ImportPatternMember {
|
|
|
|
Glob { span: Span },
|
|
|
|
Name { name: Vec<u8>, span: Span },
|
2021-09-27 02:23:22 +02:00
|
|
|
List { names: Vec<(Vec<u8>, Span)> },
|
2021-09-26 20:39:19 +02:00
|
|
|
}
|
|
|
|
|
2022-06-04 08:47:36 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2021-11-16 00:16:06 +01:00
|
|
|
pub struct ImportPatternHead {
|
|
|
|
pub name: Vec<u8>,
|
2022-05-07 21:39:22 +02:00
|
|
|
pub id: Option<ModuleId>,
|
2021-11-16 00:16:06 +01:00
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2022-06-04 08:47:36 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
2021-09-26 20:39:19 +02:00
|
|
|
pub struct ImportPattern {
|
2021-11-16 00:16:06 +01:00
|
|
|
pub head: ImportPatternHead,
|
2021-09-26 20:39:19 +02:00
|
|
|
pub members: Vec<ImportPatternMember>,
|
2021-11-30 07:14:05 +01:00
|
|
|
// communicate to eval which decls/aliases were hidden during `parse_hide()` so it does not
|
|
|
|
// interpret these as env var names:
|
|
|
|
pub hidden: HashSet<Vec<u8>>,
|
2021-09-26 20:39:19 +02:00
|
|
|
}
|
2021-11-16 00:16:06 +01:00
|
|
|
|
|
|
|
impl ImportPattern {
|
2021-12-03 20:49:11 +01:00
|
|
|
pub fn new() -> Self {
|
|
|
|
ImportPattern {
|
|
|
|
head: ImportPatternHead {
|
|
|
|
name: vec![],
|
2022-02-18 02:58:24 +01:00
|
|
|
id: None,
|
2022-12-03 10:44:12 +01:00
|
|
|
span: Span::unknown(),
|
2021-12-03 20:49:11 +01:00
|
|
|
},
|
|
|
|
members: vec![],
|
|
|
|
hidden: HashSet::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 00:16:06 +01:00
|
|
|
pub fn span(&self) -> Span {
|
|
|
|
let mut spans = vec![self.head.span];
|
|
|
|
|
|
|
|
for member in &self.members {
|
|
|
|
match member {
|
|
|
|
ImportPatternMember::Glob { span } => spans.push(*span),
|
|
|
|
ImportPatternMember::Name { name: _, span } => spans.push(*span),
|
|
|
|
ImportPatternMember::List { names } => {
|
|
|
|
for (_, span) in names {
|
|
|
|
spans.push(*span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
span(&spans)
|
|
|
|
}
|
2021-11-30 07:14:05 +01:00
|
|
|
|
|
|
|
pub fn with_hidden(self, hidden: HashSet<Vec<u8>>) -> Self {
|
|
|
|
ImportPattern {
|
|
|
|
head: self.head,
|
|
|
|
members: self.members,
|
|
|
|
hidden,
|
|
|
|
}
|
|
|
|
}
|
2021-11-16 00:16:06 +01:00
|
|
|
}
|
2021-12-03 20:49:11 +01:00
|
|
|
|
|
|
|
impl Default for ImportPattern {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|