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 parsing pairs with extra parentheses. #25

Merged
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
44 changes: 22 additions & 22 deletions src/simplified_representation/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ impl AstConverting for SrEmitter {
NodeTypeMapKey::EnclosedAddressMapKeyType(key) => key.visit(self)?,
NodeTypeMapKey::AddressMapKeyType(key) => key.visit(self)?,
};
let identifier = self.pop_ir_identifier()?;
self.stack
.push(StackObject::TypeDefinition(identifier.into()));
Ok(TraversalResult::SkipChildren)
}
fn emit_type_map_value(
Expand All @@ -179,39 +182,26 @@ impl AstConverting for SrEmitter {
match node {
NodeTypeMapValue::MapValueTypeOrEnumLikeIdentifier(value) => {
value.visit(self)?;
let value = self.pop_ir_identifier()?;
let key = self.pop_ir_identifier()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key.into(), value.into()],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
let identifier = self.pop_ir_identifier()?;
self.stack
.push(StackObject::TypeDefinition(identifier.into()));
}
NodeTypeMapValue::MapKeyValue(value) => {
value.visit(self)?;
}
NodeTypeMapValue::MapValueParenthesizedType(value) => {
value.visit(self)?;
let value = self.pop_type_definition()?;
let key = self.pop_ir_identifier()?;
let key = self.pop_type_definition()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key.into(), value],
sub_types: vec![key, value],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
}
NodeTypeMapValue::MapValueParenthesizedType(value) => {
value.visit(self)?;
}
NodeTypeMapValue::MapValueAddressType(value) => {
value.visit(self)?;
let value = self.pop_type_definition()?;
let key = self.pop_ir_identifier()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key.into(), value],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
}
};
}
Expand Down Expand Up @@ -270,6 +260,14 @@ impl AstConverting for SrEmitter {
NodeScillaType::MapType(key, value) => {
let _ = key.visit(self)?;
let _ = value.visit(self)?;
let value = self.pop_type_definition()?;
let key = self.pop_type_definition()?;
let map = SrType {
main_type: "Map".to_string(),
sub_types: vec![key, value],
address_type: None,
};
self.stack.push(StackObject::TypeDefinition(map));
}
NodeScillaType::FunctionType(_a, _b) => {
unimplemented!()
Expand Down Expand Up @@ -666,7 +664,9 @@ impl AstConverting for SrEmitter {
match mode {
TreeTraversalMode::Enter => {
match node {
NodeTypeMapValueArguments::EnclosedTypeMapValue(_) => todo!(),
NodeTypeMapValueArguments::EnclosedTypeMapValue(n) => {
n.visit(self)?;
}
NodeTypeMapValueArguments::GenericMapValueArgument(g) => {
g.visit(self)?;
let identifier = self.pop_ir_identifier()?;
Expand Down
10 changes: 10 additions & 0 deletions tests/contracts/Map.scilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
scilla_version 0
contract DifferentMaps
()

field first_map: Map String BNum
= Emp String BNum
field status3days: Map String (Pair (ByStr20) (BNum))
= Emp String (Pair (ByStr20) (BNum))
field reward_pairs : Map ByStr20 (List Uint128)
= Emp (ByStr20) (List Uint128)
34 changes: 34 additions & 0 deletions tests/full_contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ fn test_parse() -> Result<(), Box<dyn Error>> {
Ok(())
}

#[test]
fn test_map_contract_parse() {
let contract_path = PathBuf::from("tests/contracts/Map.scilla");
let contract = Contract::parse(&contract_path).unwrap();
assert_eq!(
contract,
Contract {
name: "DifferentMaps".to_string(),
init_params: FieldList::default(),
fields: FieldList(vec![
Field::new(
"first_map",
Type::Map(Box::new(Type::String), Box::new(Type::BNum))
),
Field::new(
"status3days",
Type::Map(
Box::new(Type::String),
Box::new(Type::Pair(Box::new(Type::ByStr20), Box::new(Type::BNum)))
)
),
Field::new(
"reward_pairs",
Type::Map(
Box::new(Type::ByStr20),
Box::new(Type::List(Box::new(Type::Uint128)))
)
)
]),
transitions: TransitionList::default()
}
);
}

#[test]
fn test_bystr_contract_parse() {
let contract_path = PathBuf::from("tests/contracts/ByStr.scilla");
Expand Down
Loading