diff options
Diffstat (limited to 'askama_derive/src/parser')
-rw-r--r-- | askama_derive/src/parser/mod.rs | 29 | ||||
-rw-r--r-- | askama_derive/src/parser/node.rs | 4 | ||||
-rw-r--r-- | askama_derive/src/parser/tests.rs | 4 |
3 files changed, 20 insertions, 17 deletions
diff --git a/askama_derive/src/parser/mod.rs b/askama_derive/src/parser/mod.rs index d345a81..79b178e 100644 --- a/askama_derive/src/parser/mod.rs +++ b/askama_derive/src/parser/mod.rs @@ -22,12 +22,12 @@ mod node; mod tests; struct State<'a> { - syntax: &'a Syntax, + syntax: &'a Syntax<'a>, loop_depth: Cell<usize>, } -impl State<'_> { - fn new(syntax: &Syntax) -> State<'_> { +impl<'a> State<'a> { + fn new(syntax: &'a Syntax<'a>) -> State<'a> { State { syntax, loop_depth: Cell::new(0), @@ -58,7 +58,10 @@ impl From<char> for Whitespace { } } -pub(crate) fn parse<'a>(src: &'a str, syntax: &'a Syntax) -> Result<Vec<Node<'a>>, CompileError> { +pub(crate) fn parse<'a>( + src: &'a str, + syntax: &'a Syntax<'_>, +) -> Result<Vec<Node<'a>>, CompileError> { match Node::parse(src, &State::new(syntax)) { Ok((left, res)) => { if !left.is_empty() { @@ -271,9 +274,9 @@ fn path(i: &str) -> IResult<&str, Vec<&str>> { fn take_content<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { let p_start = alt(( - tag(s.syntax.block_start.as_str()), - tag(s.syntax.comment_start.as_str()), - tag(s.syntax.expr_start.as_str()), + tag(s.syntax.block_start), + tag(s.syntax.comment_start), + tag(s.syntax.expr_start), )); let (i, _) = not(eof)(i)?; @@ -290,25 +293,25 @@ fn take_content<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { } fn tag_block_start<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.block_start.as_str())(i) + tag(s.syntax.block_start)(i) } fn tag_block_end<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.block_end.as_str())(i) + tag(s.syntax.block_end)(i) } fn tag_comment_start<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.comment_start.as_str())(i) + tag(s.syntax.comment_start)(i) } fn tag_comment_end<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.comment_end.as_str())(i) + tag(s.syntax.comment_end)(i) } fn tag_expr_start<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.expr_start.as_str())(i) + tag(s.syntax.expr_start)(i) } fn tag_expr_end<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { - tag(s.syntax.expr_end.as_str())(i) + tag(s.syntax.expr_end)(i) } diff --git a/askama_derive/src/parser/node.rs b/askama_derive/src/parser/node.rs index 3bd30d8..9f8b37b 100644 --- a/askama_derive/src/parser/node.rs +++ b/askama_derive/src/parser/node.rs @@ -520,8 +520,8 @@ fn block_node<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { fn block_comment_body<'a>(mut i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { let mut level = 0; loop { - let (end, tail) = take_until(s.syntax.comment_end.as_str())(i)?; - match take_until::<_, _, Error<_>>(s.syntax.comment_start.as_str())(i) { + let (end, tail) = take_until(s.syntax.comment_end)(i)?; + match take_until::<_, _, Error<_>>(s.syntax.comment_start)(i) { Ok((start, _)) if start.as_ptr() < end.as_ptr() => { level += 1; i = &start[2..]; diff --git a/askama_derive/src/parser/tests.rs b/askama_derive/src/parser/tests.rs index 045bf28..91bb09b 100644 --- a/askama_derive/src/parser/tests.rs +++ b/askama_derive/src/parser/tests.rs @@ -224,8 +224,8 @@ fn test_parse_root_path() { #[test] fn change_delimiters_parse_filter() { let syntax = Syntax { - expr_start: "{=".to_owned(), - expr_end: "=}".to_owned(), + expr_start: "{=", + expr_end: "=}", ..Syntax::default() }; |