-
Notifications
You must be signed in to change notification settings - Fork 579
Add frontmatter #2197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add frontmatter #2197
Changes from all commits
351363d
6beec24
027a3b9
d31d4b8
8496831
892761c
1ad2054
f84a374
a974da7
4c05885
e850b3d
4d9d363
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| r[frontmatter] | ||
| # Frontmatter | ||
|
|
||
| r[frontmatter.intro] | ||
| Frontmatter is an optional section of metadata whose syntax allows external tools to read it without parsing Rust. | ||
|
|
||
| > [!EXAMPLE] | ||
| > <!-- ignore: test runner doesn't support frontmatter --> | ||
| > ```rust,ignore | ||
| > #!/bin/env cargo | ||
| > --- cargo | ||
| > package.edition = 2024 | ||
| > --- | ||
| > | ||
| > fn main() {} | ||
| > ``` | ||
|
|
||
| r[frontmatter.syntax] | ||
| ```grammar,lexer | ||
| @root FRONTMATTER -> | ||
| WHITESPACE_ONLY_LINE* | ||
| !FRONTMATTER_INVALID | ||
| FRONTMATTER_MAIN | ||
|
|
||
| WHITESPACE_ONLY_LINE -> (!LF WHITESPACE)* LF | ||
|
|
||
| FRONTMATTER_INVALID -> (!LF WHITESPACE)+ `---` ^ ⊥ | ||
|
|
||
| FRONTMATTER_MAIN -> | ||
| `-`{n:3..=255} ^ FRONTMATTER_REST | ||
|
|
||
| FRONTMATTER_REST -> | ||
| FRONTMATTER_FENCE_START | ||
| FRONTMATTER_LINE* | ||
| FRONTMATTER_FENCE_END | ||
|
|
||
| FRONTMATTER_FENCE_START -> | ||
| MAYBE_INFOSTRING_OR_WS LF | ||
|
|
||
| FRONTMATTER_FENCE_END -> | ||
| `-`{n} HORIZONTAL_WHITESPACE* ( LF | EOF ) | ||
|
|
||
| FRONTMATTER_LINE -> !`-`{n} ~[LF CR]* LF | ||
|
|
||
| MAYBE_INFOSTRING_OR_WS -> | ||
| HORIZONTAL_WHITESPACE* INFOSTRING? HORIZONTAL_WHITESPACE* | ||
|
|
||
| INFOSTRING -> (XID_Start | `_`) ( XID_Continue | `-` | `.` )* | ||
| ``` | ||
|
|
||
| r[frontmatter.position] | ||
| Frontmatter may appear at the start of the file (after the optional [byte order mark]) or after a [shebang]. In either case, it may be preceded by [whitespace]. | ||
|
|
||
| r[frontmatter.fence] | ||
| Frontmatter must start and end with a *fence*. Each fence must start at the beginning of a line. The opening fence must consist of at least 3 and no more than 255 hyphens (`-`). The closing fence must have exactly the same number of hyphens as the opening fence. The hyphens of either fence may be followed by [horizontal whitespace]. | ||
|
|
||
| r[frontmatter.infostring] | ||
| The opening fence, after optional [horizontal whitespace], may be followed by an infostring that identifies the format or purpose of the body. An infostring may be followed by horizontal whitespace. | ||
|
|
||
| r[frontmatter.body] | ||
| No line in the body may start with a sequence of hyphens (`-`) equal to or longer than the opening fence. The body may not contain carriage returns. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got confused about the "body must not contain carriage returns" at first, since I use windows - then I remembered |
||
|
|
||
| [byte order mark]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8 | ||
| [horizontal whitespace]: grammar-HORIZONTAL_WHITESPACE | ||
| [shebang]: input-format.md#shebang-removal | ||
| [whitespace]: whitespace.md | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the whitespace considered part of the frontmatter for the lexer (here), but in
frontmatter.positionit describes whitespace as preceding (and thus not part of) the frontmatter?I'm also a bit confused about the combination of this and the
FRONTMATTER_INVALIDgrammar - what is the benefit of including the discussion of invalid frontmatter in the grammar specification itself, rather than just in the prose?