From 6368fe4fa859aaa366d16f92dfeb8f90bdf43dbb Mon Sep 17 00:00:00 2001 From: Saeed Dadkhah Date: Wed, 27 Nov 2024 16:12:05 +0330 Subject: [PATCH] Support parsing ByStr (variable length str) type. (#19) --- src/simplified_representation/emitter.rs | 11 +++++++++-- src/type.rs | 1 - tests/contracts/ByStr.scilla | 1 + tests/full_contract_tests.rs | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/simplified_representation/emitter.rs b/src/simplified_representation/emitter.rs index bec032f..7982f3f 100644 --- a/src/simplified_representation/emitter.rs +++ b/src/simplified_representation/emitter.rs @@ -131,9 +131,16 @@ impl AstConverting for SrEmitter { fn emit_meta_identifier( &mut self, _mode: TreeTraversalMode, - _node: &NodeMetaIdentifier, + node: &NodeMetaIdentifier, ) -> Result { - Ok(TraversalResult::Continue) + match node { + NodeMetaIdentifier::ByteString => { + let symbol = SrIdentifier::new("ByStr".to_string(), SrIdentifierKind::Unknown); + self.stack.push(StackObject::IrIdentifier(symbol)); + Ok(TraversalResult::SkipChildren) + } + _ => Ok(TraversalResult::Continue), + } } fn emit_variable_identifier( &mut self, diff --git a/src/type.rs b/src/type.rs index f4a556a..79d2f6d 100644 --- a/src/type.rs +++ b/src/type.rs @@ -85,7 +85,6 @@ impl From for Type { "Uint256" => Type::Uint256, "String" => Type::String, "ByStr" => Type::ByStr, - "ByStrX" => todo!(), "BNum" => Type::BNum, "Bool" => Type::Bool, // TODO: Remove unwrap diff --git a/tests/contracts/ByStr.scilla b/tests/contracts/ByStr.scilla index c07c2e2..f98c0e0 100644 --- a/tests/contracts/ByStr.scilla +++ b/tests/contracts/ByStr.scilla @@ -2,6 +2,7 @@ scilla_version 0 contract AllByStrVariants ( + bystr : ByStr, bystr32 : ByStr32, raw_address: ByStr20, library_address : ByStr20 with library end, diff --git a/tests/full_contract_tests.rs b/tests/full_contract_tests.rs index 3ed4511..41ecffe 100644 --- a/tests/full_contract_tests.rs +++ b/tests/full_contract_tests.rs @@ -26,6 +26,7 @@ fn test_bystr_contract_parse() { Contract { name: "AllByStrVariants".to_string(), init_params: FieldList(vec![ + Field::new("bystr", Type::ByStr), Field::new("bystr32", Type::ByStrX(32)), Field::new("raw_address", Type::ByStr20), Field::new(