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.

75 lines
2.0KB

  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 Gutenberg
  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. //sc_start = _{ "{{/*" | "{{" | "{%/*" | "{%" }
  38. inline_shortcode = !{ "{{" ~ sc_def ~ "}}" }
  39. ignored_inline_shortcode = !{ "{{/*" ~ sc_def ~ "*/}}" }
  40. sc_body_start = !{ "{%" ~ sc_def ~ "%}" }
  41. sc_body_end = !{ "{%" ~ "end" ~ "%}" }
  42. ignored_sc_body_start = !{ "{%/*" ~ sc_def ~ "*/%}" }
  43. ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" }
  44. shortcode_with_body = !{ sc_body_start ~ text_in_body_sc ~ sc_body_end }
  45. ignored_shortcode_with_body = !{ ignored_sc_body_start ~ text_in_ignored_body_sc ~ ignored_sc_body_end }
  46. text_in_body_sc = ${ (!("{%") ~ any)+ }
  47. text_in_ignored_body_sc = ${ (!("{%/*") ~ any)+ }
  48. text = ${ (!("{{/*" | "{{" | "{%/*" | "{%") ~ any)+ }
  49. content = _{
  50. ignored_inline_shortcode |
  51. inline_shortcode |
  52. ignored_shortcode_with_body |
  53. shortcode_with_body |
  54. text
  55. }
  56. page = ${ soi ~ content* ~ eoi }