Skip to content

Commit

Permalink
command: use HashSet for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed Jun 13, 2024
1 parent 2bd0058 commit 7aec20b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::VecDeque;
use std::collections::{HashSet, VecDeque};
use std::error::Error;

/// A block, consisting of multiple commands.
Expand All @@ -24,7 +24,7 @@ pub struct Command {
/// The command prefix, if given.
pub prefix: Option<String>,
/// Any command tags, if given.
pub tags: Vec<String>,
pub tags: HashSet<String>,
/// Silences the output of this command. This is handled automatically, the
/// [`Runner`](crate::Runner) does not have to take this into account.
pub silent: bool,
Expand Down
6 changes: 4 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use crate::command::{Argument, Block, Command};

use nom::branch::alt;
Expand Down Expand Up @@ -134,12 +136,12 @@ fn argument(input: Span) -> IResult<Argument> {
}

/// Parses a list of []-delimited command tags separated by comma or whitespace.
fn tags(input: Span) -> IResult<Vec<String>> {
fn tags(input: Span) -> IResult<HashSet<String>> {
let (input, tags) = opt(preceded(
space1,
delimited(tag("["), separated_list1(one_of(", "), string), tag("]")),
))(input)?;
Ok((input, tags.unwrap_or_default()))
Ok((input, HashSet::from_iter(tags.unwrap_or_default())))
}

/// Parses a command/output separator: --- followed by a line ending.
Expand Down

0 comments on commit 7aec20b

Please sign in to comment.