Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parenthesis handling on ranges and type2 #92

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,23 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent_visitor: &Parent
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 @@ -698,6 +700,9 @@ fn rust_type_from_type2(types: &mut IntermediateTypes, parent_visitor: &ParentVi
Type2::TaggedData{ tag, t, .. } => {
RustType::Tagged(tag.expect("tagged data without tag not supported"), Box::new(rust_type(types, parent_visitor, t)))
},
Type2::ParenthesizedType { pt, .. } => {
rust_type(types, parent_visitor, pt)
},
_ => {
panic!("Ignoring Type2: {:?}", type2);
},
Expand Down
5 changes: 4 additions & 1 deletion tests/core/input.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ signed_ints = [
; The fix would be ideal as even though the true min in CBOR would be -u64::MAX
; we can't test that since isize::BITS is never > 64 in any normal system and likely never will be
i64_min: -9223372036854775808
]
]

paren_size = uint .size (1)
paren_cbor = bytes .cbor (text)