Exemplo n.º 1
0
        /// <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();
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        private static void TestLexer(string data)
        {
            List<Token> tokens = new List<Token>();
            Lexer lex = new Lexer(data);

            while (true)
            {
                Token token = lex.Next();
                tokens.Add(token);

                Debug.WriteLine(String.Format("{0} [{1},{2}]: {3}", token.TokenType, token.Line, token.Column, token.Data));

                if (token.TokenType == TokenType.EOF)
                    break;
            }

            Console.ReadKey();
        }
Exemplo n.º 4
0
		public Parser(Lexer lexer)
		{
			this.lexer = lexer;
			this.statements = new List<Statement>();
		}
Exemplo n.º 5
0
 public Parser(Lexer lexer)
 {
     this.lexer      = lexer;
     this.statements = new List <Statement>();
 }