From 88a69fd6f8606ae0c543e83071a3b797fa64d17b Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 3 Jun 2020 21:52:02 +0200 Subject: Reorder parser type definitions --- askama_shared/src/parser.rs | 92 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'askama_shared/src/parser.rs') 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 @@ -10,6 +10,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>), + LetDecl(WS, Target<'a>), + Let(WS, Target<'a>, Expr<'a>), + Cond(Vec<(WS, Option>, Vec>)>, WS), + Match(WS, Expr<'a>, Option<&'a str>, Vec>, WS), + Loop(WS, Target<'a>, Expr<'a>, Vec>, WS), + Extends(Expr<'a>), + BlockDef(WS, &'a str, Vec>, 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), @@ -32,13 +51,23 @@ pub enum Expr<'a> { RustMacro(&'a str, &'a str), } +pub type When<'a> = ( + WS, + Option>, + MatchParameters<'a>, + Vec>, +); + #[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>), + Named(Vec<(&'a str, Option>)>), +} + +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>), - LetDecl(WS, Target<'a>), - Let(WS, Target<'a>, Expr<'a>), - Cond(Vec<(WS, Option>, Vec>)>, WS), - Match(WS, Expr<'a>, Option<&'a str>, Vec>, WS), - Loop(WS, Target<'a>, Expr<'a>, Vec>, WS), - Extends(Expr<'a>), - BlockDef(WS, &'a str, Vec>, 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>, Vec>); - -pub type When<'a> = ( - WS, - Option>, - MatchParameters<'a>, - Vec>, -); - -#[derive(Debug, PartialEq)] -pub enum MatchParameters<'a> { - Simple(Vec>), - Named(Vec<(&'a str, Option>)>), -} +#[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>, Vec>); fn ws(inner: F) -> impl Fn(I) -> IResult where -- cgit