* Fix clippy lints in tests * Replace `format!` in `.push_str()` with `write!` Stylistically that might be a bit rough but elides an allocation. Fallibility of allocation is more explicit, but ignored with `let _ =` like in the clippy example: https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string * Remove unused lifetime * Fix macro crate relative import * Derive `Eq` for `PartialEq` with `Eq` members https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq * Remove unnnecessary `.to_string()` for Cow<str> * Remove `.to_string()` for `tendril::Tendril` Implements `Deref<Target = str>`
74 lines
1.9 KiB
Rust
74 lines
1.9 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{span, ModuleId, Span};
|
|
use std::collections::HashSet;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum ImportPatternMember {
|
|
Glob { span: Span },
|
|
Name { name: Vec<u8>, span: Span },
|
|
List { names: Vec<(Vec<u8>, Span)> },
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ImportPatternHead {
|
|
pub name: Vec<u8>,
|
|
pub id: Option<ModuleId>,
|
|
pub span: Span,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ImportPattern {
|
|
pub head: ImportPatternHead,
|
|
pub members: Vec<ImportPatternMember>,
|
|
// 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>>,
|
|
}
|
|
|
|
impl ImportPattern {
|
|
pub fn new() -> Self {
|
|
ImportPattern {
|
|
head: ImportPatternHead {
|
|
name: vec![],
|
|
id: None,
|
|
span: Span { start: 0, end: 0 },
|
|
},
|
|
members: vec![],
|
|
hidden: HashSet::new(),
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
pub fn with_hidden(self, hidden: HashSet<Vec<u8>>) -> Self {
|
|
ImportPattern {
|
|
head: self.head,
|
|
members: self.members,
|
|
hidden,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for ImportPattern {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|