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.
This commit is contained in:
parent
5dac6b320b
commit
cde67f6557
@ -752,9 +752,9 @@ not put the `if` clause on a newline. E.g.,
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If every clause in a pattern is *small*, but does not fit on one line, then the
|
If every clause in a pattern is *small*, but the whole pattern does not fit on
|
||||||
pattern may be formatted across multiple lines with as many clauses per line as
|
one line, then the pattern may be formatted across multiple lines with as many
|
||||||
possible. Again break before a `|`:
|
clauses per line as possible. Again break before a `|`:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
foo | bar | baz
|
foo | bar | baz
|
||||||
@ -763,17 +763,18 @@ possible. Again break before a `|`:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
We define a pattern clause to be *small* if it matches the following grammar:
|
We define a pattern clause to be *small* if it fits on a single line and
|
||||||
|
matches "small" in the following grammar:
|
||||||
|
|
||||||
```
|
```
|
||||||
[small, ntp]:
|
small:
|
||||||
- single token
|
- smallntp
|
||||||
- `&[single-line, ntp]`
|
- unary tuple constructor: `(` smallntp `,` `)`
|
||||||
|
- `&` small
|
||||||
|
|
||||||
[small]:
|
smallntp:
|
||||||
- `[small, ntp]`
|
- single token
|
||||||
- unary tuple constructor `([small, ntp])`
|
- `&` smallntp
|
||||||
- `&[small]`
|
|
||||||
```
|
```
|
||||||
|
|
||||||
E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
|
E.g., `&&Some(foo)` matches, `Foo(4, Bar)` does not.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user