Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Tag[] ParseTag()
        {
            TemplateLexer  lexer  = new TemplateLexer(this._content);
            TemplateParser parser = new TemplateParser(lexer.Parse());

            return(parser.ToArray());
        }
Example #2
0
 public override void Parse(TemplateContext context, System.IO.TextWriter writer)
 {
     String path = this.Path.Parse(context).ToString();
     if (!String.IsNullOrEmpty(path))
     {
         TemplateLexer lexer = new TemplateLexer(Resources.LoadResource(context.Paths.ToArray(), path, context.Charset));
         TemplateParser parser = new TemplateParser(lexer.Parse(), context.Analyzer);
         while (parser.MoveNext())
         {
             parser.Current.Parse(context, writer);
         }
     }
 }
Example #3
0
        protected void Render(TemplateContext context, TextWriter writer)
        {
            if (context == null)
            {
                writer.Write(this.TemplateContent);
                return;
            }

            if (!String.IsNullOrEmpty(this.TemplateContent))
            {
                TemplateLexer  lexer  = new TemplateLexer(this.TemplateContent);
                TemplateParser parser = new TemplateParser(lexer.Parse());

                while (parser.MoveNext())
                {
                    try
                    {
                        parser.Current.Parse(context, writer);
                    }
                    catch (Exception.TemplateException e)
                    {
                        if (context.ThrowExceptions)
                        {
                            throw e;
                        }
                        else
                        {
                            context.AddError(e);
                            writer.Write(parser.Current.ToString());
                        }
                    }
                    catch (System.Exception e)
                    {
                        System.Exception baseException = e.GetBaseException();

                        Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException);
                        if (context.ThrowExceptions)
                        {
                            throw ex;
                        }
                        else
                        {
                            context.AddError(ex);
                            writer.Write(parser.Current.ToString());
                        }
                    }
                }
            }
        }
Example #4
0
        protected void Render(TemplateContext context, StringBuilder writer)
        {
            if (!String.IsNullOrEmpty(this.TemplateContent))
            {
                TemplateLexer lexer = new TemplateLexer(this.TemplateContent);
                TemplateParser parser = new TemplateParser(lexer.Parse());

                while (parser.MoveNext())
                {
                    //try
                    //{
                        parser.Current.Parse(context, writer);
                    //}
                    //catch (Exception.TemplateException e)
                    //{
                    //    if (context.ThrowExceptions)
                    //    {
                    //        throw e;
                    //    }
                    //    else
                    //    {
                    //        context.AddError(e);
                    //        writer.Append(parser.Current.ToString());
                    //    }
                    //}
                    //catch (System.Exception e)
                    //{
                    //    System.Exception baseException = e.GetBaseException();

                    //    Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException);
                    //    if (context.ThrowExceptions)
                    //    {
                    //        throw ex;
                    //    }
                    //    else
                    //    {
                    //        context.AddError(ex);
                    //        writer.Append(parser.Current.ToString());
                    //    }
                    //}
                }

            }
        }
Example #5
0
 protected void Eval(TemplateContext context)
 {
     if (context != null)
     {
         if (!string.IsNullOrEmpty(this.TemplateContent))
         {
             TemplateLexer  lexer  = new TemplateLexer(this.TemplateContent);
             TemplateParser parser = new TemplateParser(context, lexer.Parse());
             while (parser.MoveNext())
             {
                 try
                 {
                     parser.Current.Parse(context);
                 }
                 catch (TemplateException e)
                 {
                     if (context.ThrowExceptions)
                     {
                         throw e;
                     }
                     else
                     {
                         context.AddError(e);
                     }
                 }
                 catch (Exception e)
                 {
                     Exception      baseException = e.GetBaseException();
                     ParseException ex            = new ParseException(baseException.Message, baseException);
                     if (context.ThrowExceptions)
                     {
                         throw ex;
                     }
                     else
                     {
                         context.AddError(ex);
                     }
                 }
             }
         }
     }
 }
Example #6
0
        /// <summary>
        /// 呈现标签
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="writer">writer</param>
        protected void Render(TemplateContext context, TextWriter writer)
        {
            //缓存功能,待添加
            if (context == null)
            {
                writer.Write(this.TemplateContent);
                return;
            }
            Tag[] collection;

            if (!String.IsNullOrEmpty(this.TemplateContent))
            {
                TemplateLexer lexer = new TemplateLexer(this.TemplateContent, context.Config.TagFlag, context.Config.TagPrefix, context.Config.TagSuffix);

                TemplateParser parser = new TemplateParser(lexer.Parse(), context.Config.Resolver);

                collection = parser.ToArray();
            }
            else
            {
                collection = new Tag[0];
            }

            if (collection.Length > 0)
            {
                for (Int32 i = 0; i < collection.Length; i++)
                {
                    try
                    {
                        collection[i].Parse(context, writer);
                    }
                    catch (Exception.TemplateException e)
                    {
                        if (context.ThrowExceptions)
                        {
                            throw e;
                        }
                        else
                        {
                            context.AddError(e);
                            writer.Write(collection[i].ToString());
                        }
                    }
                    catch (System.Exception e)
                    {
                        System.Exception baseException = e.GetBaseException();

                        Exception.ParseException ex = new Exception.ParseException(baseException.Message, baseException);
                        if (context.ThrowExceptions)
                        {
                            throw ex;
                        }
                        else
                        {
                            context.AddError(ex);
                            writer.Write(collection[i].ToString());
                        }
                    }
                }
            }
        }