You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might be related to #271 and it's a real world case in handlebars
consider the rules
WHITESPACE = _{ " " }
name = @{ "_"? ~ ('a'..'z')+ }
param = { name }
hash = { name ~ "=" ~ name }
v = { hash | param }
exp = { "{{" ~ name ~ v+ ~ "}}"}
The rule exp works great to match expression like {{echo a b c d=1}} until there is an invalid name within it, like {{echo a b c_d}}. Note that in our name rule, underscore is only allowed as a leading character. However, in this case it still matches exp, with c and _d parsed as two params. What I expect is a failure of matching.
So I changed exp to below to ensure whitespaces between params.
exp = { "{{" ~ name ~ v ~ (WHITESPACE+ ~ v)* ~ "}}"}
However, it fails to match basic case like {{echo a b}}, and says
If you add a $ before the brackets for hash (hash = ${ param ~ "=" ~ value }) then you no longer allow whitespace in-between the = signs. AKA
{{echo a b=2 c_d = 39 }} <- this fails
{{echo a b=2 c_d=39 }} <- this is fine
And you can further customize it by using (hash = ${ param ~ WHITESPACE? ~ "=" ~ WHITESPACE? ~ value }), which has optional whitespace on both sides of the = sign. If you only wanted specific kinds of whitespace on a specific kind that is possible as well. Now all of the examples supplied are parsed again.
This might be related to #271 and it's a real world case in handlebars
consider the rules
The rule
exp
works great to match expression like{{echo a b c d=1}}
until there is an invalidname
within it, like{{echo a b c_d}}
. Note that in ourname
rule, underscore is only allowed as a leading character. However, in this case it still matchesexp
, withc
and_d
parsed as twoparam
s. What I expect is a failure of matching.So I changed
exp
to below to ensure whitespaces between params.However, it fails to match basic case like
{{echo a b}}
, and sayswhich is confusing. So before #271 landing (seems never to happen) , is there any workaround for my case?
The text was updated successfully, but these errors were encountered: