Skip to content

Commit

Permalink
refactor: extract tags prop. parsing into tags_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Aug 5, 2024
1 parent 06c4a94 commit ffcd60b
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions moz-webgpu-cts/src/wpt/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,7 @@ impl<'a> Properties<'a> for FileProps {
)
.map(|((), prefs)| FileProp::Prefs(prefs));

let tags = helper
.parser(
keyword("tags").to(()),
conditional_term.clone(),
ascii::ident()
.map(|i: &str| i.to_owned())
.separated_by(just(',').padded_by(inline_whitespace()))
.collect()
.delimited_by(
just('[').padded_by(inline_whitespace()),
just(']').padded_by(inline_whitespace()),
)
.validate(|idents: Vec<_>, e, emitter| {
if idents.is_empty() {
emitter.emit(Rich::custom(e.span(), "no tags specified"));
}
idents
}),
)
.map(|((), tags)| FileProp::Tags(tags));
let tags = tags_parser(helper, conditional_term.clone()).map(FileProp::Tags);

let disabled = helper
.parser(
Expand Down Expand Up @@ -196,6 +177,32 @@ impl<'a> Properties<'a> for FileProps {
}
}

fn tags_parser<'a, T>(
helper: &mut PropertiesParseHelper<'a>,
conditional_term: impl Parser<'a, &'a str, T, ParseError<'a>>,
) -> impl Parser<'a, &'a str, PropertyValue<T, Vec<String>>, ParseError<'a>> {
helper
.parser(
keyword("tags").to(()),
conditional_term,
ascii::ident()
.map(|i: &str| i.to_owned())
.separated_by(just(',').padded_by(inline_whitespace()))
.collect()
.delimited_by(
just('[').padded_by(inline_whitespace()),
just(']').padded_by(inline_whitespace()),
)
.validate(|idents: Vec<_>, e, emitter| {
if idents.is_empty() {
emitter.emit(Rich::custom(e.span(), "no tags specified"));
}
idents
}),
)
.map(|((), tags)| tags)
}

#[test]
fn file_props() {
let parser = FileProps::property_parser(&mut PropertiesParseHelper::new(0));
Expand Down

0 comments on commit ffcd60b

Please sign in to comment.