diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-06-03 21:52:02 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-06-03 21:52:02 +0200 |
commit | 88a69fd6f8606ae0c543e83071a3b797fa64d17b (patch) | |
tree | d6bd18fbda75140f28f9ba5cd0fbe166eac2a2e2 | |
parent | cfc38883b4b0247f21cb3403845d2fe3df06df0c (diff) | |
download | askama-88a69fd6f8606ae0c543e83071a3b797fa64d17b.tar.gz askama-88a69fd6f8606ae0c543e83071a3b797fa64d17b.tar.bz2 askama-88a69fd6f8606ae0c543e83071a3b797fa64d17b.zip |
Reorder parser type definitions
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/parser.rs | 92 |
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 |