Пример #1
0
        private static string GetStringAndClear(PooledList <char> sb)
        {
            var str = sb.AsSpan().ToString();

            sb.Clear();
            return(str);
        }
Пример #2
0
        public ParseState(Func <TToken, SourcePos, SourcePos> posCalculator, ITokenStream <TToken> stream)
        {
            _posCalculator = posCalculator;
            _bookmarks     = new PooledList <Bookmark>();
            _stream        = stream;
            _consumedCount = 0;
            SourcePos      = new SourcePos(1, 1);

            _bufferChunkSize = stream.ChunkSizeHint;
            _buffer          = ArrayPool <TToken> .Shared.Rent(_bufferChunkSize);

            _currentIndex  = 0;
            _bufferedCount = 0;

            _eof               = default;
            _unexpected        = default;
            _errorPos          = default;
            _message           = default;
            _expecteds         = new PooledList <Expected <TToken> >();
            _expectedBookmarks = new PooledList <int>();

            Buffer(0);
        }
Пример #3
0
        /// <summary>
        /// A parser which parses a floating point number without a sign.
        /// The resulting <c>double</c> is not checked for overflow.
        /// </summary>
        /// <returns>A parser which parses a floating point number without a sign.</returns>

        public static Parser <char, double> UnsignedReal()
        => Map(
            (integerPart, _, decimalPart) => integerPart.HasValue ? integerPart.Value + decimalPart : decimalPart,
            UnsignedInt(10).Optional(),
            Char('.'),
            DigitCharDouble().ChainAtLeastOnceL(
                () =>
        {
            var sb = new PooledList <char>();
            sb.Add('.');
            return(sb);
        },
                (sb, c) =>
                { sb.Add(c); return(sb); }
                ).Select(sb =>
        {
            ReadOnlySpan <char> csp = sb.AsSpan();
            double x = 0.0;
            x        = Double.Parse(csp.ToString(), System.Globalization.NumberStyles.Float);
            sb.Clear();
            return(x);
        }
                         )
            );