public override AstVisitAction VisitIfStatement(IfStatementAst ifStatementAst) { //// 8.3 The if statement //// The pipeline controlling expressions must have type bool or be implicitly convertible to that //// type. The else-clause is optional. There may be zero or more elseif-clauses. //// //// If the top-level pipeline tests True, then its statement-block is executed and execution of //// the statement terminates. Otherwise, if an elseif-clause is present, if its pipeline tests //// True, then its statement-block is executed and execution of the statement terminates. //// Otherwise, if an else-clause is present, its statement-block is executed. foreach (var clause in ifStatementAst.Clauses) { var condition = EvaluateAst(clause.Item1); if (condition == null) { continue; } if (condition.GetType() == typeof(bool)) { if ((bool)condition) { this._pipelineCommandRuntime.WriteObject(EvaluateAst(clause.Item2)); return(AstVisitAction.SkipChildren); } } else { throw new NotImplementedException(ifStatementAst.ToString()); } } if (ifStatementAst.ElseClause != null) { // iterating over a statement list should be its own method. foreach (var statement in ifStatementAst.ElseClause.Statements) { this._pipelineCommandRuntime.WriteObject(EvaluateAst(statement)); } } return(AstVisitAction.SkipChildren); }
public override AstVisitAction VisitIfStatement(IfStatementAst ifStmtAst) { Console.WriteLine("Visited an IfStatementAst."); Console.WriteLine(" " + ifStmtAst.ToString().Replace(Environment.NewLine, Environment.NewLine + " ")); return(AstVisitAction.Continue); }