Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone dot as parameter #443

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/partials/template2.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#*inline "page"}}
<p>Rendered in partial, parent is {{parent}}</p>
{{/inline}}
{{> (lookup this "parent")}}
{{> (lookup . "parent")}}
9 changes: 5 additions & 4 deletions src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ path_char = _{ "/" }

identifier = @{ symbol_char+ }
partial_identifier = @{ partial_symbol_char+ | ("[" ~ ANY+ ~ "]") | ("'" ~ (!"'" ~ ("\\'" | ANY))+ ~ "'") }
reference = ${ path_inline }
reference = { path_inline }

name = _{ subexpression | reference }

param = { !(keywords ~ !symbol_char) ~ (literal | reference | subexpression) }
hash = { identifier ~ "=" ~ param }
block_param = { "as" ~ "|" ~ identifier ~ identifier? ~ "|"}
exp_line = _{ identifier ~ (hash|param)* ~ block_param?}
partial_exp_line = _{ ((partial_identifier|name) ~ (hash|param)*) }
partial_exp_line = _{ (partial_identifier|name) ~ (hash|param)* }

subexpression = { "(" ~ ((identifier ~ (hash|param)+) | reference) ~ ")" }

Expand Down Expand Up @@ -127,8 +127,9 @@ path_sep = _{ "/" | "." }
path_up = { ".." }
path_key = _{ "[" ~ path_raw_id ~ "]" }
path_root = { "@root" }
path_current = _{ "this" ~ path_sep | "./" }
path_current = @{ ("this" ~ path_sep) | "./" }
path_item = _{ path_id|path_key }
path_local = { "@" }
path_current_standalone = _{ "." }
path_inline = ${ path_current? ~ (path_root ~ path_sep)? ~ path_local? ~ (path_up ~ path_sep)* ~ path_item ~ (path_sep ~ path_item)* }
path = _{ path_inline ~ EOI }
path = _{ (path_inline ~ EOI) | (path_current_standalone ~ EOI) }
5 changes: 5 additions & 0 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ mod test {
"[$id]",
"$id",
"this.[null]",
".",
"this",
];
for i in s.iter() {
assert_rule!(Rule::reference, i);
Expand Down Expand Up @@ -183,6 +185,7 @@ mod test {
"{{exp key=(sub)}}",
"{{exp key=(sub 0)}}",
"{{exp key=(sub 0 key=1)}}",
"{{exp .}}",
];
for i in s.iter() {
assert_rule!(Rule::expression, i);
Expand Down Expand Up @@ -306,6 +309,8 @@ mod test {
"[foo]",
"@root/a/b",
"nullable",
".",
"this",
];
for i in s.iter() {
assert_rule_match!(Rule::path, i);
Expand Down