Skip to content

Commit

Permalink
Keep seq after formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Oct 15, 2020
1 parent 6eec81f commit 9751073
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
12 changes: 7 additions & 5 deletions book/src/syntax-and-semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,22 @@ Sequence expressions work just like `do` expressions, only they do not have a bi

```f#,rust
let io @ { ? } = import! std.io
io.print "Hello"
io.print " "
seq io.print "Hello"
seq io.print " "
io.println "world!"
```

For backwards compatibility it is also possible to write (`seq`) before each expression.
The `seq` keyword can also be omitted.

```f#,rust
let io @ { ? } = import! std.io
seq io.print "Hello"
seq io.print " "
io.print "Hello"
io.print " "
io.println "world!"
```

(In the future one of these ways are likely to be deprecated with only one way remaining, the formatter will be able to update the code in any case).

### Indentation

If you have been following along this far, you may be think that the syntax so far is pretty limiting. In particular, you wouldn't be wrong in thinking that the `let` and `type` syntax are clunky due to their need to be closed by the `in` keyword. Luckily, Gluon offers a more convenient way of writing bindings by relying on indentation.
Expand Down
8 changes: 4 additions & 4 deletions examples/marshalling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ fn marshal_wrapper(thread: &Thread) -> Result<()> {
let actual = { name = "Bob", age = 11, data = True }
let expected = roundtrip actual
assert (actual.name == expected.name)
assert (actual.age == expected.age)
let _ = assert (actual.name == expected.name)
let _ = assert (actual.age == expected.age)
assert (actual.data == expected.data)
"#;

Expand Down Expand Up @@ -369,8 +369,8 @@ fn marshal_userdata(thread: &Thread) -> Result<()> {
let { assert } = import! std.test
let { WindowHandle, create_hwnd, id, metadata } = import! hwnd
let hwnd : WindowHandle = create_hwnd 0 "Window1"
assert (id hwnd == 0)
assert (metadata hwnd == "Window1")
let _ = assert (id hwnd == 0)
let _ = assert (metadata hwnd == "Window1")
hwnd
"#;

Expand Down
49 changes: 32 additions & 17 deletions format/src/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,29 +478,44 @@ where
ref bound,
ref body,
..
}) => match id {
Some(pattern) => {
let from = chain![
arena,
"do",
self.space_before(pattern.span.start()),
self.pretty_pattern(pattern),
self.space_after(pattern.span.end()),
"="
];
}) => {
if self.source.src_slice(expr.span).starts_with("seq") {
let from = arena.text("seq");
chain![
arena,
self.hang(from, (self.space_before(bound.span.start()), true), bound),
self.pretty_expr_(bound.span.end(), body)
]
}
} else {
match id {
Some(pattern) => {
let from = chain![
arena,
"do",
self.space_before(pattern.span.start()),
self.pretty_pattern(pattern),
self.space_after(pattern.span.end()),
"="
];
chain![
arena,
self.hang(
from,
(self.space_before(bound.span.start()), true),
bound
),
self.pretty_expr_(bound.span.end(), body)
]
}

None => chain![
arena,
self.pretty_expr_(bound.span.start(), bound),
self.pretty_expr_(bound.span.end(), body)
],
},
None => chain![
arena,
self.pretty_expr_(bound.span.start(), bound),
self.pretty_expr_(bound.span.end(), body)
],
}
}
}
Expr::MacroExpansion { ref original, .. } => {
return self.pretty_expr_(previous_end, original);
}
Expand Down
7 changes: 4 additions & 3 deletions format/tests/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ let assert_success : [Show e]
fn sequence() {
let expr = r#"
// a
io.print "Hello"
seq io.print "Hello"
// b
io.print " "
// c
Expand All @@ -828,11 +828,12 @@ io.println "World"
expect![[r#"
// a
io.print "Hello"
seq io.print "Hello"
// b
io.print " "
// c
io.println "World"
// d
"#]].assert_eq(&format_expr(expr).unwrap());
"#]]
.assert_eq(&format_expr(expr).unwrap());
}

0 comments on commit 9751073

Please sign in to comment.