protected override Completion ExecuteImpl(ExecutionEnvironment enviroment) { if (Test == null) { return(Completion.Exception(Properties.Language.TestNullException, this)); } var t = Test.Execute(enviroment); if (t.ReturnValue is bool) { if ((bool)t.ReturnValue) { if (Consequent == null) { return(Completion.Exception(Properties.Language.NullException, this)); } return(Consequent.Execute(enviroment)); } else { if (Alternate == null) { return(Completion.Exception(Properties.Language.NullException, this)); } return(Alternate.Execute(enviroment)); } } else { return(Completion.Exception(Properties.Language.NotBoolean, Test)); } }
public Completion Execute(ExecutionEnvironment enviroment) { if (Test == null) { return(Completion.Void); } var t = Test.Execute(enviroment); if (t.ReturnValue is bool) { if ((bool)t.ReturnValue) { if (Consequent == null) { return(Completion.Void); } ExecutionEnvironment current = new ExecutionEnvironment(enviroment); return(Consequent.Execute(current)); } else { if (Alternate == null) { return(Completion.Void); } ExecutionEnvironment current = new ExecutionEnvironment(enviroment); return(Alternate.Execute(current)); } } else { return(new Completion("Test return not boolean value", CompletionType.Exception)); } }
public Completion Execute(ExecutionEnvironment enviroment) { if (Test == null) { return(Completion.Exception("Test can not be null", this)); } var t = Test.Execute(enviroment); if (t.ReturnValue is bool) { if ((bool)t.ReturnValue) { if (Consequent == null) { return(Completion.Exception("Consequent can not be null", this)); } return(Consequent.Execute(enviroment)); } else { if (Alternate == null) { return(Completion.Exception("Alternate can not be null", this)); } return(Alternate.Execute(enviroment)); } } else { return(new Completion("Test return not boolean value", CompletionType.Exception, this)); } }
public CodeType Type() { if (Consequent.Type() == Alternative.Type()) { return(Consequent.Type()); } return(null); }
public CodeType Type() { // Consequent or Alternative can equal null on GetExpression failure. if (Consequent != null && Alternative != null && Consequent.Type() == Alternative.Type()) { return(Consequent.Type()); } return(null); }
public override object Evaluate(TemplateScopeContext scope) { var test = Test.EvaluateToBool(scope); var value = test ? Consequent.Evaluate(scope) : Alternate.Evaluate(scope); return(value); }
public override int GetHashCode() { unchecked { var hashCode = (Test != null ? Test.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Consequent != null ? Consequent.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Alternate != null ? Alternate.GetHashCode() : 0); return(hashCode); } }
public override string ToRawString() { var sb = StringBuilderCache.Allocate(); sb.Append(Test.ToRawString()); sb.Append(" ? "); sb.Append(Consequent.ToRawString()); sb.Append(" : "); sb.Append(Alternate.ToRawString()); return(StringBuilderCache.ReturnAndFree(sb)); }
public override void Render(StringBuilder sb, int depth = 0) { string pad = String.Empty.PadLeft(depth, ' '); sb.Append(pad).AppendLine("conditional"); sb.Append(pad).AppendLine("expression"); Condition.Render(sb, depth + 2); sb.Append(pad).AppendLine("consequent"); Consequent.Render(sb, depth + 2); sb.Append(pad).AppendLine("alternate"); Alternate.Render(sb, depth + 2); }
public override Dictionary <string, object> ToJsAst() { var to = new Dictionary <string, object> { ["type"] = ToJsAstType(), ["test"] = Test.ToJsAst(), ["consequent"] = Consequent.ToJsAst(), ["alternate"] = Alternate.ToJsAst(), }; return(to); }
//public FailureLevel ConsequentFailureLevel { get; set; } public RuleCheckResult RunRuleAgainstObject(object dataStructureObject) { RuleCheckResult result = new RuleCheckResult(this); result.Object = dataStructureObject; try { result.AntecedentEvaluatesToTrue = Antecedent.EvaluateAgainstObject(dataStructureObject); } catch (Exception ex) { result.ResultText = "Error evaluating antecedent: " + ex.Message; result.HasError = true; return(result); } try { if (result.AntecedentEvaluatesToTrue.Value) { result.ConsequentEvaluatesToTrue = Consequent.EvaluateAgainstObject(dataStructureObject); } } catch (Exception ex) { result.ResultText = "Error evaluating consequent: " + ex.Message; result.HasError = true; return(result); } if (result.AntecedentEvaluatesToTrue.Value) { if (result.ConsequentEvaluatesToTrue.Value) { result.ResultText = $"PASS: {Consequent.GetSentence()}"; } else { result.ResultText = $"{Enum.GetName(typeof(OutcomeLevelEnum), OutcomeLevel)}: {Consequent.GetSentence()}"; } } else { result.ResultText = $"N/A: {Antecedent.GetSentence()}"; } result.Stopwatch.Stop(); return(result); }
public override IValue Evaluate(Environment env) { IValue predValue = Predicate.Evaluate(env); if (Boolean.IsTrue(predValue)) { return(Consequent.Evaluate(env)); } else if (Alternative == null) { return(Boolean.FalseLiteral); } else { return(Alternative.Evaluate(env)); } }
public TernaryConditionalAction(ParseInfo parseInfo, Scope scope, TernaryExpression ternaryContext) { this.parseInfo = parseInfo; Condition = parseInfo.GetExpression(scope, ternaryContext.Condition); Consequent = parseInfo.GetExpression(scope, ternaryContext.Consequent); Alternative = parseInfo.GetExpression(scope, ternaryContext.Alternative); if (Consequent.Type() != null && Consequent.Type().IsConstant()) { parseInfo.Script.Diagnostics.Error($"Cannot use constant types in a ternary expression.", ternaryContext.Consequent.Range); } if (Alternative.Type() != null && Alternative.Type().IsConstant()) { parseInfo.Script.Diagnostics.Error($"Cannot use constant types in a ternary expression.", ternaryContext.Alternative.Range); } }
public override string ToString() { if (Alternate == null) { return(string.Format( "if({0}){1}", Test.ToString(), Consequent.ToString() )); } return(string.Format( "if({0}){1} else {2}", Test.ToString(), Consequent.ToString(), Alternate.ToString() )); }
public override string ToString() => Condition.ToString() + " ? " + Consequent.ToString() + " : " + Alternative.ToString();
public IWorkshopTree Parse(ActionSet actionSet, bool asElement = true) => Element.TernaryConditional(Condition.Parse(actionSet), Consequent.Parse(actionSet), Alternative.Parse(actionSet));
public void SetConfidenceOfConsequentToZero() { Consequent.ClearDOM(); }