Parse self-references and add a test for sections.
This commit is contained in:
parent
71181fbd9a
commit
41ad6179d1
js/test_cases
dot_reference
sections
src/parser
1
js/test_cases/dot_reference/input1.json
Normal file
1
js/test_cases/dot_reference/input1.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"names": ["Alice", "Bob", "Chris"]}
|
3
js/test_cases/dot_reference/main.dust
Normal file
3
js/test_cases/dot_reference/main.dust
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{#names}
|
||||||
|
Hello {.}!
|
||||||
|
{/names}
|
1
js/test_cases/sections/input1.json
Normal file
1
js/test_cases/sections/input1.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": ["Alice", "Bob", "Chris"]}
|
1
js/test_cases/sections/input10.json
Normal file
1
js/test_cases/sections/input10.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": {}}
|
1
js/test_cases/sections/input2.json
Normal file
1
js/test_cases/sections/input2.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": {"name": "Alice", "keyboard": "K-Type"}}
|
1
js/test_cases/sections/input3.json
Normal file
1
js/test_cases/sections/input3.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"there_are_no_things": 4}
|
1
js/test_cases/sections/input4.json
Normal file
1
js/test_cases/sections/input4.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": "just a string"}
|
1
js/test_cases/sections/input5.json
Normal file
1
js/test_cases/sections/input5.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": false}
|
1
js/test_cases/sections/input6.json
Normal file
1
js/test_cases/sections/input6.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": null}
|
1
js/test_cases/sections/input7.json
Normal file
1
js/test_cases/sections/input7.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": 0}
|
1
js/test_cases/sections/input8.json
Normal file
1
js/test_cases/sections/input8.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": ""}
|
1
js/test_cases/sections/input9.json
Normal file
1
js/test_cases/sections/input9.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"things": []}
|
5
js/test_cases/sections/main.dust
Normal file
5
js/test_cases/sections/main.dust
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{#things}
|
||||||
|
Thing: {.}
|
||||||
|
{:else}
|
||||||
|
No things
|
||||||
|
{/things}
|
@ -58,6 +58,9 @@ pub struct Comment<'a> {
|
|||||||
value: &'a str,
|
value: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A series of keys separated by '.' to reference a variable in the context
|
||||||
|
///
|
||||||
|
/// Special case: If the path is just "." then keys will be an empty vec
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct Path<'a> {
|
pub struct Path<'a> {
|
||||||
pub keys: Vec<&'a str>,
|
pub keys: Vec<&'a str>,
|
||||||
@ -197,7 +200,10 @@ fn key(i: &str) -> IResult<&str, &str> {
|
|||||||
|
|
||||||
/// A series of keys separated by '.' to reference a variable in the context
|
/// A series of keys separated by '.' to reference a variable in the context
|
||||||
fn path(i: &str) -> IResult<&str, Path> {
|
fn path(i: &str) -> IResult<&str, Path> {
|
||||||
map(separated_list1(tag("."), key), |body| Path { keys: body })(i)
|
alt((
|
||||||
|
map(separated_list1(tag("."), key), |body| Path { keys: body }),
|
||||||
|
value(Path { keys: Vec::new() }, tag(".")),
|
||||||
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Either a literal or a path to a value
|
/// Either a literal or a path to a value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user