Skip to content

Commit 75506d3

Browse files
fix: loop to parse all derive attributes separated by a comma
1 parent 27fadb6 commit 75506d3

File tree

1 file changed

+69
-64
lines changed

1 file changed

+69
-64
lines changed

derive/src/generate.rs

+69-64
Original file line numberDiff line numberDiff line change
@@ -228,50 +228,67 @@ fn read_type_attributes(attributes: Vec<syn::Attribute>) -> Result<TypeAttribute
228228
syn::Meta::List(list) => {
229229
let mut tokens = list.tokens.into_iter();
230230

231-
match tokens.next() {
232-
Some(TokenTree::Ident(id)) => {
233-
if id == "prefix" {
234-
match tokens.next() {
235-
Some(TokenTree::Group(g)) => {
236-
let (prefix, suffix) =
237-
parse_prefix_binding(g.stream(), span)?;
238-
result.prefixes.insert(prefix, suffix);
239-
}
240-
Some(token) => {
241-
return Err(Error::InvalidAttribute(
242-
AttributeError::UnexpectedToken,
243-
token.span(),
244-
))
245-
}
246-
None => {
247-
return Err(Error::InvalidAttribute(
248-
AttributeError::MissingPrefixBinding,
249-
span,
250-
))
231+
while let Some(token) = tokens.next() {
232+
match token {
233+
TokenTree::Ident(id) => {
234+
if id == "prefix" {
235+
match tokens.next() {
236+
Some(TokenTree::Group(g)) => {
237+
let (prefix, suffix) =
238+
parse_prefix_binding(g.stream(), span)?;
239+
result.prefixes.insert(prefix, suffix);
240+
}
241+
Some(token) => {
242+
return Err(Error::InvalidAttribute(
243+
AttributeError::UnexpectedToken,
244+
token.span(),
245+
))
246+
}
247+
None => {
248+
return Err(Error::InvalidAttribute(
249+
AttributeError::MissingPrefixBinding,
250+
span,
251+
))
252+
}
251253
}
252-
}
253-
} else if id == "type" {
254-
match tokens.next() {
255-
Some(TokenTree::Punct(p)) if p.as_char() == '=' => match tokens
256-
.next()
257-
{
258-
Some(TokenTree::Literal(l)) => {
259-
let span = l.span();
260-
match syn::Lit::new(l) {
261-
syn::Lit::Str(s) => match IriBuf::new(s.value()) {
262-
Ok(iri) => {
263-
result.type_ = Some(CompactIri(iri, span))
264-
}
265-
Err(_) => {
266-
return Err(Error::InvalidAttribute(
267-
AttributeError::InvalidType,
268-
span,
269-
))
254+
} else if id == "type" {
255+
match tokens.next() {
256+
Some(TokenTree::Punct(p)) if p.as_char() == '=' => {
257+
match tokens.next() {
258+
Some(TokenTree::Literal(l)) => {
259+
let span = l.span();
260+
match syn::Lit::new(l) {
261+
syn::Lit::Str(s) => {
262+
match IriBuf::new(s.value()) {
263+
Ok(iri) => {
264+
result.type_ =
265+
Some(CompactIri(iri, span))
266+
}
267+
Err(_) => return Err(
268+
Error::InvalidAttribute(
269+
AttributeError::InvalidType,
270+
span,
271+
),
272+
),
273+
}
274+
}
275+
_ => {
276+
return Err(Error::InvalidAttribute(
277+
AttributeError::InvalidType,
278+
span,
279+
))
280+
}
270281
}
271-
},
272-
_ => {
282+
}
283+
Some(token) => {
284+
return Err(Error::InvalidAttribute(
285+
AttributeError::UnexpectedToken,
286+
token.span(),
287+
))
288+
}
289+
None => {
273290
return Err(Error::InvalidAttribute(
274-
AttributeError::InvalidType,
291+
AttributeError::MissingType,
275292
span,
276293
))
277294
}
@@ -289,34 +306,22 @@ fn read_type_attributes(attributes: Vec<syn::Attribute>) -> Result<TypeAttribute
289306
span,
290307
))
291308
}
292-
},
293-
Some(token) => {
294-
return Err(Error::InvalidAttribute(
295-
AttributeError::UnexpectedToken,
296-
token.span(),
297-
))
298-
}
299-
None => {
300-
return Err(Error::InvalidAttribute(
301-
AttributeError::MissingType,
302-
span,
303-
))
304309
}
310+
} else {
311+
return Err(Error::InvalidAttribute(
312+
AttributeError::UnknownIdent,
313+
id.span(),
314+
));
305315
}
306-
} else {
316+
}
317+
TokenTree::Punct(p) if p.as_char() == ',' => {}
318+
token => {
307319
return Err(Error::InvalidAttribute(
308-
AttributeError::UnknownIdent,
309-
id.span(),
310-
));
320+
AttributeError::UnexpectedToken,
321+
token.span(),
322+
))
311323
}
312324
}
313-
Some(token) => {
314-
return Err(Error::InvalidAttribute(
315-
AttributeError::UnexpectedToken,
316-
token.span(),
317-
))
318-
}
319-
None => return Err(Error::InvalidAttribute(AttributeError::Empty, span)),
320325
}
321326
}
322327
_ => {

0 commit comments

Comments
 (0)