From 014c0620c41a4b891eb1fa7086f41044e8c9a79b Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Mon, 31 May 2021 20:29:45 +0800 Subject: [PATCH 1/2] (fix) add support for . as path --- examples/partials/template2.hbs | 2 +- src/grammar.pest | 5 +++-- src/grammar.rs | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/partials/template2.hbs b/examples/partials/template2.hbs index 934416eb7..60255888b 100644 --- a/examples/partials/template2.hbs +++ b/examples/partials/template2.hbs @@ -1,4 +1,4 @@ {{#*inline "page"}}

Rendered in partial, parent is {{parent}}

{{/inline}} -{{> (lookup this "parent")}} +{{> (lookup . "parent")}} diff --git a/src/grammar.pest b/src/grammar.pest index 6ed45e53f..2842990bc 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -40,7 +40,7 @@ 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) ~ ")" } @@ -130,5 +130,6 @@ path_root = { "@root" } path_current = _{ "this" ~ path_sep | "./" } path_item = _{ path_id|path_key } path_local = { "@" } +path_this_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_this_standalone ~ EOI) | (path_inline ~ EOI) } diff --git a/src/grammar.rs b/src/grammar.rs index 6be52a6cc..4b5fa788f 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -183,6 +183,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); @@ -306,6 +307,8 @@ mod test { "[foo]", "@root/a/b", "nullable", + ".", + "this", ]; for i in s.iter() { assert_rule_match!(Rule::path, i); From 2b934934cc49c7dc109e275d9e6722a36832f52a Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 1 Jun 2021 22:50:27 +0800 Subject: [PATCH 2/2] (fix) attempt to add support for standalone . --- src/grammar.pest | 8 ++++---- src/grammar.rs | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/grammar.pest b/src/grammar.pest index 2842990bc..6e5f3faee 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -32,7 +32,7 @@ path_char = _{ "/" } identifier = @{ symbol_char+ } partial_identifier = @{ partial_symbol_char+ | ("[" ~ ANY+ ~ "]") | ("'" ~ (!"'" ~ ("\\'" | ANY))+ ~ "'") } -reference = ${ path_inline } +reference = { path_inline } name = _{ subexpression | reference } @@ -127,9 +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_this_standalone = _{ "." } +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_this_standalone ~ EOI) | (path_inline ~ EOI) } +path = _{ (path_inline ~ EOI) | (path_current_standalone ~ EOI) } diff --git a/src/grammar.rs b/src/grammar.rs index 4b5fa788f..2b0bb6e6a 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -85,6 +85,8 @@ mod test { "[$id]", "$id", "this.[null]", + ".", + "this", ]; for i in s.iter() { assert_rule!(Rule::reference, i);