예제 #1
0
        public static ILiteralToken MakeLiteralToken(this string tokenString, IConfiguration configuration = null)
        {
            if (string.IsNullOrWhiteSpace(tokenString))
            {
                return(null);
            }

            var firstSpace = tokenString.IndexOf(' ');
            var tokenType  = firstSpace <= 0
                ? tokenString
                : tokenString.Substring(0, firstSpace).Trim();
            var tokenArg = firstSpace <= 0
                ? ""
                : tokenString.Substring(firstSpace).Trim();

            switch (tokenType.ToLower())
            {
            case "date":
            case "datetoken":
                return(DateToken.Parse(tokenArg, false, SourcePosition.None, configuration));

            case "float":
            case "floattoken":
                return(FloatToken.Parse(tokenArg, configuration));

            case "limitedinteger":
            case "limitedintegertoken":
            {
                var portions = _limitedIntegerRegex.Match(tokenArg);
                var isNeg    = portions.Groups[1].Value == "-";
                var numBase  = IntegerBase.Decimal;
                switch (portions.Groups[2].Value.ToLower())
                {
                case "0x": numBase = IntegerBase.Hexadecimal; break;

                case "b": numBase = IntegerBase.Decimal; break;

                case "o": numBase = IntegerBase.Decimal; break;

                case "": numBase = IntegerBase.Decimal; break;

                default: throw new ArgumentOutOfRangeException($"Unhandled numeric base indicator '{portions.Groups[2].Value}'");
                }
                var num      = portions.Groups[3].Value;
                var isSigned = portions.Groups[4].Value.ToLower() != "u";
                var bitWidth = LimitedIntegerToken.ParseBitWidth(portions.Groups[5].Value);
                return(LimitedIntegerToken.Parse(num, numBase, bitWidth, isSigned, isNeg, tokenArg, SourcePosition.None, configuration ?? new Configuration()
                    {
                        IgnoreLimitedIntegerMaxMinRange = true
                    }));
            }

            case "unlimitedinteger":
            case "unlimitedintegertoken":
            {
                var portions = _unlimitedIntegerRegex.Match(tokenArg);
                var isNeg    = portions.Groups[1].Value == "-";
                var numBase  = IntegerBase.Decimal;
                switch (portions.Groups[2].Value.ToLower())
                {
                case "0x": numBase = IntegerBase.Hexadecimal; break;

                case "b": numBase = IntegerBase.Decimal; break;

                case "o": numBase = IntegerBase.Decimal; break;

                case "": numBase = IntegerBase.Decimal; break;

                default: throw new ArgumentOutOfRangeException($"Unhandled numeric base indicator '{portions.Groups[2].Value}'");
                }
                var num = portions.Groups[3].Value;
                return(UnlimitedIntegerToken.Parse(num, numBase, isNeg, SourcePosition.None, configuration));
            }

            case "timespan":
            case "timespantoken":
                return(TimespanToken.Parse(TimeToken.Parse(tokenArg, SourcePosition.None, configuration).TypedValue, tokenArg, SourcePosition.None, configuration));

            case "time":
            case "timetoken":
                return(TimeToken.Parse(tokenArg, SourcePosition.None, configuration));

            default:
                throw new TestOperationException($"Unrecognised token type {tokenType}");
            }
        }
 public static UnlimitedIntegerTokenAssertions Should(this UnlimitedIntegerToken token) => new UnlimitedIntegerTokenAssertions(token);