Skip to content

Instantly share code, notes, and snippets.

@cholcombe973
Created March 17, 2016 17:54
Show Gist options
  • Save cholcombe973/118bff1617414fd02da2 to your computer and use it in GitHub Desktop.
Save cholcombe973/118bff1617414fd02da2 to your computer and use it in GitHub Desktop.
fn parse_rule<'a>(input: &'a [u8], num_of_rules: u32) ->nom::IResult<&[u8], [Option<Rule>]>{
let mut rules = [Option::<Rule>; num_of_rules];
for i in 0..num_of_rules{
let yes = le_u32(input);
if yes == 0{
rules[i] = None;
continue;
}
else{
let rule = Rule::parse(input);
match rule{
nom::IResult::Done(unparsed_data, decoded_rule) =>{
rules[i] = Some(decode_rule)
},
nom::IResult::Incomplete(needed) => {
return nom::IResult::Incomplete(needed);
}
nom::IResult::Error(e) => {
return nom::IResult::Error(e);
},
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment