From 1a9f5a16fb54d6c75a8e36aafa9703cc29a0a76a Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 1 Jul 2023 16:12:54 +0200 Subject: derive: move Parsed into parser module --- askama_derive/src/generator.rs | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'askama_derive/src/generator.rs') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index e2d657f..b6c6151 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -1,7 +1,7 @@ use crate::config::{get_template_source, read_config_file, Config, WhitespaceHandling}; use crate::heritage::{Context, Heritage}; use crate::input::{Print, Source, TemplateInput}; -use crate::parser::{Cond, CondTest, Expr, Loop, Node, Target, When, Whitespace, Ws}; +use crate::parser::{Cond, CondTest, Expr, Loop, Node, Parsed, Target, When, Whitespace, Ws}; use crate::CompileError; use proc_macro::TokenStream; @@ -241,41 +241,6 @@ fn find_used_templates( Ok(()) } -mod _parsed { - use std::mem; - - use crate::parser::{parse, Node, Syntax}; - use crate::CompileError; - - pub(super) struct Parsed { - #[allow(dead_code)] - source: String, - nodes: Vec>, - } - - impl Parsed { - pub(super) fn new(source: String, syntax: &Syntax<'_>) -> Result { - // Self-referential borrowing: `self` will keep the source alive as `String`, - // internally we will transmute it to `&'static str` to satisfy the compiler. - // However, we only expose the nodes with a lifetime limited to `self`. - let src = unsafe { mem::transmute::<&str, &'static str>(source.as_str()) }; - let nodes = match parse(src, syntax) { - Ok(nodes) => nodes, - Err(e) => return Err(e.to_string().into()), - }; - - Ok(Self { source, nodes }) - } - - // The return value's lifetime must be limited to `self` to uphold the unsafe invariant. - pub(super) fn nodes(&self) -> &[Node<'_>] { - &self.nodes - } - } -} - -use _parsed::Parsed; - struct Generator<'a> { // The template input state: original struct AST and attributes input: &'a TemplateInput<'a>, -- cgit