public IParseTreeValue CreateDeclaredType(string expression, string declaredTypeName) { if (expression is null || declaredTypeName is null) { throw new ArgumentNullException(); } if (ParseTreeValue.TryGetNonPrintingControlCharCompareToken(expression, out string comparableToken)) { var charConversion = new TypeTokenPair(Tokens.String, comparableToken); return(ParseTreeValue.CreateValueType(charConversion)); } var goalTypeTokenPair = new TypeTokenPair(declaredTypeName, null); var typeToken = TypeTokenPair.ConformToType(declaredTypeName, expression); if (typeToken.HasValue) { if (LetCoerce.ExceedsValueTypeRange(typeToken.ValueType, typeToken.Token)) { return(ParseTreeValue.CreateOverflowExpression(expression, declaredTypeName)); } return(ParseTreeValue.CreateValueType(typeToken)); } return(ParseTreeValue.CreateExpression(new TypeTokenPair(declaredTypeName, expression))); }
public IParseTreeValue CreateDeclaredType(string expression, string declaredTypeName) { if (expression is null || declaredTypeName is null) { throw new ArgumentNullException(); } var goalTypeTokenPair = new TypeTokenPair(declaredTypeName, null); var typeToken = TypeTokenPair.ConformToType(declaredTypeName, expression); if (typeToken.HasValue) { if (LetCoerce.ExceedsValueTypeRange(typeToken.ValueType, typeToken.Token)) { return(ParseTreeValue.CreateOverflowExpression(expression, declaredTypeName)); } return(ParseTreeValue.CreateValueType(typeToken)); } return(ParseTreeValue.CreateExpression(new TypeTokenPair(declaredTypeName, expression))); }
public IParseTreeValue Create(string valueToken) { if (valueToken is null || valueToken.Equals(string.Empty)) { throw new ArgumentException(); } if (HasTypeHint(valueToken, out string valueType)) { var vToken = valueToken.Remove(valueToken.Length - 1); var conformedTypeTokenPair = TypeTokenPair.ConformToType(valueType, vToken); if (conformedTypeTokenPair.HasValue) { return(ParseTreeValue.CreateValueType(conformedTypeTokenPair)); } return(ParseTreeValue.CreateExpression(new TypeTokenPair(valueType, vToken))); } if (TypeTokenPair.TryParse(valueToken, out TypeTokenPair result)) { return(ParseTreeValue.CreateValueType(result)); } return(ParseTreeValue.CreateExpression(new TypeTokenPair(null, valueToken))); }