コード例 #1
0
ファイル: Template.cs プロジェクト: jordan49/websitepanel
        /// <summary>
        /// Verifies template syntax and throws <see cref="ParserException">ParserException</see> when error is found.
        /// </summary>
        /// <exception cref="ParserException">Thrown when error is found.</exception>
        public void CheckSyntax()
        {
            // create lexer
            lexer = new Lexer(data);

            // create parser
            parser = new Parser(lexer);

            // parse template
            parser.Parse();
        }
コード例 #2
0
ファイル: Template.cs プロジェクト: jordan49/websitepanel
        /// <summary>
        /// Evaluates template to the StringWriter.
        /// </summary>
        /// <param name="writer">StringWriter to write evaluation results.</param>
        public void Evaluate(StringWriter writer)
        {
            if(writer == null)
                throw new ArgumentNullException("writer");

            if (lexer == null)
            {
                // create lexer
                lexer = new Lexer(data);

                // create parser
                parser = new Parser(lexer);

                // parse template
                statements = parser.Parse();
            }

            // index custom templates
            int i = 0;
            while (i < statements.Count)
            {
                TemplateStatement tmpStatement = statements[i] as TemplateStatement;
                if (tmpStatement != null)
                {
                    context.Templates.Add(tmpStatement.Name, tmpStatement);
                    statements.RemoveAt(i);
                    continue;
                }
                i++;
            }

            // evaluate template statements
            foreach (AST.Statement stm in statements)
            {
                // eval next statement
                stm.Eval(context, writer);
            }
        }