2018-05-03 18:50:30 +00:00
|
|
|
// Partly taken from Tera
|
2018-10-09 13:24:56 +00:00
|
|
|
WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
|
2018-05-03 18:50:30 +00:00
|
|
|
|
|
|
|
/// LITERALS
|
|
|
|
int = @{ "-" ? ~ ("0" | '1'..'9' ~ '0'..'9' * ) }
|
|
|
|
float = @{
|
|
|
|
"-" ? ~
|
|
|
|
(
|
|
|
|
"0" ~ "." ~ '0'..'9' + |
|
|
|
|
'1'..'9' ~ '0'..'9' * ~ "." ~ '0'..'9' +
|
|
|
|
)
|
|
|
|
}
|
|
|
|
// matches anything between 2 double quotes
|
2018-10-09 13:24:56 +00:00
|
|
|
double_quoted_string = @{ "\"" ~ (!("\"") ~ ANY)* ~ "\""}
|
2018-05-03 18:50:30 +00:00
|
|
|
// matches anything between 2 single quotes
|
2018-10-09 13:24:56 +00:00
|
|
|
single_quoted_string = @{ "\'" ~ (!("\'") ~ ANY)* ~ "\'"}
|
2018-05-03 18:50:30 +00:00
|
|
|
// matches anything between 2 backquotes\backticks
|
2018-10-09 13:24:56 +00:00
|
|
|
backquoted_quoted_string = @{ "`" ~ (!("`") ~ ANY)* ~ "`"}
|
2018-05-03 18:50:30 +00:00
|
|
|
|
|
|
|
string = @{
|
|
|
|
double_quoted_string |
|
|
|
|
single_quoted_string |
|
|
|
|
backquoted_quoted_string
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean = { "true" | "false" }
|
|
|
|
|
|
|
|
literal = { boolean | string | float | int }
|
|
|
|
array = { "[" ~ (literal ~ ",")* ~ literal? ~ "]"}
|
|
|
|
|
|
|
|
/// Idents
|
|
|
|
|
|
|
|
all_chars = _{'a'..'z' | 'A'..'Z' | "_" | '0'..'9'}
|
|
|
|
ident = @{
|
|
|
|
('a'..'z' | 'A'..'Z' | "_") ~
|
|
|
|
all_chars*
|
|
|
|
}
|
|
|
|
|
2018-10-18 20:50:06 +00:00
|
|
|
/// Now specific to Zola
|
2018-05-03 18:50:30 +00:00
|
|
|
|
|
|
|
// shortcode is abbreviated to sc to keep things short
|
|
|
|
|
|
|
|
kwarg = { ident ~ "=" ~ (literal | array) }
|
|
|
|
kwargs = _{ kwarg ~ ("," ~ kwarg )* }
|
|
|
|
sc_def = _{ ident ~ "(" ~ kwargs* ~ ")" }
|
|
|
|
|
|
|
|
inline_shortcode = !{ "{{" ~ sc_def ~ "}}" }
|
|
|
|
ignored_inline_shortcode = !{ "{{/*" ~ sc_def ~ "*/}}" }
|
|
|
|
|
|
|
|
sc_body_start = !{ "{%" ~ sc_def ~ "%}" }
|
|
|
|
sc_body_end = !{ "{%" ~ "end" ~ "%}" }
|
|
|
|
ignored_sc_body_start = !{ "{%/*" ~ sc_def ~ "*/%}" }
|
|
|
|
ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" }
|
|
|
|
|
|
|
|
shortcode_with_body = !{ sc_body_start ~ text_in_body_sc ~ sc_body_end }
|
2018-09-12 14:44:52 +00:00
|
|
|
ignored_shortcode_with_body = { ignored_sc_body_start ~ text_in_ignored_body_sc ~ ignored_sc_body_end }
|
2018-05-03 18:50:30 +00:00
|
|
|
|
2018-10-09 13:24:56 +00:00
|
|
|
text_in_body_sc = ${ (!(sc_body_end) ~ ANY)+ }
|
|
|
|
text_in_ignored_body_sc = ${ (!(ignored_sc_body_end) ~ ANY)+ }
|
2018-10-09 17:56:18 +00:00
|
|
|
text = ${ (!(inline_shortcode | ignored_inline_shortcode | shortcode_with_body | ignored_shortcode_with_body) ~ ANY)+ }
|
2018-05-03 18:50:30 +00:00
|
|
|
|
|
|
|
content = _{
|
|
|
|
ignored_inline_shortcode |
|
|
|
|
inline_shortcode |
|
|
|
|
ignored_shortcode_with_body |
|
|
|
|
shortcode_with_body |
|
|
|
|
text
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-09 13:24:56 +00:00
|
|
|
page = ${ SOI ~ content* ~ EOI }
|