public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); return(ValueBoolean.From(!a.IsEquals(b))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var a = args.Get("a"); var b = args.Get("b"); return(ValueBoolean.From(a.CompareTo(b) < 0)); }
public Value Evaluate(Environment environment) { var value = expression.Evaluate(environment); var container = list.Evaluate(environment); if (container.IsList()) { var items = container.AsList().GetValue(); foreach (var item in items) { if (value.IsEquals(item)) { return(ValueBoolean.TRUE); } } } else if (container.IsSet()) { return(ValueBoolean.From(container.AsSet().GetValue().Contains(value))); } else if (container.IsMap()) { return(ValueBoolean.From(container.AsMap().GetValue().ContainsKey(value))); } else if (container.IsObject()) { return(ValueBoolean.From(container.AsObject().value.ContainsKey(value.AsString().GetValue()))); } else if (container.IsString()) { return(ValueBoolean.From(container.AsString().GetValue().Contains(value.AsString().GetValue()))); } return(ValueBoolean.FALSE); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueBoolean.FALSE); } return(ValueBoolean.From(args.GetString("str").GetValue().Contains(args.GetString("part").GetValue()))); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { if (args.IsNull("str")) { return(ValueBoolean.FALSE); } return(ValueBoolean.From(args.GetString("str").Matches(args.GetAsPattern("pattern")))); }
public override ValueBoolean AsBoolean() { if (value == "1") { return(ValueBoolean.TRUE); } if (value == "0") { return(ValueBoolean.FALSE); } return(ValueBoolean.From(bool.Parse(value))); }
public Value Evaluate(Environment environment) { var firstValue = firstExpr.Evaluate(environment); var secondValue = secondExpr.Evaluate(environment); if (!firstValue.IsBoolean()) { throw new ControlErrorException(new ValueString("ERROR"), "Expected boolean but got " + firstValue.Type(), pos); } if (!secondValue.IsBoolean()) { throw new ControlErrorException(new ValueString("ERROR"), "Expected boolean but got " + secondValue.Type(), pos); } return(ValueBoolean.From(firstValue.AsBoolean().GetValue() ^ secondValue.AsBoolean().GetValue())); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var obj = args.Get("obj"); if (obj.IsNull()) { return(ValueBoolean.FALSE); } if (obj.IsNumerical()) { return(ValueBoolean.TRUE); } if (obj.IsString()) { return(ValueBoolean.From(obj.AsString().GetValue().Length > 0)); } if (obj.IsList()) { return(ValueBoolean.From(obj.AsList().GetValue().Count != 0)); } if (obj.IsSet()) { return(ValueBoolean.From(obj.AsSet().GetValue().Count != 0)); } if (obj.IsMap()) { return(ValueBoolean.From(obj.AsMap().GetValue().Count != 0)); } if (obj.IsObject()) { return(ValueBoolean.From(obj.AsObject().value.Count != 0)); } return(ValueBoolean.TRUE); }
public override Value Execute(Args args, Environment environment, SourcePos pos) { return(ValueBoolean.From(!args.Get("obj").IsNull())); }
public override ValueBoolean AsBoolean() { return(ValueBoolean.From(value != 0)); }
private static Value Parse(Lexer lexer) { try { var token = lexer.NextToken(); if (token == "[") { var result = new ValueList(); var next = lexer.NextToken(); while (next != "]") { lexer.PutBackToken(next); result.AddItem(Parse(lexer)); next = lexer.NextToken(); if (next != "]") { lexer.PutBackToken(next); lexer.MatchToken(","); next = lexer.NextToken(); } } return(result); } if (token == "{") { var result = new ValueMap(); var next = lexer.NextToken(); while (next != "}") { lexer.PutBackToken(next); var key = lexer.NextToken(); if (!key.StartsWith("\"")) { throw new Exception("Expected object key, but got " + key); } key = key.Substring(1, key.Length - 2); lexer.MatchToken(":"); result.AddItem(new ValueString(key), Parse(lexer)); next = lexer.NextToken(); if (next != "}") { lexer.PutBackToken(next); lexer.MatchToken(","); next = lexer.NextToken(); } } return(result); } if (token.StartsWith("\"")) { return(new ValueString(token.Substring(1, token.Length - 2))); } if (token == "true" || token == "false") { return(ValueBoolean.From(bool.Parse(token))); } if (token == "null") { return(ValueNull.NULL); } if (token.IndexOf('.') == -1) { return(new ValueInt(long.Parse(token))); } return(new ValueDecimal(decimal.Parse(token))); } catch (Exception) { return(null); } }
public override Value Execute(Args args, Environment environment, SourcePos pos) { var filename = args.GetString("filename").GetValue(); return(ValueBoolean.From(File.Exists(filename) || Directory.Exists(filename))); }