Skip to content

Commit

Permalink
Resolves rinja-rs#331
Browse files Browse the repository at this point in the history
  • Loading branch information
vallentin committed Dec 2, 2020
1 parent a199def commit 0ff2a8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 16 additions & 6 deletions askama_shared/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,15 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
}

fn visit_path(&mut self, buf: &mut Buffer, path: &[&str]) -> DisplayWrap {
for (i, part) in path.iter().enumerate() {
if i > 0 {
buf.write("::");
let mut it = path.iter();
match it.next() {
Some(&part) if part != "::" => {
buf.write(part);
}
_ => {}
}
for part in it {
buf.write("::");
buf.write(part);
}
DisplayWrap::Unwrapped
Expand All @@ -1357,10 +1362,15 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
path: &[&str],
args: &[Expr],
) -> Result<DisplayWrap, CompileError> {
for (i, part) in path.iter().enumerate() {
if i > 0 {
buf.write("::");
let mut it = path.iter();
match it.next() {
Some(&part) if part != "::" => {
buf.write(part);
}
_ => {}
}
for part in it {
buf.write("::");
buf.write(part);
}
buf.write("(");
Expand Down
10 changes: 6 additions & 4 deletions askama_shared/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nom::branch::alt;
use nom::bytes::complete::{escaped, is_not, tag, take_until};
use nom::character::complete::{anychar, char, digit1};
use nom::combinator::{complete, map, opt};
use nom::combinator::{complete, map, opt, value};
use nom::error::ParseError;
use nom::multi::{many0, many1, separated_list0, separated_list1};
use nom::sequence::{delimited, pair, tuple};
Expand Down Expand Up @@ -312,10 +312,12 @@ fn expr_var_call(i: &[u8]) -> IResult<&[u8], Expr> {
}

fn path(i: &[u8]) -> IResult<&[u8], Vec<&str>> {
let root = opt(value("::", ws(tag("::"))));
let tail = separated_list1(ws(tag("::")), identifier);
let (i, (start, _, rest)) = tuple((identifier, ws(tag("::")), tail))(i)?;

let mut path = vec![start];
let (i, (root, start, _, rest)) = tuple((root, identifier, ws(tag("::")), tail))(i)?;
let mut path = Vec::new();
path.extend(root);
path.push(start);
path.extend(rest);
Ok((i, path))
}
Expand Down

0 comments on commit 0ff2a8f

Please sign in to comment.