Skip to content

Commit

Permalink
fix(templ): don't parse incomplete macro tags
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Feb 3, 2025
1 parent a2712cb commit 85692ec
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions crates/rari-doc/src/templ/rari-templ.pest
Original file line number Diff line number Diff line change
@@ -1,72 +1,64 @@

WHITESPACE = _{ " " | "\t" | "\r" | "\n" }

int = @{ "-" ? ~ ("0" | '1'..'9' ~ '0'..'9' * ) }
float = @{
"-" ? ~
(
"0" ~ "." ~ '0'..'9' + |
'1'..'9' ~ '0'..'9' * ~ "." ~ '0'..'9' +
)
int = @{ "-"? ~ ("0" | '1'..'9' ~ '0'..'9'*) }
float = @{
"-"? ~ ("0" ~ "." ~ '0'..'9'+ | '1'..'9' ~ '0'..'9'* ~ "." ~ '0'..'9'+)
}
dq_char = {
dq_char = {
!("\"" | "\\") ~ ANY
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
sq_char = {
sq_char = {
!("'" | "\\") ~ ANY
| "\\" ~ ("'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
| "\\" ~ ("'" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
bq_char = {
bq_char = {
!("`" | "\\") ~ ANY
| "\\" ~ ( "`" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
| "\\" ~ ("`" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
dq_string = @{ (!("\"") ~ dq_char )* }
sq_string = @{ (!("\'") ~ sq_char )* }
bq_string = @{ (!("`") ~ bq_char )* }
double_quoted_string = ${ "\"" ~ dq_string ~ "\""}
single_quoted_string = ${ "\'" ~ sq_string ~ "\'"}
backquoted_quoted_string = ${ "`" ~ bq_string ~ "`"}
dq_string = @{ (!("\"") ~ dq_char)* }
sq_string = @{ (!("\'") ~ sq_char)* }
bq_string = @{ (!("`") ~ bq_char)* }
double_quoted_string = ${ "\"" ~ dq_string ~ "\"" }
single_quoted_string = ${ "\'" ~ sq_string ~ "\'" }
backquoted_quoted_string = ${ "`" ~ bq_string ~ "`" }

string = _{
double_quoted_string |
single_quoted_string |
backquoted_quoted_string
double_quoted_string
| single_quoted_string
| backquoted_quoted_string
}

boolean = { "true" | "false" }
none = { "" }
boolean = { "true" | "false" }
none = { "" }
empty_string = { "\"\"" | "''" | "``" }


all_chars = _{'a'..'z' | 'A'..'Z' | "_" | "-" | '0'..'9'}
ident = ${
('a'..'z' | 'A'..'Z' | "_") ~
all_chars*
all_chars = _{ 'a'..'z' | 'A'..'Z' | "_" | "-" | '0'..'9' }
ident = ${
('a'..'z' | 'A'..'Z' | "_") ~ all_chars*
}

arg = _{ empty_string | string | float | int | boolean | none }
kwargs = !{ arg ~ ("," ~ arg )* ~ ","? }
arg = _{ empty_string | string | float | int | boolean | none }
kwargs = !{ arg ~ ("," ~ arg)* ~ ","? }
fn_call = !{ ident ~ "(" ~ kwargs? ~ ")" }

tag_start = _{ "{{" }
tag_end = _{ "}}" }
tag_end = _{ "}}" }

macro_tag = ${
tag_start ~ WHITESPACE* ~ (fn_call | ident)
~ WHITESPACE* ~ tag_end
tag_start ~ WHITESPACE* ~ (fn_call | ident) ~ WHITESPACE* ~ tag_end
}

dropped_escape = _{ "\\\\" | "\\" }
text = ${ ((dropped_escape | !(tag_start)) ~ ANY)+ }
content = @{
text |
macro_tag
text = ${ ((dropped_escape | !(macro_tag)) ~ ANY)+ }
content = @{
macro_tag
| text
}

doc = @{
content*
content*
}

0 comments on commit 85692ec

Please sign in to comment.