Skip to content

Commit

Permalink
Swap inverted to enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Dec 24, 2024
1 parent eefe0a0 commit 78c67e2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 49 deletions.
64 changes: 32 additions & 32 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ pub(crate) enum Attribute<'src> {
Doc(Option<StringLiteral<'src>>),
Extension(StringLiteral<'src>),
Group(StringLiteral<'src>),
Linux { inverted: bool },
Macos { inverted: bool },
Linux { enabled: bool },
Macos { enabled: bool },
NoCd,
NoExitMessage,
NoQuiet,
Openbsd { inverted: bool },
Openbsd { enabled: bool },
PositionalArguments,
Private,
Script(Option<Interpreter<'src>>),
Unix { inverted: bool },
Windows { inverted: bool },
Unix { enabled: bool },
Windows { enabled: bool },
WorkingDirectory(StringLiteral<'src>),
}

Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'src> Attribute<'src> {
pub(crate) fn new(
name: Name<'src>,
arguments: Vec<StringLiteral<'src>>,
inverted: bool,
enabled: bool,
) -> CompileResult<'src, Self> {
let discriminant = name
.lexeme()
Expand All @@ -76,38 +76,38 @@ impl<'src> Attribute<'src> {
);
}

Ok(match (inverted, discriminant) {
(inverted, AttributeDiscriminant::Linux) => Self::Linux { inverted },
(inverted, AttributeDiscriminant::Macos) => Self::Macos { inverted },
(inverted, AttributeDiscriminant::Unix) => Self::Unix { inverted },
(inverted, AttributeDiscriminant::Windows) => Self::Windows { inverted },
(inverted, AttributeDiscriminant::Openbsd) => Self::Openbsd { inverted },
Ok(match (enabled, discriminant) {
(enabled, AttributeDiscriminant::Linux) => Self::Linux { enabled },
(enabled, AttributeDiscriminant::Macos) => Self::Macos { enabled },
(enabled, AttributeDiscriminant::Unix) => Self::Unix { enabled },
(enabled, AttributeDiscriminant::Windows) => Self::Windows { enabled },
(enabled, AttributeDiscriminant::Openbsd) => Self::Openbsd { enabled },

(true, _attr) => {
(false, _attr) => {
return Err(name.error(CompileErrorKind::InvalidInvertedAttribute {
attr_name: name.lexeme(),
}))
}

(false, AttributeDiscriminant::Confirm) => Self::Confirm(arguments.into_iter().next()),
(false, AttributeDiscriminant::Doc) => Self::Doc(arguments.into_iter().next()),
(false, AttributeDiscriminant::Extension) => {
(true, AttributeDiscriminant::Confirm) => Self::Confirm(arguments.into_iter().next()),
(true, AttributeDiscriminant::Doc) => Self::Doc(arguments.into_iter().next()),
(true, AttributeDiscriminant::Extension) => {
Self::Extension(arguments.into_iter().next().unwrap())
}
(false, AttributeDiscriminant::Group) => Self::Group(arguments.into_iter().next().unwrap()),
(false, AttributeDiscriminant::NoCd) => Self::NoCd,
(false, AttributeDiscriminant::NoExitMessage) => Self::NoExitMessage,
(false, AttributeDiscriminant::NoQuiet) => Self::NoQuiet,
(false, AttributeDiscriminant::PositionalArguments) => Self::PositionalArguments,
(false, AttributeDiscriminant::Private) => Self::Private,
(false, AttributeDiscriminant::Script) => Self::Script({
(true, AttributeDiscriminant::Group) => Self::Group(arguments.into_iter().next().unwrap()),
(true, AttributeDiscriminant::NoCd) => Self::NoCd,
(true, AttributeDiscriminant::NoExitMessage) => Self::NoExitMessage,
(true, AttributeDiscriminant::NoQuiet) => Self::NoQuiet,
(true, AttributeDiscriminant::PositionalArguments) => Self::PositionalArguments,
(true, AttributeDiscriminant::Private) => Self::Private,
(true, AttributeDiscriminant::Script) => Self::Script({
let mut arguments = arguments.into_iter();
arguments.next().map(|command| Interpreter {
command,
arguments: arguments.collect(),
})
}),
(false, AttributeDiscriminant::WorkingDirectory) => {
(true, AttributeDiscriminant::WorkingDirectory) => {
Self::WorkingDirectory(arguments.into_iter().next().unwrap())
}
})
Expand Down Expand Up @@ -137,15 +137,15 @@ impl Display for Attribute<'_> {
| Self::Group(argument)
| Self::WorkingDirectory(argument) => write!(f, "{name}({argument})")?,
Self::Script(Some(shell)) => write!(f, "{name}({shell})")?,
Self::Linux { inverted }
| Self::Macos { inverted }
| Self::Unix { inverted }
| Self::Openbsd { inverted }
| Self::Windows { inverted } => {
if *inverted {
write!(f, "not({name})")?;
} else {
Self::Linux { enabled }
| Self::Macos { enabled }
| Self::Unix { enabled }
| Self::Openbsd { enabled }
| Self::Windows { enabled } => {
if *enabled {
write!(f, "{name}")?;
} else {
write!(f, "not({name})")?;
}
}
Self::Confirm(None)
Expand Down
18 changes: 9 additions & 9 deletions src/attribute_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ impl<'src> AttributeSet<'src> {
) -> Option<InvertedStatus> {
self.get(target).and_then(|attr| {
Some(match attr {
Attribute::Linux { inverted }
| Attribute::Macos { inverted }
| Attribute::Openbsd { inverted }
| Attribute::Unix { inverted }
| Attribute::Windows { inverted } => {
if *inverted {
InvertedStatus::Inverted
} else {
Attribute::Linux { enabled }
| Attribute::Macos { enabled }
| Attribute::Openbsd { enabled }
| Attribute::Unix { enabled }
| Attribute::Windows { enabled } => {
if *enabled {
InvertedStatus::Normal
} else {
InvertedStatus::Inverted
}
}
_ => return None,
_ => panic!("contains_invertible called with non-invertible attribute"),
})
})
}
Expand Down
15 changes: 7 additions & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,16 +1136,15 @@ impl<'run, 'src> Parser<'run, 'src> {

loop {
let (name, inverted) = {
let mut i = false;
let mut n = self.parse_name()?;
if n.lexeme() == "not" {
i = true;
let name = self.parse_name()?;
if name.lexeme() == "not" {
self.expect(ParenL)?;
n = self.parse_name()?;
let name = self.parse_name()?;
self.expect(ParenR)?;
(name, true)
} else {
(name, false)
}

(n, i)
};

let mut arguments = Vec::new();
Expand All @@ -1163,7 +1162,7 @@ impl<'run, 'src> Parser<'run, 'src> {
self.expect(ParenR)?;
}

let attribute = Attribute::new(name, arguments, inverted)?;
let attribute = Attribute::new(name, arguments, !inverted)?;

let first = attributes.get(&attribute).or_else(|| {
if attribute.repeatable() {
Expand Down

0 comments on commit 78c67e2

Please sign in to comment.