/// <summary> /// set a boolean value, in a language. /// exp: true -> "true" in english or "true -> "vrai" in french. /// /// </summary> /// <param name="boolValue"></param> /// <param name="constStringValue"></param> public void SetBoolConstValue(bool boolValue, string constStringValue) { BoolConst boolConst = new BoolConst(); boolConst.BoolValue = boolValue; boolConst.BoolStringValue = constStringValue; ListBoolConst.Add(boolConst); }
/// <summary> /// Build the final operand: not a separator. /// can be a number (positive or negative), an object name (var, fct,...) or a string. /// /// The string can be well-formed or bad-formed: the end tag is missing. /// </summary> /// <param name="token"></param> /// <returns></returns> private ExprFinalOperand BuildOperand(ExprToken token, ParseResult result) { ExprFinalOperand exprFinalOperand = new ExprFinalOperand(); exprFinalOperand.Operand = token.Value; exprFinalOperand.Token = token; //----is the value a string? starts with a string tag (quote or double-quote) if (_exprEvalConfig.StringTagValue == token.Value[0].ToString()) { // is the last char a string tag? //if (_exprEvalConfig.ListStringTag.Contains(token.Value[token.Value.Length-1]) && token.Value.Length>1) if (_exprEvalConfig.StringTagValue == token.Value[token.Value.Length - 1].ToString() && token.Value.Length > 1) { exprFinalOperand.ContentType = OperandType.ValueString; return(exprFinalOperand); } exprFinalOperand.ContentType = OperandType.ValueStringBadFormed; ExprError error = new ExprError(); error.Token = token; error.Code = ErrorCode.ValueStringBadFormed; result.ListError.Add(error); return(exprFinalOperand); } //----is the value an integer? int numberInt; if (int.TryParse(token.Value, out numberInt)) { exprFinalOperand.ContentType = OperandType.ValueInt; exprFinalOperand.ValueInt = numberInt; return(exprFinalOperand); } //----is the value a double? if (IsOperandDouble(token, result, exprFinalOperand)) { return(exprFinalOperand); } // is it a bad-formed number? (seems to be number: start with minus or a digit) if (token.Value[0] == '-' || char.IsDigit(token.Value[0])) { exprFinalOperand.ContentType = OperandType.ValueNumberBadFormed; ExprError error = new ExprError(); error.Token = token; error.Code = ErrorCode.ValueNumberBadFormed; result.ListError.Add(error); return(exprFinalOperand); } //-----is it a bool value? // todo: get values from the configurator: true/false, vrai/faux BoolConst boolConst = _exprEvalConfig.ListBoolConst.Find(bc => bc.BoolStringValue.Equals(token.Value, StringComparison.InvariantCultureIgnoreCase)); if (boolConst != null) { exprFinalOperand.ContentType = OperandType.ValueBool; exprFinalOperand.ValueBool = boolConst.BoolValue; return(exprFinalOperand); } // it's an object name, (sure?) check the syntax CheckObjectNameSyntax(token, result, exprFinalOperand); return(exprFinalOperand); }