You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: reference-dev-guide/src/grammar.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Rust grammar
2
2
3
-
The Reference grammar is written in markdown code blocks using a modified BNF-like syntax (with a blend of regex and other arbitrary things). The [`mdbook-spec`] extension parses these rules and converts them to a renderable format, including railroad diagrams.
3
+
The Reference grammar is written in markdown code blocks using a modified BNF-like syntax (with a blend of regex and other arbitrary things). The [`mdbook-spec`] extension parses these rules and converts them into a renderable format, including railroad diagrams.
4
4
5
-
The code block should have a lang string with the word "grammar", a comma, and the category of the grammar, like this:
5
+
The code block should have a lang string with the word `grammar`, a comma, and the category of the grammar, like this:
6
6
7
7
~~~
8
8
```grammar,items
@@ -14,7 +14,7 @@ The category is used to group similar productions on the grammar summary page in
14
14
15
15
## Grammar syntax
16
16
17
-
The syntax for the grammar itself is pretty close to what is described in the [Notation chapter], though there are some rendering differences.
17
+
The syntax for the grammar itself is similar to what is described in the [Notation chapter], though there are some rendering differences.
18
18
19
19
A "root" production, marked with `@root`, is one that is not used in any other production.
The general format is a series of productions separated by blank lines. The expressions are:
97
+
The general format is a series of productions separated by blank lines. The expressions are as follows:
98
98
99
99
| Expression | Example | Description |
100
100
|------------|---------|-------------|
101
-
| Unicode | U+0060 | A single unicode character. |
101
+
| Unicode | U+0060 | A single Unicode character. |
102
102
| NonTerminal | FunctionParameters | A reference to another production by name. |
103
-
| Break ||This is used internally by the renderer to detect line breaks and indentation. |
103
+
| Break ||Used internally by the renderer to detect line breaks and indentation. |
104
104
| Comment | // Single line comment. | A comment extending to the end of the line. |
105
-
| Terminal |\`example\`|This is a sequence of exact characters, surrounded by backticks |
106
-
| Charset |[\`A\`-\`Z\`\`0\`-\`9\`\`_\`]| A choice from a set of characters, spaceseparated. There are three different forms. |
107
-
| CharacterRange | [\`A\`-\`Z\`] | A range of characters, each character should be in backticks.
108
-
| CharacterTerminal |[\`x\`]| A single character, surrounded by backticks. |
109
-
| CharacterName |[ LF ]| A nonterminal, referring to another production. |
110
-
| Prose |\<any ASCII character except CR\>|This is an English description of what should be matched, surrounded in angle brackets. |
111
-
| Group | (\`,\` Parameter)+ | This groups an expression for the purpose of precedence, such as applying a repetition operator to a sequence of other expressions.
112
-
| NegativeExpression |~[\`\` LF]| Matches anything except the given Charset, Terminal, or Nonterminal. |
113
-
| Sequence |\`fn\` Name Parameters | A sequence of expressions, where they must match in order. |
105
+
| Terminal |\`example\`|A sequence of exact characters, surrounded by backticks.|
106
+
| Charset |\[\`A\`-\`Z\`\`0\`-\`9\`\`_\`\]| A choice from a set of characters, space-separated. There are three different forms. |
107
+
| CharacterRange | \[\`A\`-\`Z\`\] | A range of characters; each character should be in backticks.
108
+
| CharacterTerminal |\[\`x\`\]| A single character, surrounded by backticks. |
109
+
| CharacterName |\[ LF \]| A nonterminal, referring to another production. |
110
+
| Prose |\<any ASCII character except CR\>|An English description of what should be matched, surrounded in angle brackets. |
111
+
| Group | (\`,\` Parameter)+ | Groups an expression for the purpose of precedence, such as applying a repetition operator to a sequence of other expressions.
112
+
| NegativeExpression |~\[\`\` LF\]| Matches anything except the given Charset, Terminal, or Nonterminal. |
113
+
| Sequence |\`fn\` Name Parameters | A sequence of expressions that must match in order. |
114
114
| Alternation | Expr1 \| Expr2 | Matches only one of the given expressions, separated by the vertical pipe character. |
115
-
| Suffix |\_except \[LazyBooleanExpression\]\_|This adds a suffix to the previous expression to provide an additional English description to it, rendered in subscript. This can have limited markdown, but try to avoid anything except basics like links. |
116
-
| Footnote |\[^extern-safe\]|This adds a footnote, which can supply some extra information that may be helpful to the user. The footnote itself should be defined outside of the code block like a normal markdown footnote. |
115
+
| Suffix |\_except \[LazyBooleanExpression\]\_|Adds a suffix to the previous expression to provide an additional English description, rendered in subscript. This can contain limited markdown, but try to avoid anything except basics like links. |
116
+
| Footnote |\[^extern-safe\]|Adds a footnote, which can supply extra information that may be helpful to the user. The footnote itself should be defined outside of the code block like a normal markdown footnote. |
117
117
| Optional | Expr? | The preceding expression is optional. |
118
118
| Repeat | Expr*| The preceding expression is repeated 0 or more times. |
119
119
| Repeat (non-greedy) | Expr*? | The preceding expression is repeated 0 or more times without being greedy. |
120
120
| RepeatPlus | Expr+ | The preceding expression is repeated 1 or more times. |
121
121
| RepeatPlus (non-greedy) | Expr+? | The preceding expression is repeated 1 or more times without being greedy. |
122
-
| RepeatRange | Expr{2..4} | The preceding expression is repeated between the range of times specified. Either bounds can be excluded, which works just like Rust ranges. |
122
+
| RepeatRange | Expr{2..4} | The preceding expression is repeated between the range of times specified. Either bound can be excluded, which works just like Rust ranges. |
123
123
124
124
## Automatic linking
125
125
126
-
The [`mdbook-spec`] plugin automatically adds markdown link definitions for all the production names on every page. If you want to link directly to a production name, all you need to do is surround it in square brackets, like `[ArrayExpression]`.
126
+
The [`mdbook-spec`] plugin automatically adds markdown link definitions for all production names on every page. To link directly to a production name, simply surround it in square brackets, like `[ArrayExpression]`.
127
127
128
-
In some cases there might be name collisions with the automatic linking of rule names. In that case, disambiguate with the `grammar-` prefix, such as `[Type][grammar-Type]`. You can also do that if you just feel like being more explicit.
128
+
In some cases, there might be name collisions with the automatic linking of rule names. In that case, disambiguate with the `grammar-` prefix, such as `[Type][grammar-Type]`. You can also do this if you prefer to be more explicit.
0 commit comments