From 63e092d47931ba2f061c2136b37b4a770d61956c Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 2 Aug 2024 16:46:39 -0400 Subject: [PATCH 1/2] refactor: extract `tags` prop. parsing into `tags_parser` --- moz-webgpu-cts/src/wpt/metadata.rs | 47 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/moz-webgpu-cts/src/wpt/metadata.rs b/moz-webgpu-cts/src/wpt/metadata.rs index 0591b79..16d4235 100644 --- a/moz-webgpu-cts/src/wpt/metadata.rs +++ b/moz-webgpu-cts/src/wpt/metadata.rs @@ -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( @@ -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>, 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)); From 949b9eaf5c7766bd339f9ecb44bfedffce1bc996 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 5 Aug 2024 17:39:05 -0400 Subject: [PATCH 2/2] fix: allow hyphens in `tags` props. --- moz-webgpu-cts/src/wpt/metadata.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/moz-webgpu-cts/src/wpt/metadata.rs b/moz-webgpu-cts/src/wpt/metadata.rs index 16d4235..fa98fa9 100644 --- a/moz-webgpu-cts/src/wpt/metadata.rs +++ b/moz-webgpu-cts/src/wpt/metadata.rs @@ -181,11 +181,34 @@ 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>, ParseError<'a>> { + use crate::chumsky::{error::Error, util::MaybeRef}; + + let tag_ident = { + let underscore_or_hyphen = |c| matches!(c, '_' | '-'); + any() + .try_map(move |c: char, span| { + if c.is_ascii_alphabetic() || underscore_or_hyphen(c) { + Ok(c) + } else { + Err(Error::<&'a str>::expected_found( + [], + Some(MaybeRef::Val(c)), + span, + )) + } + }) + .then( + any() + .filter(move |c: &char| c.is_ascii_alphanumeric() || underscore_or_hyphen(*c)) + .repeated(), + ) + .to_slice() + }; helper .parser( keyword("tags").to(()), conditional_term, - ascii::ident() + tag_ident .map(|i: &str| i.to_owned()) .separated_by(just(',').padded_by(inline_whitespace())) .collect()