Skip to content

Commit 2b3a5fa

Browse files
committed
docs(ref): Specify frontmatter
1 parent 00405f8 commit 2b3a5fa

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
r[frontmatter]
2+
# Frontmatter
3+
4+
r[frontmatter.syntax]
5+
```grammar,lexer
6+
FRONTMATTER ->
7+
FRONTMATTER_FENCE INFOSTRING? LF
8+
(FRONTMATTER_LINE LF )*
9+
FRONTMATTER_FENCE[^matched-fence] 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."
32+
The opening and closing fences must be at the start of a line.
33+
They must be a matching pair of three or more hyphens (`-`).
34+
35+
r[frontmatter.infostring]
36+
Following the opening fence may be an infostring for identifying the intention of the contained content.
37+
An infostring may be preceded by non-newline whitespace.
38+
39+
r[frontmatter.body]
40+
The body of the frontmatter may contain any content except for a line starting with as many or more hyphens (`-`) than in the fences.
41+
42+
[shebang]: input-format.md#shebang-removal

0 commit comments

Comments
 (0)