Skip to content

Commit d7203a4

Browse files
committed
docs(ref): Specify frontmatter
1 parent 7a08d2f commit d7203a4

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Input format](input-format.md)
99
- [Keywords](keywords.md)
1010
- [Identifiers](identifiers.md)
11+
- [Frontmatter](frontmatter.md)
1112
- [Comments](comments.md)
1213
- [Whitespace](whitespace.md)
1314
- [Tokens](tokens.md)

src/frontmatter.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
r[frontmatter]
2+
# Frontmatter
3+
4+
r[frontmatter.syntax]
5+
```grammar,lexer
6+
@root FRONTMATTER ->
7+
FRONTMATTER_FENCE HORIZONTAL_WHITESPACE* INFOSTRING? HORIZONTAL_WHITESPACE* LF
8+
(FRONTMATTER_LINE LF )*
9+
FRONTMATTER_FENCE[^matched-fence] HORIZONTAL_WHITESPACE* LF
10+
11+
FRONTMATTER_FENCE -> `---` `-`*
12+
13+
INFOSTRING -> (XID_Start | `_`) ( XID_Continue | `-` | `.` )*
14+
15+
FRONTMATTER_LINE -> (~INVALID_FRONTMATTER_LINE_START (~INVALID_FRONTMATTER_LINE_CONTINUE)*)?
16+
17+
INVALID_FRONTMATTER_LINE_START -> (FRONTMATTER_FENCE[^escaped-fence] | LF)
18+
19+
INVALID_FRONTMATTER_LINE_CONTINUE -> LF
20+
```
21+
22+
[^matched-fence]: The closing fence must have the same number of `-` as the opening fence
23+
[^escaped-fence]: A `FRONTMATTER_FENCE` at the beginning of a `FRONTMATTER_LINE` is only invalid if it has the same or more `-` as the `FRONTMATTER_FENCE`
24+
25+
Frontmatter is an optional section for content intended for external tools without requiring these tools to have full knowledge of the Rust grammar.
26+
27+
r[frontmatter.document]
28+
Frontmatter may only be preceded by a [shebang] and whitespace.
29+
30+
r[frontmatter.fence]
31+
The delimiters are referred to as a "fence." The opening and closing fences must be at the start of a line. They must be a matching pair of three or more hyphens (`-`). A fence may be followed by horizontal whitespace.
32+
33+
r[frontmatter.infostring]
34+
Following the opening fence may be an infostring for identifying the intention of the contained content. An infostring may be followed by horizontal whitespace.
35+
36+
r[frontmatter.body]
37+
The body of the frontmatter may contain any content except for a line starting with as many or more hyphens (`-`) than in the fences.
38+
39+
[shebang]: input-format.md#shebang-removal

src/whitespace.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ END_OF_LINE ->
1313
| U+000B // vertical tabulation
1414
| U+000C // form feed
1515
| CR
16-
| U+0085 // Unicode next line
17-
| U+2028 // Unicode LINE SEPARATOR
18-
| U+2029 // Unicode PARAGRAPH SEPARATOR
16+
| U+0085 // next line
17+
| U+2028 // LINE SEPARATOR
18+
| U+2029 // PARAGRAPH SEPARATOR
1919
2020
IGNORABLE_CODE_POINT ->
21-
U+200E // Unicode LEFT-TO-RIGHT MARK
22-
| U+200F // Unicode RIGHT-TO-LEFT MARK
21+
U+200E // LEFT-TO-RIGHT MARK
22+
| U+200F // RIGHT-TO-LEFT MARK
2323
2424
HORIZONTAL_WHITESPACE ->
2525
TAB
26-
| U+0020 // space ' '
26+
| U+0020 // space, `' '`
2727
28-
TAB -> U+0009 // horizontal tab ('\t')
28+
TAB -> U+0009 // horizontal tab, `'\t'`
2929
30-
LF -> U+000A // line feed ('\n')
30+
LF -> U+000A // line feed, `'\n'`
3131
32-
CR -> U+000D // carriage return ('\r')
32+
CR -> U+000D // carriage return, `'\r'`
3333
```
3434

3535
r[lex.whitespace.intro]

0 commit comments

Comments
 (0)