From 94b07e891fb9363c8dfbc0344a500b4c7b12d4a5 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Fri, 2 Sep 2022 22:50:23 +0900 Subject: [PATCH 1/2] Fix parenthesis handling on ranges and type2 --- src/parsing.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/parsing.rs b/src/parsing.rs index fb917ae..ab916de 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -185,7 +185,10 @@ 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 { @@ -193,13 +196,12 @@ fn parse_control_operator(types: &mut IntermediateTypes, parent_visitor: &Parent 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), }; @@ -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, pt) + }, _ => { panic!("Ignoring Type2: {:?}", type2); }, From 127e8f54269f0111506420ff10e68da965d51135 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Wed, 2 Nov 2022 23:52:49 +0900 Subject: [PATCH 2/2] Add partial tests --- src/parsing.rs | 2 +- tests/core/input.cddl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/parsing.rs b/src/parsing.rs index ab916de..7962d7f 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -701,7 +701,7 @@ fn rust_type_from_type2(types: &mut IntermediateTypes, parent_visitor: &ParentVi RustType::Tagged(tag.expect("tagged data without tag not supported"), Box::new(rust_type(types, parent_visitor, t))) }, Type2::ParenthesizedType { pt, .. } => { - rust_type(types, pt) + rust_type(types, parent_visitor, pt) }, _ => { panic!("Ignoring Type2: {:?}", type2); diff --git a/tests/core/input.cddl b/tests/core/input.cddl index f2f34dd..bf7cf78 100644 --- a/tests/core/input.cddl +++ b/tests/core/input.cddl @@ -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 -] \ No newline at end of file +] + +paren_size = uint .size (1) +paren_cbor = bytes .cbor (text)