Beispiel #1
0
        public static bool Rewind(this ISource source, string pattern)
        {
            var codes = new LinkedList <int>();

            foreach (var ch in pattern)
            {
                var code = source.Peek();
                if (code == -1 || ch != (char)code)
                {
                    codes.ForEach(x => source.Buffer(x));
                    return(false);
                }
                codes.AddFirst(source.Read());
            }
            return(true);
        }
Beispiel #2
0
        public ClDouble Read(ISource source)
        {
            if (!TryReadAtLeastOneNumber(source, out var significand))
            {
                return(null);
            }
            if (!source.Rewind("."))
            {
                significand.Reverse().ForEach(ch => source.Buffer(ch));
                return(null);
            }
            if (!TryReadAtLeastOneNumber(source, out var mantissa))
            {
                throw new SyntaxError($"Invalid format of the {nameof(ClDouble)} literal");
            }
            var number = double.Parse($"{significand}.{mantissa}", NumberStyles.Float,
                                      CultureInfo.InvariantCulture);

            return(new ClDouble(number));
        }
Beispiel #3
0
        public static bool RewindSpaces(this ISource source)
        {
            bool loop(bool atLeastOne = false)
            {
                if (source.Eof())
                {
                    return(atLeastOne);
                }
                var code = source.Read();

                if (char.IsWhiteSpace((char)code))
                {
                    return(loop(true));
                }
                source.Buffer(code);
                return(atLeastOne);
            }

            return(loop());
        }