Skip to content

Commit cde67f6

Browse files
committed
style-guide: Clarify grammar for small patterns (not a semantic change)
The grammar as written feels ambiguous and confusing, in large part because it uses square brackets and commas in the names of non-terminals. Rewrite it to avoid symbols in the names of non-terminals, and to instead wrap terminals in backquotes.
1 parent 5dac6b3 commit cde67f6

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/doc/style-guide/src/expressions.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,9 @@ not put the `if` clause on a newline. E.g.,
752752
}
753753
```
754754

755-
If every clause in a pattern is *small*, but does not fit on one line, then the
756-
pattern may be formatted across multiple lines with as many clauses per line as
757-
possible. Again break before a `|`:
755+
If every clause in a pattern is *small*, but the whole pattern does not fit on
756+
one line, then the pattern may be formatted across multiple lines with as many
757+
clauses per line as possible. Again break before a `|`:
758758

759759
```rust
760760
foo | bar | baz
@@ -763,17 +763,18 @@ possible. Again break before a `|`:
763763
}
764764
```
765765

766-
We define a pattern clause to be *small* if it matches the following grammar:
766+
We define a pattern clause to be *small* if it fits on a single line and
767+
matches "small" in the following grammar:
767768

768769
```
769-
[small, ntp]:
770-
- single token
771-
- `&[single-line, ntp]`
770+
small:
771+
- smallntp
772+
- unary tuple constructor: `(` smallntp `,` `)`
773+
- `&` small
772774
773-
[small]:
774-
- `[small, ntp]`
775-
- unary tuple constructor `([small, ntp])`
776-
- `&[small]`
775+
smallntp:
776+
- single token
777+
- `&` smallntp
777778
```
778779

779780
E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.

0 commit comments

Comments
 (0)