Skip to content

Commit 3f34fb4

Browse files
Fix parenthesis handling on ranges and type2 (#92)
* Fix parenthesis handling on ranges and type2 * Add partial tests
1 parent 5a7e680 commit 3f34fb4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/parsing.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,23 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent_visitor: &Parent
185185
Type2::IntValue{ value, .. } => Some(value as i128),
186186
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
187187
};
188-
let max = match &inner_type.operator {
188+
match &inner_type.operator {
189+
// if there was only one value instead of a range, we take that value to be the max
190+
// ex: uint .size (1)
191+
None => ControlOperator::Range((None, min)),
189192
Some(op) => match op.operator {
190193
RangeCtlOp::RangeOp{ is_inclusive, ..} => {
191194
let value = match op.type2 {
192195
Type2::UintValue{ value, .. } => value as i128,
193196
Type2::IntValue{ value, ..} => value as i128,
194197
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
195198
};
196-
Some(if is_inclusive { value } else { value + 1 })
199+
let max = Some(if is_inclusive { value } else { value + 1 });
200+
ControlOperator::Range((min, max))
197201
},
198202
RangeCtlOp::CtlOp{ .. } => panic!(""),
199203
},
200-
None => min,
201-
};
202-
ControlOperator::Range((min, max))
204+
}
203205
},
204206
_ => unimplemented!("unsupported type in range control operator: {:?}", operator),
205207
};
@@ -698,6 +700,9 @@ fn rust_type_from_type2(types: &mut IntermediateTypes, parent_visitor: &ParentVi
698700
Type2::TaggedData{ tag, t, .. } => {
699701
RustType::Tagged(tag.expect("tagged data without tag not supported"), Box::new(rust_type(types, parent_visitor, t)))
700702
},
703+
Type2::ParenthesizedType { pt, .. } => {
704+
rust_type(types, parent_visitor, pt)
705+
},
701706
_ => {
702707
panic!("Ignoring Type2: {:?}", type2);
703708
},

tests/core/input.cddl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ signed_ints = [
6161
; The fix would be ideal as even though the true min in CBOR would be -u64::MAX
6262
; we can't test that since isize::BITS is never > 64 in any normal system and likely never will be
6363
i64_min: -9223372036854775808
64-
]
64+
]
65+
66+
paren_size = uint .size (1)
67+
paren_cbor = bytes .cbor (text)

0 commit comments

Comments
 (0)