Skip to content

Commit

Permalink
Fix parenthesis handling on ranges and type2
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Sep 2, 2022
1 parent a354a5e commit 1aed35d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,23 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent: &Type2AndParent
Type2::IntValue{ value, .. } => Some(value as i128),
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
};
let max = match &inner_type.operator {
match &inner_type.operator {
// if there was only one value instead of a range, we take that value to be the max
// ex: uint .size (1)
None => ControlOperator::Range((None, min)),
Some(op) => match op.operator {
RangeCtlOp::RangeOp{ is_inclusive, ..} => {
let value = match op.type2 {
Type2::UintValue{ value, .. } => value as i128,
Type2::IntValue{ value, ..} => value as i128,
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
};
Some(if is_inclusive { value } else { value + 1 })
let max = Some(if is_inclusive { value } else { value + 1 });
ControlOperator::Range((min, max))
},
RangeCtlOp::CtlOp{ .. } => panic!(""),
},
None => min,
};
ControlOperator::Range((min, max))
}
},
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
};
Expand Down Expand Up @@ -672,6 +674,9 @@ fn rust_type_from_type2(types: &mut IntermediateTypes, type2: &Type2AndParent) -
Type2::TaggedData{ tag, t, .. } => {
RustType::Tagged(tag.expect("tagged data without tag not supported"), Box::new(rust_type(types, t)))
},
Type2::ParenthesizedType { pt, .. } => {
rust_type(types, pt)
},
_ => {
panic!("Ignoring Type2: {:?}", type2.type2);
},
Expand Down

0 comments on commit 1aed35d

Please sign in to comment.