From 78c67e2ed8aeed33a860d5d7995ac8b353636b28 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 23 Dec 2024 20:37:26 -0800 Subject: [PATCH] Swap inverted to enabled --- src/attribute.rs | 64 ++++++++++++++++++++++---------------------- src/attribute_set.rs | 18 ++++++------- src/parser.rs | 15 +++++------ 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/attribute.rs b/src/attribute.rs index 041af8b0de..2206f5bff6 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -13,17 +13,17 @@ pub(crate) enum Attribute<'src> { Doc(Option>), 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>), - Unix { inverted: bool }, - Windows { inverted: bool }, + Unix { enabled: bool }, + Windows { enabled: bool }, WorkingDirectory(StringLiteral<'src>), } @@ -51,7 +51,7 @@ impl<'src> Attribute<'src> { pub(crate) fn new( name: Name<'src>, arguments: Vec>, - inverted: bool, + enabled: bool, ) -> CompileResult<'src, Self> { let discriminant = name .lexeme() @@ -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()) } }) @@ -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) diff --git a/src/attribute_set.rs b/src/attribute_set.rs index 96c1c049a4..a5213d4793 100644 --- a/src/attribute_set.rs +++ b/src/attribute_set.rs @@ -24,18 +24,18 @@ impl<'src> AttributeSet<'src> { ) -> Option { 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"), }) }) } diff --git a/src/parser.rs b/src/parser.rs index a43b33699f..6fa8a8ab66 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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(); @@ -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() {