Skip to content

Commit 70cf56e

Browse files
committed
respect alternative flag
1 parent dbaad4f commit 70cf56e

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

crates/formality-core/src/binder.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,24 @@ where
261261
T: std::fmt::Debug,
262262
{
263263
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
264-
if !self.kinds.is_empty() {
265-
write!(f, "{}", L::BINDING_OPEN)?;
266-
for (kind, i) in self.kinds.iter().zip(0..) {
267-
if i > 0 {
268-
write!(f, ", ")?;
264+
if f.alternate() {
265+
f.debug_struct("Binder")
266+
.field("kinds", &self.kinds)
267+
.field("term", &self.term)
268+
.finish()
269+
} else {
270+
if !self.kinds.is_empty() {
271+
write!(f, "{}", L::BINDING_OPEN)?;
272+
for (kind, i) in self.kinds.iter().zip(0..) {
273+
if i > 0 {
274+
write!(f, ", ")?;
275+
}
276+
write!(f, "{:?}", kind)?;
269277
}
270-
write!(f, "{:?}", kind)?;
278+
write!(f, "{} ", L::BINDING_CLOSE)?;
271279
}
272-
write!(f, "{} ", L::BINDING_CLOSE)?;
280+
write!(f, "{:?}", &self.term)?;
281+
Ok(())
273282
}
274-
write!(f, "{:?}", &self.term)?;
275-
Ok(())
276283
}
277284
}

examples/formality-eg/grammar/test.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ fn test_struct_decl() {
1010
expect_test::expect![[r#"
1111
StructDecl {
1212
id: Point,
13-
bound: { x : integer, y : integer },
13+
bound: Binder {
14+
kinds: [],
15+
term: StructBoundData {
16+
fields: [
17+
FieldDecl {
18+
name: x,
19+
ty: Integer,
20+
},
21+
FieldDecl {
22+
name: y,
23+
ty: Integer,
24+
},
25+
],
26+
},
27+
},
1428
}
1529
"#]]
1630
.assert_debug_eq(&r);

0 commit comments

Comments
 (0)