CEP-0060: Newline-Permissive Trailing Continuations¶
Draft
Draft proposal for allowing selected trailing continuation keywords across newlines. V1 keeps Go-like statement separation.
Summary¶
Catalyst should consider allowing selected trailing continuations such as else and catch after a newline, similar to Kotlin-style control-flow grammar.
V1 uses parser-contextual statement separation: in statement-list contexts, a newline separates statements when the parser can accept the end of the current statement. As a result, trailing continuation keywords must remain on the same logical statement unless the preceding syntax is incomplete.
Motivation¶
Same-line trailing continuations are simple to parse and easy to explain, but some programmers prefer vertically separated control-flow keywords:
const x = if ready {
1
}
else {
2
}
That style can read naturally for large blocks, but it requires grammar-specific exceptions to the V1 newline rule.
Proposed Direction¶
A future design should decide whether selected grammar productions may consume newlines before trailing continuation keywords.
Candidate continuations:
elseafter anifthen-block;catchafter a fallible expression;- future
else ifor pattern-matching continuations if those forms are accepted.
The design should specify:
- whether this applies only to control-flow constructs or also postfix expression forms;
- whether comments between the closing token and continuation keyword are allowed;
- how diagnostics distinguish a missing continuation from a genuinely separate statement;
- how formatting preserves or normalizes the style;
- whether trailing operators such as
+remain the only way to continue arbitrary expressions across newlines.
Example¶
Possible future accepted shape:
const x = if ready {
1
}
else {
2
}
Possible future accepted catch shape:
var bytes = read(path)
catch {
empty_bytes
}
The exact set of newline-permissive continuations is deferred.
V1 Compatibility¶
V1 rejects trailing continuation keywords after a statement-separating newline. Programmers should write same-line forms:
const x = if ready {
1
} else {
2
}
var bytes = read(path) catch {
empty_bytes
}
Accepting this proposal later would be mostly source-additive. It may affect diagnostics and parser recovery for code that currently errors after a separated else or catch.