diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-03-10 09:02:10 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-03-23 19:37:10 +0100 |
commit | 07584691a8b2ff44776d22c9f9b2c4ec1b303948 (patch) | |
tree | 43549d7d414aad8c728b7f6b6e3c67c0b6004898 /askama_shared/src/parser.rs | |
parent | 4c0388d11e1bafb85250b649ff610d3f9c7f9452 (diff) | |
download | askama-07584691a8b2ff44776d22c9f9b2c4ec1b303948.tar.gz askama-07584691a8b2ff44776d22c9f9b2c4ec1b303948.tar.bz2 askama-07584691a8b2ff44776d22c9f9b2c4ec1b303948.zip |
Un-"pub" most of askama_shared's internals
Previously askama_shared exported most of it's internals, so
askama_derive could use them. This is not needed anymore.
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r-- | askama_shared/src/parser.rs | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 900e71a..2a7f49f 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -13,7 +13,7 @@ use nom::{self, error_position, AsChar, IResult, InputTakeAtPosition}; use crate::{CompileError, Syntax}; #[derive(Debug, PartialEq)] -pub enum Node<'a> { +pub(crate) enum Node<'a> { Lit(&'a str, &'a str, &'a str), Comment(Ws), Expr(Ws, Expr<'a>), @@ -34,19 +34,19 @@ pub enum Node<'a> { } #[derive(Debug, PartialEq)] -pub struct Loop<'a> { - pub ws1: Ws, - pub var: Target<'a>, - pub iter: Expr<'a>, - pub cond: Option<Expr<'a>>, - pub body: Vec<Node<'a>>, - pub ws2: Ws, - pub else_block: Vec<Node<'a>>, - pub ws3: Ws, +pub(crate) struct Loop<'a> { + pub(crate) ws1: Ws, + pub(crate) var: Target<'a>, + pub(crate) iter: Expr<'a>, + pub(crate) cond: Option<Expr<'a>>, + pub(crate) body: Vec<Node<'a>>, + pub(crate) ws2: Ws, + pub(crate) else_block: Vec<Node<'a>>, + pub(crate) ws3: Ws, } #[derive(Debug, PartialEq)] -pub enum Expr<'a> { +pub(crate) enum Expr<'a> { BoolLit(&'a str), NumLit(&'a str), StrLit(&'a str), @@ -70,7 +70,7 @@ pub enum Expr<'a> { impl Expr<'_> { /// Returns `true` if enough assumptions can be made, /// to determine that `self` is copyable. - pub fn is_copyable(&self) -> bool { + pub(crate) fn is_copyable(&self) -> bool { self.is_copyable_within_op(false) } @@ -98,7 +98,7 @@ impl Expr<'_> { } /// Returns `true` if this is an `Attr` where the `obj` is `"self"`. - pub fn is_attr_self(&self) -> bool { + pub(crate) fn is_attr_self(&self) -> bool { match self { Expr::Attr(obj, _) if matches!(obj.as_ref(), Expr::Var("self")) => true, Expr::Attr(obj, _) if matches!(obj.as_ref(), Expr::Attr(..)) => obj.is_attr_self(), @@ -107,18 +107,18 @@ impl Expr<'_> { } } -pub type When<'a> = (Ws, Target<'a>, Vec<Node<'a>>); +pub(crate) type When<'a> = (Ws, Target<'a>, Vec<Node<'a>>); #[derive(Debug, PartialEq)] -pub struct Macro<'a> { - pub ws1: Ws, - pub args: Vec<&'a str>, - pub nodes: Vec<Node<'a>>, - pub ws2: Ws, +pub(crate) struct Macro<'a> { + pub(crate) ws1: Ws, + pub(crate) args: Vec<&'a str>, + pub(crate) nodes: Vec<Node<'a>>, + pub(crate) ws2: Ws, } #[derive(Debug, PartialEq)] -pub enum Target<'a> { +pub(crate) enum Target<'a> { Name(&'a str), Tuple(Vec<&'a str>, Vec<Target<'a>>), Struct(Vec<&'a str>, Vec<(&'a str, Target<'a>)>), @@ -130,14 +130,14 @@ pub enum Target<'a> { } #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Ws(pub bool, pub bool); +pub(crate) struct Ws(pub(crate) bool, pub(crate) bool); -pub type Cond<'a> = (Ws, Option<CondTest<'a>>, Vec<Node<'a>>); +pub(crate) type Cond<'a> = (Ws, Option<CondTest<'a>>, Vec<Node<'a>>); #[derive(Debug, PartialEq)] -pub struct CondTest<'a> { - pub target: Option<Target<'a>>, - pub expr: Expr<'a>, +pub(crate) struct CondTest<'a> { + pub(crate) target: Option<Target<'a>>, + pub(crate) expr: Expr<'a>, } fn is_ws(c: char) -> bool { @@ -1157,7 +1157,10 @@ fn tag_expr_end<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, &'a str> { tag(s.syntax.expr_end)(i) } -pub fn parse<'a>(src: &'a str, syntax: &'a Syntax<'a>) -> Result<Vec<Node<'a>>, CompileError> { +pub(crate) fn parse<'a>( + src: &'a str, + syntax: &'a Syntax<'a>, +) -> Result<Vec<Node<'a>>, CompileError> { let state = State { syntax, loop_depth: Cell::new(0), |