Skip to content

Commit f844924

Browse files
committed
docs(ref): Specify frontmatter
1 parent ce56cb3 commit f844924

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
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/input-format.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ This prevents an [inner attribute] at the start of a source file being removed.
5959
> [!NOTE]
6060
> The standard library [`include!`] macro applies byte order mark removal, CRLF normalization, and shebang removal to the file it reads. The [`include_str!`] and [`include_bytes!`] macros do not.
6161
62+
r[input.frontmatter]
63+
## Frontmatter removal
64+
65+
After some whitespace, [frontmatter] may next appear in the input.
66+
6267
r[input.tokenization]
6368
## Tokenization
6469

@@ -69,4 +74,5 @@ The resulting sequence of characters is then converted into tokens as described
6974
[comments]: comments.md
7075
[Crates and source files]: crates-and-source-files.md
7176
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix)
77+
[frontmatter]: frontmatter.md
7278
[whitespace]: whitespace.md

0 commit comments

Comments
 (0)