Skip to content

Commit 63e092d

Browse files
refactor: extract tags prop. parsing into tags_parser
1 parent 714b142 commit 63e092d

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

moz-webgpu-cts/src/wpt/metadata.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,7 @@ impl<'a> Properties<'a> for FileProps {
111111
)
112112
.map(|((), prefs)| FileProp::Prefs(prefs));
113113

114-
let tags = helper
115-
.parser(
116-
keyword("tags").to(()),
117-
conditional_term.clone(),
118-
ascii::ident()
119-
.map(|i: &str| i.to_owned())
120-
.separated_by(just(',').padded_by(inline_whitespace()))
121-
.collect()
122-
.delimited_by(
123-
just('[').padded_by(inline_whitespace()),
124-
just(']').padded_by(inline_whitespace()),
125-
)
126-
.validate(|idents: Vec<_>, e, emitter| {
127-
if idents.is_empty() {
128-
emitter.emit(Rich::custom(e.span(), "no tags specified"));
129-
}
130-
idents
131-
}),
132-
)
133-
.map(|((), tags)| FileProp::Tags(tags));
114+
let tags = tags_parser(helper, conditional_term.clone()).map(FileProp::Tags);
134115

135116
let disabled = helper
136117
.parser(
@@ -196,6 +177,32 @@ impl<'a> Properties<'a> for FileProps {
196177
}
197178
}
198179

180+
fn tags_parser<'a, T>(
181+
helper: &mut PropertiesParseHelper<'a>,
182+
conditional_term: impl Parser<'a, &'a str, T, ParseError<'a>>,
183+
) -> impl Parser<'a, &'a str, PropertyValue<T, Vec<String>>, ParseError<'a>> {
184+
helper
185+
.parser(
186+
keyword("tags").to(()),
187+
conditional_term,
188+
ascii::ident()
189+
.map(|i: &str| i.to_owned())
190+
.separated_by(just(',').padded_by(inline_whitespace()))
191+
.collect()
192+
.delimited_by(
193+
just('[').padded_by(inline_whitespace()),
194+
just(']').padded_by(inline_whitespace()),
195+
)
196+
.validate(|idents: Vec<_>, e, emitter| {
197+
if idents.is_empty() {
198+
emitter.emit(Rich::custom(e.span(), "no tags specified"));
199+
}
200+
idents
201+
}),
202+
)
203+
.map(|((), tags)| tags)
204+
}
205+
199206
#[test]
200207
fn file_props() {
201208
let parser = FileProps::property_parser(&mut PropertiesParseHelper::new(0));

0 commit comments

Comments
 (0)