private void ProcessElement(Token elem) { if (elem is Text) { Text text = (Text) elem; WriteValue(text.Data); } else if (elem is Expression) { ProcessExpression((Expression) elem); } else if (elem is IfStatement) { ProcessIf((IfStatement) elem); } else if (elem is Tag) { ProcessTag((Tag) elem); } }
private Token Consume() { Token old = current; current = lexer.Next(); return old; }
private Token Consume(TokenKind kind) { Token old = current; current = lexer.Next(); if (old.TokenKind != kind) { throw new TmplException("Unexpected token: " + current.TokenKind.ToString() + ". Was expecting: " + kind + " " + current.Line + "," + current.Col, current.Line, current.Col); } return old; }
///====================================================================== private void visitElement(Token elem) { if (elem is Expression) visitExpression((Expression) elem); else if (elem is Text) visitText((Text) elem); else if (elem is IfStatement) visitTagIf((IfStatement) elem); else if (elem is Tag) visitTag((Tag) elem); else if (elem is StatementClose) visitTagClose((StatementClose) elem); else WriteLine("Unknown Token: " + elem.GetType().ToString()); }