aboutsummaryrefslogtreecommitdiffstats
path: root/askama_parser/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-07-02 11:59:30 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-07-31 10:27:15 +0200
commitcdbe8ef39f74fa978f4f2e8ac25acfee2c4432aa (patch)
tree5aa8a9db9e7c81b31c1eea5b5450566b1df84c32 /askama_parser/src/lib.rs
parentaa22236a601d458603ee69d33789afa6022074af (diff)
downloadaskama-cdbe8ef39f74fa978f4f2e8ac25acfee2c4432aa.tar.gz
askama-cdbe8ef39f74fa978f4f2e8ac25acfee2c4432aa.tar.bz2
askama-cdbe8ef39f74fa978f4f2e8ac25acfee2c4432aa.zip
parser: move node parsers into impl block
Diffstat (limited to 'askama_parser/src/lib.rs')
-rw-r--r--askama_parser/src/lib.rs24
1 files changed, 2 insertions, 22 deletions
diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs
index ab3eb83..cf105cb 100644
--- a/askama_parser/src/lib.rs
+++ b/askama_parser/src/lib.rs
@@ -8,7 +8,7 @@ use nom::branch::alt;
use nom::bytes::complete::{escaped, is_not, tag, take_till};
use nom::character::complete::char;
use nom::character::complete::{anychar, digit1};
-use nom::combinator::{eof, map, not, opt, recognize, value};
+use nom::combinator::{map, opt, recognize, value};
use nom::error::ErrorKind;
use nom::multi::separated_list1;
use nom::sequence::{delimited, pair, tuple};
@@ -63,7 +63,7 @@ pub struct Ast<'a> {
impl<'a> Ast<'a> {
pub fn from_str(src: &'a str, syntax: &Syntax<'_>) -> Result<Self, ParseError> {
- let err = match Node::parse(src, &State::new(syntax)) {
+ let err = match Node::many(src, &State::new(syntax)) {
Ok((left, nodes)) => match left.is_empty() {
true => return Ok(Self { nodes }),
false => return Err(ParseError(format!("unable to parse template:\n\n{left:?}"))),
@@ -246,26 +246,6 @@ impl<'a> State<'a> {
}
}
- fn take_content<'i>(&self, i: &'i str) -> IResult<&'i str, Node<'i>> {
- let p_start = alt((
- tag(self.syntax.block_start),
- tag(self.syntax.comment_start),
- tag(self.syntax.expr_start),
- ));
-
- let (i, _) = not(eof)(i)?;
- let (i, content) = opt(recognize(skip_till(p_start)))(i)?;
- let (i, content) = match content {
- Some("") => {
- // {block,comment,expr}_start follows immediately.
- return Err(nom::Err::Error(error_position!(i, ErrorKind::TakeUntil)));
- }
- Some(content) => (i, content),
- None => ("", i), // there is no {block,comment,expr}_start: take everything
- };
- Ok((i, split_ws_parts(content)))
- }
-
fn tag_block_start<'i>(&self, i: &'i str) -> IResult<&'i str, &'i str> {
tag(self.syntax.block_start)(i)
}