mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-04 23:30:53 +00:00
Error instead of infinite loop when parsing enum without a derive attribute in derive_parser! (#391)
This commit is contained in:
parent
74ff9ebf96
commit
5edfeb04eb
1 changed files with 15 additions and 6 deletions
|
@ -22,14 +22,23 @@ impl Parse for ParseDefinitions {
|
||||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||||
let token_type = input.parse::<ItemEnum>()?;
|
let token_type = input.parse::<ItemEnum>()?;
|
||||||
let mut additional_enums = FxHashMap::default();
|
let mut additional_enums = FxHashMap::default();
|
||||||
while input.peek(Token![#]) {
|
|
||||||
let enum_ = input.parse::<ItemEnum>()?;
|
|
||||||
additional_enums.insert(enum_.ident.clone(), enum_);
|
|
||||||
}
|
|
||||||
let mut definitions = Vec::new();
|
let mut definitions = Vec::new();
|
||||||
while !input.is_empty() {
|
loop {
|
||||||
definitions.push(input.parse::<OpcodeDefinition>()?);
|
if input.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let lookahead = input.lookahead1();
|
||||||
|
if lookahead.peek(Token![#]) {
|
||||||
|
let enum_ = input.parse::<ItemEnum>()?;
|
||||||
|
additional_enums.insert(enum_.ident.clone(), enum_);
|
||||||
|
} else if lookahead.peek(Ident) {
|
||||||
|
definitions.push(input.parse::<OpcodeDefinition>()?);
|
||||||
|
} else {
|
||||||
|
return Err(lookahead.error());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
token_type,
|
token_type,
|
||||||
additional_enums,
|
additional_enums,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue