You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

content.pest 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Partly taken from Tera
  2. WHITESPACE = _{ " " | "\t" | "\r" | "\n" }
  3. /// LITERALS
  4. int = @{ "-" ? ~ ("0" | '1'..'9' ~ '0'..'9' * ) }
  5. float = @{
  6. "-" ? ~
  7. (
  8. "0" ~ "." ~ '0'..'9' + |
  9. '1'..'9' ~ '0'..'9' * ~ "." ~ '0'..'9' +
  10. )
  11. }
  12. // matches anything between 2 double quotes
  13. double_quoted_string = @{ "\"" ~ (!("\"") ~ ANY)* ~ "\""}
  14. // matches anything between 2 single quotes
  15. single_quoted_string = @{ "\'" ~ (!("\'") ~ ANY)* ~ "\'"}
  16. // matches anything between 2 backquotes\backticks
  17. backquoted_quoted_string = @{ "`" ~ (!("`") ~ ANY)* ~ "`"}
  18. string = @{
  19. double_quoted_string |
  20. single_quoted_string |
  21. backquoted_quoted_string
  22. }
  23. boolean = { "true" | "false" }
  24. literal = { boolean | string | float | int }
  25. array = { "[" ~ (literal ~ ",")* ~ literal? ~ "]"}
  26. /// Idents
  27. all_chars = _{'a'..'z' | 'A'..'Z' | "_" | '0'..'9'}
  28. ident = @{
  29. ('a'..'z' | 'A'..'Z' | "_") ~
  30. all_chars*
  31. }
  32. /// Now specific to Zola
  33. // shortcode is abbreviated to sc to keep things short
  34. kwarg = { ident ~ "=" ~ (literal | array) }
  35. kwargs = _{ kwarg ~ ("," ~ kwarg )* }
  36. sc_def = _{ ident ~ "(" ~ kwargs* ~ ")" }
  37. inline_shortcode = !{ "{{" ~ sc_def ~ "}}" }
  38. ignored_inline_shortcode = !{ "{{/*" ~ sc_def ~ "*/}}" }
  39. sc_body_start = !{ "{%" ~ sc_def ~ "%}" }
  40. sc_body_end = !{ "{%" ~ "end" ~ "%}" }
  41. ignored_sc_body_start = !{ "{%/*" ~ sc_def ~ "*/%}" }
  42. ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" }
  43. shortcode_with_body = !{ sc_body_start ~ text_in_body_sc ~ sc_body_end }
  44. ignored_shortcode_with_body = { ignored_sc_body_start ~ text_in_ignored_body_sc ~ ignored_sc_body_end }
  45. text_in_body_sc = ${ (!(sc_body_end) ~ ANY)+ }
  46. text_in_ignored_body_sc = ${ (!(ignored_sc_body_end) ~ ANY)+ }
  47. text = ${ (!(inline_shortcode | ignored_inline_shortcode | shortcode_with_body | ignored_shortcode_with_body) ~ ANY)+ }
  48. content = _{
  49. ignored_inline_shortcode |
  50. inline_shortcode |
  51. ignored_shortcode_with_body |
  52. shortcode_with_body |
  53. text
  54. }
  55. page = ${ SOI ~ content* ~ EOI }