public override Verb CreateVerb(string[] tokens) { Color(position, length, Operators); if (GetExpression(source, NextPosition, FuncThen()) is Some <(Block, int)> e1) { (var condition, var i) = e1.Value; if (GetExpression(source, i, FuncThen()) is Some <(Block, int)> e2) { (var thenExpression, var j) = e2.Value; if (GetExpression(source, j, FuncEnd()) is Some <(Block, int)> e3) { (var elseExpression, var k) = e3.Value; overridePosition = k; var _if = new If(condition, thenExpression) { ElseBlock = elseExpression }; return(new IfExecute(_if, VerbPresidenceType.Push)); } } } return(null); }
static (Verb, int) enclose(bool forward, Block condition, Block block, string source, int index) { var newCondition = forward ? condition : CodeBuilder.Not(condition); var elseParser = new ElseParser(); var _if = new If(newCondition, block); var overriding = index; if (elseParser.Scan(source, index)) { _if.ElseBlock = elseParser.Block; overriding = elseParser.Position; } var ifExecute = new IfExecute(_if); return(ifExecute, overriding); }
public void If(Block condition, Block result, params Block[] elses) { var _if = new If(condition, result); if (elses.Length > 0) { _if.ElseBlock = elses[0]; var current = _if; for (var i = 1; i < elses.Length; i += 2) { var elseCondition = elses[i]; var elseResult = elses[i + 1]; var elseIf = new If(elseCondition, elseResult); current.Next = elseIf; current = elseIf; } } Value(_if); Invoke(); End(); }