Skip to content

Commit 9dc142a

Browse files
committed
AttributeSet
1 parent 1aa440c commit 9dc142a

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
/// An alias, e.g. `name := target`
44
#[derive(Debug, PartialEq, Clone, Serialize)]
55
pub(crate) struct Alias<'src, T = Rc<Recipe<'src>>> {
6-
pub(crate) attributes: BTreeSet<Attribute<'src>>,
6+
pub(crate) attributes: AttributeSet<'src>,
77
pub(crate) name: Name<'src>,
88
#[serde(
99
bound(serialize = "T: Keyed<'src>"),

src/attribute.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,53 @@ impl<'src> Display for Attribute<'src> {
135135
}
136136
}
137137

138+
#[derive(Debug, Clone, PartialEq)]
139+
pub(crate) struct AttributeSet<'src> {
140+
inner: BTreeSet<Attribute<'src>>,
141+
}
142+
143+
impl<'src> Serialize for AttributeSet<'src> {
144+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
145+
where
146+
S: Serializer,
147+
{
148+
self.inner.serialize(serializer)
149+
}
150+
}
151+
152+
impl<'src> AttributeSet<'src> {
153+
pub(crate) fn empty() -> Self {
154+
Self {
155+
inner: BTreeSet::new(),
156+
}
157+
}
158+
159+
pub(crate) fn from_set(input: BTreeSet<Attribute<'src>>) -> Self {
160+
Self { inner: input }
161+
}
162+
163+
pub(crate) fn contains(&self, attribute: &Attribute) -> bool {
164+
self.inner.contains(attribute)
165+
}
166+
167+
//pub(crate) fn ensure_validity(&self, valid_attributes:
168+
169+
/// Get the names of all Group attributes defined in this attribute set
170+
pub(crate) fn groups(&self) -> Vec<&StringLiteral<'src>> {
171+
self
172+
.inner
173+
.iter()
174+
.filter_map(|attr| {
175+
if let Attribute::Group(name) = attr {
176+
Some(name)
177+
} else {
178+
None
179+
}
180+
})
181+
.collect()
182+
}
183+
}
184+
138185
#[cfg(test)]
139186
mod tests {
140187
use super::*;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pub(crate) use {
88
crate::{
99
alias::Alias, analyzer::Analyzer, argument_parser::ArgumentParser, assignment::Assignment,
10-
assignment_resolver::AssignmentResolver, ast::Ast, attribute::Attribute, binding::Binding,
10+
assignment_resolver::AssignmentResolver, ast::Ast, attribute::{Attribute, AttributeSet}, binding::Binding,
1111
color::Color, color_display::ColorDisplay, command_color::CommandColor,
1212
command_ext::CommandExt, compilation::Compilation, compile_error::CompileError,
1313
compile_error_kind::CompileErrorKind, compiler::Compiler, condition::Condition,

src/parser.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ impl<'run, 'src> Parser<'run, 'src> {
339339
} else if self.next_is(Identifier) {
340340
match Keyword::from_lexeme(next.lexeme()) {
341341
Some(Keyword::Alias) if self.next_are(&[Identifier, Identifier, ColonEquals]) => {
342-
items.push(Item::Alias(self.parse_alias(take_attributes())?));
342+
items.push(Item::Alias(
343+
self.parse_alias(AttributeSet::from_set(take_attributes()))?,
344+
));
343345
}
344346
Some(Keyword::Export) if self.next_are(&[Identifier, Identifier, ColonEquals]) => {
345347
self.presume_keyword(Keyword::Export)?;
@@ -462,7 +464,7 @@ impl<'run, 'src> Parser<'run, 'src> {
462464
/// Parse an alias, e.g `alias name := target`
463465
fn parse_alias(
464466
&mut self,
465-
attributes: BTreeSet<Attribute<'src>>,
467+
attributes: AttributeSet<'src>,
466468
) -> CompileResult<'src, Alias<'src, Name<'src>>> {
467469
self.presume_keyword(Keyword::Alias)?;
468470
let name = self.parse_name()?;

0 commit comments

Comments
 (0)