diff options
-rw-r--r-- | askama_shared/src/parser.rs | 10 | ||||
-rw-r--r-- | testing/templates/tuple-attr.html | 1 | ||||
-rw-r--r-- | testing/tests/simple.rs | 12 |
3 files changed, 20 insertions, 3 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 5de964f..ab79a31 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -118,8 +118,12 @@ fn identifier(input: &[u8]) -> IResult<&[u8], &str> { IResult::Done(&input[1..], str::from_utf8(&input[..1]).unwrap()) } -named!(expr_num_lit<Expr>, map!(nom::digit, - |s| Expr::NumLit(str::from_utf8(s).unwrap()) +named!(num_lit<&str>, map!(nom::digit, + |s| str::from_utf8(s).unwrap() +)); + +named!(expr_num_lit<Expr>, map!(num_lit, + |s| Expr::NumLit(s) )); named!(expr_str_lit<Expr>, map!( @@ -187,7 +191,7 @@ named!(expr_single<Expr>, alt!( named!(attr<(&str, Option<Vec<Expr>>)>, do_parse!( tag_s!(".") >> - attr: identifier >> + attr: alt!(num_lit | identifier) >> args: opt!(arguments) >> (attr, args) )); diff --git a/testing/templates/tuple-attr.html b/testing/templates/tuple-attr.html new file mode 100644 index 0000000..4a7d781 --- /dev/null +++ b/testing/templates/tuple-attr.html @@ -0,0 +1 @@ +{{ tuple.0 }}{{ tuple.1 }} diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index eac7c4b..d2111f0 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -93,6 +93,18 @@ fn test_attr() { assert_eq!(t.render().unwrap(), "5"); } +#[derive(Template)] +#[template(path = "tuple-attr.html")] +struct TupleAttrTemplate<'a> { + tuple: (&'a str, &'a str), +} + +#[test] +fn test_tuple_attr() { + let t = TupleAttrTemplate { tuple: ("foo", "bar") }; + assert_eq!(t.render().unwrap(), "foobar"); +} + struct NestedHolder { holder: Holder, |