/// <summary> /// Convert the presense / count of the enumerable expression(list/map) into bool true/false. /// </summary> /// <param name="expr">The list check expression.</param> /// <returns></returns> public object VisitListCheck(ListCheckExpr expr) { var varExp = expr.NameExp.Evaluate(this) as LObject; if (varExp == LObjects.Null) return new LBool(false); var count = 0; // 1. Array type ? check count if (varExp.Type == LTypes.Array) { count = ((LArray)varExp).Value.Count; } // 2 Table Map type else if (varExp.Type == LTypes.Map) { count = ((LMap)varExp).Value.Count; } // 3. Table type else if (varExp.Type == LTypes.Table) { count = ((LTable) varExp).Value.Count; } // 3. Other type : keep count as 0 so we return false; var result = count > 0 ? new LBool(true) : new LBool(false); return result; }
/// <summary> /// Creates an expr that checks if the list variable supplied has any items. /// </summary> /// <param name="varName"></param> /// <param name="token"></param> /// <returns></returns> public static Expr ListCheck(TokenData name, TokenData token) { var exp = new ListCheckExpr(); exp.NameExp = Ident(name.Token.Text, name); SetupContext(exp, token); return exp; }
/// <summary> /// Check the epxr which checks the presense / count of the enumerable expression(list/map) into bool true/false. /// </summary> /// <param name="expr">The list check expression.</param> /// <returns></returns> public object VisitListCheck(ListCheckExpr expr) { return null; }