override public void WriteTo(ParserNodeContext Context)
		{
			foreach (var Node in Nodes)
			{
				Node.WriteTo(Context);
			}
		}
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write(Context._GetContextWriteAutoFilteredMethod() + "(");
     Parent.WriteTo(Context);
     Context.Write(");");
     Context.WriteLine("");
 }
Example #3
0
 override public void WriteTo(ParserNodeContext Context)
 {
     Context.Write("Context.OutputWriteAutoFiltered(");
     Parent.WriteTo(Context);
     Context.Write(");");
     Context.WriteLine("");
 }
Example #4
0
        override public void WriteTo(ParserNodeContext Context)
        {
            //DynamicUtils.CountArray

            //Foreach(TemplateContext Context, String VarName, dynamic Expression, Action Iteration, Action Else = null)

            Context.WriteLine("Context.NewScope(delegate() {");
            Context.Indent(delegate()
            {
                Context.Write("Foreach(Context, {0}, ", StringUtils.EscapeString(VarName));
                Context.Indent(delegate()
                {
                    LoopIterator.WriteTo(Context);
                });
                Context.Write(", ");
                Context.WriteLine("new EmptyDelegate(delegate() {");
                Context.Indent(delegate()
                {
                    BodyBlock.WriteTo(Context);
                });
                Context.Write("})");
                if (!(ElseBlock is DummyParserNode))
                {
                    Context.Write(", ");
                    Context.WriteLine("new EmptyDelegate(delegate() {");
                    ElseBlock.WriteTo(Context);
                    Context.Write("})");
                }
                Context.WriteLine(");");          // Foreach
            });
            Context.WriteLine("});");             // Context.NewScope
        }
        public override ParserNode Optimize(ParserNodeContext Context)
        {
            var That = CreateThisInstanceAs <ParserNodeParent>();

            That.Parent = Parent.Optimize(Context);
            return(That);
        }
Example #6
0
		protected void RenderCodeTo(TextWriter TextWriter)
		{
			var TemplateHandler = new TemplateParser(Tokens, TextWriter);
			var Context = new ParserNodeContext(TextWriter, TemplateFactory);
			TemplateHandler.Reset();
			var ParserNode = TemplateHandler.HandleLevel_Root();

			//OptimizedParserNode.Dump();
			Context.WriteLine("using System;");
			Context.WriteLine("using System.Collections.Generic;");
			Context.WriteLine("using System.Threading.Tasks;");
			Context.WriteLine("using CSharpUtils.Templates;");
			Context.WriteLine("using CSharpUtils.Templates.Runtime;");
			Context.WriteLine("using CSharpUtils.Templates.TemplateProvider;");
			Context.WriteLine("");
			//Context.WriteLine("namespace CSharpUtils.Templates.CompiledTemplates {");
			Context.Indent(delegate()
			{
				Context.WriteLine("class CompiledTemplate_TempTemplate : TemplateCode {");

				Context.Indent(delegate()
				{
					Context.WriteLine("public CompiledTemplate_TempTemplate(TemplateFactory TemplateFactory = null) : base(TemplateFactory) { }");
					Context.WriteLine("");

					Context.WriteLine("public override void SetBlocks(Dictionary<String, RenderDelegate> Blocks) {");
					Context.Indent(delegate()
					{
						foreach (var BlockPair in TemplateHandler.Blocks)
						{
							Context.WriteLine(String.Format("SetBlock(Blocks, {0}, Block_{1});", StringUtils.EscapeString(BlockPair.Key), BlockPair.Key));
						}
					});
					Context.WriteLine("}");
					Context.WriteLine("");

					Context.WriteLine("async protected override Task LocalRenderAsync(TemplateContext Context) {");
					Context.Indent(delegate()
					{
						ParserNode.OptimizeAndWrite(Context);
					});
					Context.WriteLine("}"); // Method

					foreach (var BlockPair in TemplateHandler.Blocks)
					{
						Context.WriteLine("");
						Context.WriteLine("public async Task Block_" + BlockPair.Key + "(TemplateContext Context) {");
						Context.Indent(delegate()
						{
							BlockPair.Value.OptimizeAndWrite(Context);
						});
						Context.WriteLine("}"); // Method
					}
				});

				Context.WriteLine("}"); // class
			});

			//Context.WriteLine("}"); // namespace
		}
Example #7
0
		public override void WriteTo(ParserNodeContext Context)
		{
			//DynamicUtils.CountArray

			//Foreach(TemplateContext Context, String VarName, dynamic Expression, Action Iteration, Action Else = null)

			Context.WriteLine("Context.NewScope(delegate() {");
			Context.Indent(delegate()
			{
				Context.Write("Foreach(Context, {0}, ", StringUtils.EscapeString(VarName));
				Context.Indent(delegate()
				{
					LoopIterator.WriteTo(Context);
				});
				Context.Write(", ");
				Context.WriteLine("new EmptyDelegate(async delegate() {");
				Context.Indent(delegate()
				{
					BodyBlock.WriteTo(Context);
				});
				Context.Write("})");
				if (!(ElseBlock is DummyParserNode))
				{
					Context.Write(", ");
					Context.WriteLine("new EmptyDelegate(async delegate() {");
					ElseBlock.WriteTo(Context);
					Context.Write("})");
				}
				Context.WriteLine(");");  // Foreach
			});
			Context.WriteLine("});"); // Context.NewScope
		}
        override public ParserNode Optimize(ParserNodeContext Context)
        {
            var LeftNodeOptimized  = LeftNode.Optimize(Context);
            var RightNodeOptimized = RightNode.Optimize(Context);

            if ((LeftNodeOptimized is ParserNodeNumericLiteral) && (RightNodeOptimized is ParserNodeNumericLiteral))
            {
                var LeftNodeLiteral  = (ParserNodeNumericLiteral)LeftNodeOptimized;
                var RightNodeLiteral = (ParserNodeNumericLiteral)RightNodeOptimized;
                switch (Operator)
                {
                case "+": return(new ParserNodeNumericLiteral()
                    {
                        Value = LeftNodeLiteral.Value + RightNodeLiteral.Value,
                    });

                case "-": return(new ParserNodeNumericLiteral()
                    {
                        Value = LeftNodeLiteral.Value - RightNodeLiteral.Value,
                    });

                case "*": return(new ParserNodeNumericLiteral()
                    {
                        Value = LeftNodeLiteral.Value * RightNodeLiteral.Value,
                    });

                case "/": return(new ParserNodeNumericLiteral()
                    {
                        Value = LeftNodeLiteral.Value / RightNodeLiteral.Value,
                    });
                }
            }
            return(this);
        }
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("SetAndRenderParentTemplate(");
     Parent.WriteTo(Context);
     Context.Write(", Context);");
     Context.WriteLine("");
 }
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write(Context._GetContextWriteAutoFilteredMethod() + "(");
			Parent.WriteTo(Context);
			Context.Write(");");
			Context.WriteLine("");
		}
Example #11
0
 public override void WriteTo(ParserNodeContext Context)
 {
     foreach (var Node in Nodes)
     {
         Node.WriteTo(Context);
     }
 }
		public override void WriteTo(ParserNodeContext Context)
		{
			Context.Write("Autoescape(Context, ");
			AutoescapeExpression.WriteTo(Context);
			Context.WriteLine(", new EmptyDelegate(async delegate() {");
			Body.WriteTo(Context);
			Context.WriteLine("}));");
		}
Example #13
0
		override public void WriteTo(ParserNodeContext Context)
		{
			//Context.Write("await " + ((Func<string, TemplateContext, Task>)TemplateCode.Methods.SetAndRenderParentTemplateAsync).Method.Name + "(");
			Context.Write("await SetAndRenderParentTemplateAsync(");
			Parent.WriteTo(Context);
			Context.Write(", Context);");
			Context.WriteLine("");
		}
Example #14
0
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write("DynamicUtils.Access(");
			Parent.WriteTo(Context);
			Context.Write(",");
			Key.WriteTo(Context);
			Context.Write(")");
		}
Example #15
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("DynamicUtils.Access(");
     Parent.WriteTo(Context);
     Context.Write(",");
     Key.WriteTo(Context);
     Context.Write(")");
 }
Example #16
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("Autoescape(Context, ");
     AutoescapeExpression.WriteTo(Context);
     Context.WriteLine(", new EmptyDelegate(delegate() {");
     Body.WriteTo(Context);
     Context.WriteLine("}));");
 }
 override public void WriteTo(ParserNodeContext Context)
 {
     Context.Write("DynamicUtils.BinaryOperation_" + DynamicUtils.GetOpName(Operator) + "(");
     LeftNode.WriteTo(Context);
     Context.Write(",");
     RightNode.WriteTo(Context);
     Context.Write(")");
 }
		public override void WriteTo(ParserNodeContext Context)
		{
			Context.Write("DynamicUtils.BinaryOperation_" + DynamicUtils.GetOpName(Operator) + "(");
			LeftNode.WriteTo(Context);
			Context.Write(",");
			RightNode.WriteTo(Context);
			Context.Write(")");
		}
		override public ParserNode Optimize(ParserNodeContext Context)
		{
			ParserNodeContainer OptimizedNode = CreateThisInstanceAs<ParserNodeContainer>();
			foreach (var Node in Nodes)
			{
				OptimizedNode.Add(Node.Optimize(Context));
			}
			return OptimizedNode;
		}
Example #20
0
		public override void WriteTo(ParserNodeContext Context)
		{
			Context.Write("Context.CallFilter({0}", StringUtils.EscapeString(FilterName));
			foreach (var Param in Params)
			{
				Context.Write(", ");
				Param.WriteTo(Context);
			}
			Context.Write(")");
		}
Example #21
0
		override public void WriteTo(ParserNodeContext Context)
		{
			switch (Name)
			{
				case "true": Context.Write("true"); break;
				case "false": Context.Write("false"); break;
				case "none": Context.Write("null"); break;
				default: throw (new Exception(String.Format("Unknown constant '{0}'", Name)));
			}
		}
Example #22
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("Context.CallFilter({0}", StringUtils.EscapeString(FilterName));
     foreach (var Param in Params)
     {
         Context.Write(", ");
         Param.WriteTo(Context);
     }
     Context.Write(")");
 }
Example #23
0
        public override ParserNode Optimize(ParserNodeContext Context)
        {
            ParserNodeContainer OptimizedNode = CreateThisInstanceAs <ParserNodeContainer>();

            foreach (var Node in Nodes)
            {
                OptimizedNode.Add(Node.Optimize(Context));
            }
            return(OptimizedNode);
        }
Example #24
0
        public override void WriteTo(ParserNodeContext Context)
        {
            switch (Name)
            {
            case "true": Context.Write("true"); break;

            case "false": Context.Write("false"); break;

            case "none": Context.Write("null"); break;

            default: throw(new Exception(String.Format("Unknown constant '{0}'", Name)));
            }
        }
Example #25
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("if (DynamicUtils.ConvertToBool(");
     ConditionNode.WriteTo(Context);
     Context.Write(")) {");
     Context.WriteLine("");
     BodyIfNode.WriteTo(Context);
     Context.Write("}");
     if (!(BodyElseNode is DummyParserNode))
     {
         Context.Write(" else {");
         BodyElseNode.WriteTo(Context);
         Context.Write("}");
     }
     Context.WriteLine("");
 }
Example #26
0
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write("if (DynamicUtils.ConvertToBool(");
			ConditionNode.WriteTo(Context);
			Context.Write(")) {");
			Context.WriteLine("");
			BodyIfNode.WriteTo(Context);
			Context.Write("}");
			if (!(BodyElseNode is DummyParserNode))
			{
				Context.Write(" else {");
				BodyElseNode.WriteTo(Context);
				Context.Write("}");
			}
			Context.WriteLine("");
		}
		public override ParserNode Optimize(ParserNodeContext Context)
		{
			var LeftNodeOptimized = LeftNode.Optimize(Context);
			var RightNodeOptimized = RightNode.Optimize(Context);

			if ((LeftNodeOptimized is ParserNodeNumericLiteral) && (RightNodeOptimized is ParserNodeNumericLiteral))
			{
				var LeftNodeLiteral = (ParserNodeNumericLiteral)LeftNodeOptimized;
				var RightNodeLiteral = (ParserNodeNumericLiteral)RightNodeOptimized;
				switch (Operator)
				{
					case "+": return new ParserNodeNumericLiteral() { Value = LeftNodeLiteral.Value + RightNodeLiteral.Value, };
					case "-": return new ParserNodeNumericLiteral() { Value = LeftNodeLiteral.Value - RightNodeLiteral.Value, };
					case "*": return new ParserNodeNumericLiteral() { Value = LeftNodeLiteral.Value * RightNodeLiteral.Value, };
					case "/": return new ParserNodeNumericLiteral() { Value = LeftNodeLiteral.Value / RightNodeLiteral.Value, };
				}
			}
			return this;
		}
		override public void WriteTo(ParserNodeContext Context)
		{
			switch (Operator)
			{
				case "?":
					Context.Write("DynamicUtils.ConvertToBool(");
					ConditionNode.WriteTo(Context);
					Context.Write(")");
					Context.Write("?");
					Context.Write("(");
					TrueNode.WriteTo(Context);
					Context.Write(")");
					Context.Write(":");
					Context.Write("(");
					FalseNode.WriteTo(Context);
					Context.Write(")");
					break;
				default:
					throw (new Exception(String.Format("Unknown Operator '{0}'", Operator)));
			}
		}
Example #29
0
        public override void WriteTo(ParserNodeContext Context)
        {
            switch (Operator)
            {
            case "?":
                Context.Write("DynamicUtils.ConvertToBool(");
                ConditionNode.WriteTo(Context);
                Context.Write(")");
                Context.Write("?");
                Context.Write("(");
                TrueNode.WriteTo(Context);
                Context.Write(")");
                Context.Write(":");
                Context.Write("(");
                FalseNode.WriteTo(Context);
                Context.Write(")");
                break;

            default:
                throw (new Exception(String.Format("Unknown Operator '{0}'", Operator)));
            }
        }
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write("{0}(", Operator);
			Parent.WriteTo(Context);
			Context.Write(")");
		}
Example #31
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.WriteLine("CallParentBlock({0}, Context);", StringUtils.EscapeString(BlockName));
 }
Example #32
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("{0}(", Operator);
     Parent.WriteTo(Context);
     Context.Write(")");
 }
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.WriteLine("await CallBlockAsync({0}, Context);", StringUtils.EscapeString(this.BlockName));
			Context.WriteLine("");
		}
Example #34
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("Context.GetVar({0})", StringUtils.EscapeString(Id));
 }
Example #35
0
 public virtual ParserNode Optimize(ParserNodeContext Context)
 {
     return(this);
 }
Example #36
0
 override public void WriteTo(ParserNodeContext Context)
 {
     //Context.Write("Context.Output.Write(Context.AutoFilter({0}));", StringUtils.EscapeString(Text));
     Context.Write("Context.Output.Write({0});", StringUtils.EscapeString(Text));
     Context.WriteLine("");
 }
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write("Context.GetVar({0})", StringUtils.EscapeString(Id));
		}
Example #38
0
 public override void GenerateIL(ILGenerator ILGenerator, ParserNodeContext Context)
 {
     ILGenerator.Emit(OpCodes.Ldstr, Value);
 }
Example #39
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write(StringUtils.EscapeString(Value));
 }
Example #40
0
 public virtual void WriteTo(ParserNodeContext Context)
 {
 }
Example #41
0
 public override void WriteTo(ParserNodeContext Context)
 {
     Context.Write("{0}", Value);
 }
Example #42
0
		override public void GenerateIL(ILGenerator ILGenerator, ParserNodeContext Context)
		{
			ILGenerator.Emit(OpCodes.Ldstr, Value);
		}
Example #43
0
 internal void OptimizeAndWrite(ParserNodeContext Context)
 {
     Optimize(Context).WriteTo(Context);
 }
Example #44
0
		override public void WriteTo(ParserNodeContext Context)
		{
			//Context.Write("Context.Output.Write(Context.AutoFilter({0}));", StringUtils.EscapeString(Text));
			Context.Write("{0}({1});", Context._GetContextWriteMethod(), StringUtils.EscapeString(Text));
			Context.WriteLine("");
		}
Example #45
0
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write("{0}", Value);
		}
Example #46
0
 public virtual void GenerateIL(ILGenerator ILGenerator, ParserNodeContext Context)
 {
     throw(new NotImplementedException());
 }
Example #47
0
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.Write(StringUtils.EscapeString(Value));
		}
Example #48
0
 public override void WriteTo(ParserNodeContext Context)
 {
     //Context.Write("Context.Output.Write(Context.AutoFilter({0}));", StringUtils.EscapeString(Text));
     Context.Write("{0}({1});", Context._GetContextWriteMethod(), StringUtils.EscapeString(Text));
     Context.WriteLine("");
 }
Example #49
0
		override public ParserNode Optimize(ParserNodeContext Context)
		{
			var That = CreateThisInstanceAs<ParserNodeParent>();
			That.Parent = Parent.Optimize(Context);
			return That;
		}
Example #50
0
 override public void WriteTo(ParserNodeContext Context)
 {
     Context.WriteLine("CallBlock({0}, Context);", StringUtils.EscapeString(this.BlockName));
     Context.WriteLine("");
 }
		override public void WriteTo(ParserNodeContext Context)
		{
			Context.WriteLine("CallParentBlock({0}, Context);", StringUtils.EscapeString(BlockName));
		}