Skip to content

Commit

Permalink
Add tuple support
Browse files Browse the repository at this point in the history
  • Loading branch information
op8867555 committed Oct 17, 2023
1 parent 87654d4 commit d8bb0c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion zngur-generator/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ impl IntoCpp for RustType {
if v.is_empty() {
return CppType::from("rust::Unit");
}
todo!()
CppType {
path: CppPath::from("rust::Tuple"),
generic_args: v.into_iter().map(|x| x.into_cpp()).collect(),
}
}
RustType::Dyn(tr, marker_bounds) => {
let tr_as_cpp_type = tr.into_cpp();
Expand Down
8 changes: 8 additions & 0 deletions zngur-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ fn rust_type<'a>(
let unit = just(Token::ParenOpen)
.then(just(Token::ParenClose))
.map(|_| ParsedRustType::Tuple(vec![]));
let tuple = parser
.clone()
.separated_by(just(Token::Comma))
.allow_trailing()
.collect::<Vec<_>>()
.delimited_by(just(Token::ParenOpen), just(Token::ParenClose))
.map(|xs| ParsedRustType::Tuple(xs));
let slice = parser
.clone()
.map(|x| ParsedRustType::Slice(Box::new(x)))
Expand All @@ -748,6 +755,7 @@ fn rust_type<'a>(
scalar
.or(boxed)
.or(unit)
.or(tuple)
.or(slice)
.or(adt)
.or(reference)
Expand Down
12 changes: 12 additions & 0 deletions zngur-parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ type () {
);
}

#[test]
fn parse_tuple() {
check_success(
r#"
type (i8, u8) {
#layout(size = 0, align = 1);
}
"#,
);
}


#[test]
fn typo_in_wellknown_trait() {
check_fail(
Expand Down

0 comments on commit d8bb0c9

Please sign in to comment.