コード例 #1
0
        private static NespNumericExpression ParseNumeric(
            string text, NespSourceInformation token)
        {
            if (byte.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var byteValue))
            {
                return(new NespNumericExpression(byteValue, token));
            }
            if (short.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var shortValue))
            {
                return(new NespNumericExpression(shortValue, token));
            }
            if (int.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var intValue))
            {
                return(new NespNumericExpression(intValue, token));
            }
            if (long.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var longValue))
            {
                return(new NespNumericExpression(longValue, token));
            }
            if (double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue))
            {
                return(new NespNumericExpression(doubleValue, token));
            }
            if (decimal.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var decimalValue))
            {
                return(new NespNumericExpression(decimalValue, token));
            }

            return(null);
        }
コード例 #2
0
        private static NespNumericExpression ParseHexadecimalNumeric(
            string text, NespSourceInformation token)
        {
            if (text.StartsWith("0x") == false)
            {
                return(null);
            }

            var numericText = text.Substring(2);

            if (numericText.EndsWith("ul"))
            {
                numericText = numericText.Substring(0, numericText.Length - 2);
                if (ulong.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var ulongValue))
                {
                    return(new NespNumericExpression(ulongValue, token));
                }
            }
            else if (numericText.EndsWith("l"))
            {
                numericText = numericText.Substring(0, numericText.Length - 1);
                if (long.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var longValue))
                {
                    return(new NespNumericExpression(longValue, token));
                }
            }
            else if (numericText.EndsWith("u"))
            {
                numericText = numericText.Substring(0, numericText.Length - 1);
                if (uint.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var uintValue))
                {
                    return(new NespNumericExpression(uintValue, token));
                }
            }
            else
            {
                if (byte.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var byteValue))
                {
                    return(new NespNumericExpression(byteValue, token));
                }
                if (short.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var shortValue))
                {
                    return(new NespNumericExpression(shortValue, token));
                }
                if (int.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var intValue))
                {
                    return(new NespNumericExpression(intValue, token));
                }
                if (long.TryParse(numericText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var longValue))
                {
                    return(new NespNumericExpression(longValue, token));
                }
            }

            return(null);
        }
コード例 #3
0
        private static NespNumericExpression ParseStrictNumeric(
            string text, NespSourceInformation token)
        {
            if (text.EndsWith("ul"))
            {
                var numericText = text.Substring(0, text.Length - 2);
                if (ulong.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var ulongValue))
                {
                    return(new NespNumericExpression(ulongValue, token));
                }
            }
            else if (text.EndsWith("l"))
            {
                var numericText = text.Substring(0, text.Length - 1);
                if (long.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var longValue))
                {
                    return(new NespNumericExpression(longValue, token));
                }
            }
            else if (text.EndsWith("u"))
            {
                var numericText = text.Substring(0, text.Length - 1);
                if (uint.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var uintValue))
                {
                    return(new NespNumericExpression(uintValue, token));
                }
            }
            else if (text.EndsWith("f"))
            {
                var numericText = text.Substring(0, text.Length - 1);
                if (float.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var floatValue))
                {
                    return(new NespNumericExpression(floatValue, token));
                }
            }
            else if (text.EndsWith("d"))
            {
                var numericText = text.Substring(0, text.Length - 1);
                if (double.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue))
                {
                    return(new NespNumericExpression(doubleValue, token));
                }
            }
            else if (text.EndsWith("m"))
            {
                var numericText = text.Substring(0, text.Length - 1);
                if (decimal.TryParse(numericText, NumberStyles.Any, CultureInfo.InvariantCulture, out var decimalValue))
                {
                    return(new NespNumericExpression(decimalValue, token));
                }
            }

            return(null);
        }
コード例 #4
0
 internal NespResolvedExpression(NespSourceInformation source)
     : base(source)
 {
 }