Machine-readable frontmatter grammar
The machine-readable Pest grammar for frontmatter is presented here for convenience.
See Parsing Expression Grammars for an explanation of the notation.
This version of the grammar uses Pest's PUSH
, PEEK
, and POP
for the the matched fences.
ANY
, EOI
, PATTERN_WHITE_SPACE
, XID_START
, and XID_CONTINUE
are built in to Pest and so not defined below.
FRONTMATTER = {
WHITESPACE_ONLY_LINE * ~
START_LINE ~
CONTENT_LINE * ~
END_LINE
}
WHITESPACE_ONLY_LINE = {
( !"\n" ~ PATTERN_WHITE_SPACE ) * ~
"\n"
}
START_LINE = {
PUSH(FENCE) ~
HORIZONTAL_WHITESPACE * ~
( INFOSTRING ~ HORIZONTAL_WHITESPACE * ) ? ~
"\n"
}
CONTENT_LINE = {
!PEEK ~
( !"\n" ~ ANY ) * ~
"\n"
}
END_LINE = {
POP ~
HORIZONTAL_WHITESPACE * ~
( "\n" | EOI )
}
FENCE = { "---" ~ "-" * }
INFOSTRING = {
( XID_START | "_" ) ~
( XID_CONTINUE | "-" | "." ) *
}
HORIZONTAL_WHITESPACE = { " " | "\t" }
RESERVED = {
PATTERN_WHITE_SPACE * ~
FENCE
}