Ejemplo n.º 1
0
        internal static object StringToNumber(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return((object)null);
            }
            input = input.Trim();
            if (string.IsNullOrEmpty(input))
            {
                return((object)null);
            }
            string str1 = "";

            if (input[0] == '+' || SpecialCharacters.IsDash(input[0]))
            {
                str1  = input[0].ToString();
                input = input.Substring(1);
            }
            string str2 = NumberTokenReader.ScanForNumber(input, 0);

            if (str2 == null)
            {
                return((object)null);
            }
            if (str2.Length < input.Length)
            {
                throw InterpreterError.NewInterpreterException((object)input, typeof(RuntimeException), (Token)null, "BadNumericConstant", (object)input);
            }
            return(NumberTokenReader.ConvertToNumber(str1 + str2, (Tokenizer)null));
        }
Ejemplo n.º 2
0
        private string Match(string input, int offset, out object tokenData)
        {
            tokenData = (object)null;
            int startIndex = offset;

            if (this.Tokenizer.AllowSignedNumber && offset < input.Length && (input[offset] == '+' || SpecialCharacters.IsDash(input[offset])))
            {
                ++offset;
            }
            string str1 = NumberTokenReader.ScanForNumber(input, offset);

            if (string.IsNullOrEmpty(str1))
            {
                return((string)null);
            }
            offset += str1.Length;
            if (offset < input.Length)
            {
                if (this.Tokenizer.Mode == ParseMode.Command)
                {
                    if ("{}();,|&\r\n\t ".IndexOf(input[offset]) == -1)
                    {
                        return((string)null);
                    }
                }
                else if (char.IsLetterOrDigit(input[offset]))
                {
                    if (this.Tokenizer.Mode == ParseMode.Expression)
                    {
                        this.Tokenizer.Parser.ReportException((object)str1, typeof(ParseException), this.Tokenizer.PositionToken(offset), "BadNumericConstant", (object)str1);
                    }
                    return((string)null);
                }
            }
            try
            {
                string str2 = input.Substring(startIndex, offset - startIndex);
                tokenData = NumberTokenReader.ConvertToNumber(str2, this.Tokenizer);
                return(str2);
            }
            catch (RuntimeException ex)
            {
                if (this.Tokenizer.Mode != ParseMode.Expression)
                {
                    return((string)null);
                }
                if (ex.ErrorRecord != null)
                {
                    ex.ErrorRecord.SetInvocationInfo(new InvocationInfo((CommandInfo)null, this.Tokenizer.PositionToken(offset)));
                }
                throw;
            }
        }