aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r--askama_shared/src/parser.rs92
1 files changed, 46 insertions, 46 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs
index 67d28b4..3a3157a 100644
--- a/askama_shared/src/parser.rs
+++ b/askama_shared/src/parser.rs
@@ -11,6 +11,25 @@ use std::str;
use crate::Syntax;
#[derive(Debug, PartialEq)]
+pub enum Node<'a> {
+ Lit(&'a str, &'a str, &'a str),
+ Comment(WS),
+ Expr(WS, Expr<'a>),
+ Call(WS, Option<&'a str>, &'a str, Vec<Expr<'a>>),
+ LetDecl(WS, Target<'a>),
+ Let(WS, Target<'a>, Expr<'a>),
+ Cond(Vec<(WS, Option<Expr<'a>>, Vec<Node<'a>>)>, WS),
+ Match(WS, Expr<'a>, Option<&'a str>, Vec<When<'a>>, WS),
+ Loop(WS, Target<'a>, Expr<'a>, Vec<Node<'a>>, WS),
+ Extends(Expr<'a>),
+ BlockDef(WS, &'a str, Vec<Node<'a>>, WS),
+ Include(WS, &'a str),
+ Import(WS, &'a str, &'a str),
+ Macro(&'a str, Macro<'a>),
+ Raw(WS, &'a str, WS),
+}
+
+#[derive(Debug, PartialEq)]
pub enum Expr<'a> {
BoolLit(&'a str),
NumLit(&'a str),
@@ -32,13 +51,23 @@ pub enum Expr<'a> {
RustMacro(&'a str, &'a str),
}
+pub type When<'a> = (
+ WS,
+ Option<MatchVariant<'a>>,
+ MatchParameters<'a>,
+ Vec<Node<'a>>,
+);
+
#[derive(Debug, PartialEq)]
-pub enum MatchVariant<'a> {
- Path(Vec<&'a str>),
- Name(&'a str),
- NumLit(&'a str),
- StrLit(&'a str),
- CharLit(&'a str),
+pub enum MatchParameters<'a> {
+ Simple(Vec<MatchParameter<'a>>),
+ Named(Vec<(&'a str, Option<MatchParameter<'a>>)>),
+}
+
+impl<'a> Default for MatchParameters<'a> {
+ fn default() -> Self {
+ MatchParameters::Simple(vec![])
+ }
}
#[derive(Debug, PartialEq)]
@@ -50,14 +79,14 @@ pub enum MatchParameter<'a> {
}
#[derive(Debug, PartialEq)]
-pub enum Target<'a> {
+pub enum MatchVariant<'a> {
+ Path(Vec<&'a str>),
Name(&'a str),
- Tuple(Vec<&'a str>),
+ NumLit(&'a str),
+ StrLit(&'a str),
+ CharLit(&'a str),
}
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct WS(pub bool, pub bool);
-
#[derive(Debug, PartialEq)]
pub struct Macro<'a> {
pub ws1: WS,
@@ -67,44 +96,15 @@ pub struct Macro<'a> {
}
#[derive(Debug, PartialEq)]
-pub enum Node<'a> {
- Lit(&'a str, &'a str, &'a str),
- Comment(WS),
- Expr(WS, Expr<'a>),
- Call(WS, Option<&'a str>, &'a str, Vec<Expr<'a>>),
- LetDecl(WS, Target<'a>),
- Let(WS, Target<'a>, Expr<'a>),
- Cond(Vec<(WS, Option<Expr<'a>>, Vec<Node<'a>>)>, WS),
- Match(WS, Expr<'a>, Option<&'a str>, Vec<When<'a>>, WS),
- Loop(WS, Target<'a>, Expr<'a>, Vec<Node<'a>>, WS),
- Extends(Expr<'a>),
- BlockDef(WS, &'a str, Vec<Node<'a>>, WS),
- Include(WS, &'a str),
- Import(WS, &'a str, &'a str),
- Macro(&'a str, Macro<'a>),
- Raw(WS, &'a str, WS),
+pub enum Target<'a> {
+ Name(&'a str),
+ Tuple(Vec<&'a str>),
}
-pub type Cond<'a> = (WS, Option<Expr<'a>>, Vec<Node<'a>>);
-
-pub type When<'a> = (
- WS,
- Option<MatchVariant<'a>>,
- MatchParameters<'a>,
- Vec<Node<'a>>,
-);
-
-#[derive(Debug, PartialEq)]
-pub enum MatchParameters<'a> {
- Simple(Vec<MatchParameter<'a>>),
- Named(Vec<(&'a str, Option<MatchParameter<'a>>)>),
-}
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct WS(pub bool, pub bool);
-impl<'a> Default for MatchParameters<'a> {
- fn default() -> Self {
- MatchParameters::Simple(vec![])
- }
-}
+pub type Cond<'a> = (WS, Option<Expr<'a>>, Vec<Node<'a>>);
fn ws<F, I, O, E>(inner: F) -> impl Fn(I) -> IResult<I, O, E>
where