Skip to content

Commit

Permalink
Rollup merge of #113384 - joshtriplett:style-guide-grammar, r=compile…
Browse files Browse the repository at this point in the history
…r-errors

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.

Also rename "smallntp" to "small_no_tuple" to make it self-describing.
  • Loading branch information
fee1-dead committed Jul 6, 2023
2 parents 70e8f9d + 79df44b commit c668eb0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/doc/style-guide/src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,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
pattern may be formatted across multiple lines with as many clauses per line as
possible. Again break before a `|`:
If every clause in a pattern is *small*, but the whole pattern does not fit on
one line, then the pattern may be formatted across multiple lines with as many
clauses per line as possible. Again break before a `|`:

```rust
foo | bar | baz
Expand All @@ -764,17 +764,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]:
- single token
- `&[single-line, ntp]`
small:
- small_no_tuple
- unary tuple constructor: `(` small_no_tuple `,` `)`
- `&` small
[small]:
- `[small, ntp]`
- unary tuple constructor `([small, ntp])`
- `&[small]`
small_no_tuple:
- single token
- `&` small_no_tuple
```

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

0 comments on commit c668eb0

Please sign in to comment.