Ejemplo n.º 1
0
        internal static ASTNode GetTemplateNode(JinjaEnvironment environment, string templateText)
        {
            var     lexer          = new Lexer(environment);
            var     tokens         = lexer.Tokenize(templateText).ToArray();
            var     parsed         = Parser.Parse(tokens).ToArray();
            var     outputCombined = OutputCombiner.CombineOutput(parsed);
            ASTNode templateNode   = ASTGenerator.ParseTemplate(environment, lexer, outputCombined);

            //templateNode = templateNode.Transform(CommentRemoverTransformer.Instance);
            templateNode = WhiteSpaceController.ControlWhiteSpace(environment, templateNode);

            return(templateNode);
        }
Ejemplo n.º 2
0
        //internal static Expression ToExpression(JinjaEnvironment environment, string templateText, IDictionary<string, object?> variableTemplate, out ASTCompiler compiler)
        //{
        //    var lexer = new Lexer(environment);
        //    var tokens = lexer.Tokenize(templateText).ToArray();
        //    var parsed = Parser.Parse(tokens).ToArray();
        //    var environmentTrimmed = EnvironmentTrimming.EnvironmentTrim(parsed, environment.Settings).ToArray();
        //    var templateNode = ASTGenerator.ParseTemplate(environmentTrimmed);
        //    var commentsRemoved = templateNode.Transform(CommentRemoverTransformer.Instance);
        //    var controlledWhiteSpace = WhiteSpaceController.ControlWhiteSpace(commentsRemoved);
        //    var containerAssembled = controlledWhiteSpace.Transform(TemplateContainerAssembler.Instance);

        //    var finished = NewASTCompiler.ToExpression(environment, containerAssembled, variableTemplate, out var newcompiler);
        //    throw new NotImplementedException();
        //}
        internal static Expression ToExpression(string templateName, JinjaEnvironment environment, string templateText, IScope rootScope)
        {
            var lexer                = new Lexer(environment);
            var tokens               = lexer.Tokenize(templateText).ToArray();
            var parsed               = Parser.Parse(tokens).ToArray();
            var environmentTrimmed   = EnvironmentTrimming.EnvironmentTrim(parsed, environment.Settings).ToArray();
            var templateNode         = ASTGenerator.ParseTemplate(environmentTrimmed);
            var commentsRemoved      = templateNode.Transform(CommentRemoverTransformer.Instance);
            var controlledWhiteSpace = WhiteSpaceController.ControlWhiteSpace(commentsRemoved);
            var containerAssembled   = controlledWhiteSpace.Transform(TemplateContainerAssembler.Instance);

            var finished = NewASTCompiler.ToExpression(templateName, environment, containerAssembled, out var newcompiler, rootScope);

            return(finished);
        }