Skip to content

Commit

Permalink
parse tuple with param names (full signature)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZelionD committed Oct 25, 2024
1 parent 2c4d3fe commit bab236e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions crates/sol-type-parser/src/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
new_input,
utils::{spanned, tuple_parser},
Error, Input, Result, TypeSpecifier,
Error, Input, ParameterSpecifier, Result, TypeSpecifier,
};
use alloc::vec::Vec;
use winnow::{
Expand Down Expand Up @@ -68,7 +68,8 @@ impl<'a> TupleSpecifier<'a> {

#[inline]
fn parse_types(input: &mut Input<'a>) -> PResult<Vec<TypeSpecifier<'a>>> {
preceded(opt("tuple"), tuple_parser(TypeSpecifier::parser)).parse_next(input)
preceded(opt("tuple"), tuple_parser(ParameterSpecifier::parser.map(|param| param.ty)))
.parse_next(input)
}

/// Returns the tuple specifier as a string.
Expand Down Expand Up @@ -98,6 +99,20 @@ mod test {
TupleSpecifier::parse("(bool,uint256").unwrap_err();
}

#[test]
fn full_signature_tuple() {
assert_eq!(
TupleSpecifier::parse("(bool param1,uint256 param2)").unwrap(),
TupleSpecifier {
span: "(bool param1,uint256 param2)",
types: vec![
TypeSpecifier::parse("bool").unwrap(),
TypeSpecifier::parse("uint256").unwrap(),
]
}
);
}

#[test]
fn nested_tuples() {
assert_eq!(
Expand Down

0 comments on commit bab236e

Please sign in to comment.