Ejemplo n.º 1
0
        bool TryParseUntil(int index, out MatchCursor <TInput> match)
        {
            if (index >= _count)
            {
                match = default(MatchCursor <TInput>);
                return(false);
            }

            lock (_matches)
            {
                for (int i = _matches.Count; i <= index; i++)
                {
                    Result <TInput, Match> result = _parser.Parse(_input);
                    if (result.HasValue)
                    {
                        _input = result.Next;
                        _matches.Add(new MatchCursor <TInput>(this, index, result.Value));
                        continue;
                    }

                    _count = i;
                    break;
                }
            }

            if (index < _matches.Count)
            {
                match = _matches[index];
                return(true);
            }

            match = default(MatchCursor <TInput>);
            return(false);
        }
Ejemplo n.º 2
0
        public bool TryGet(int index, out MatchCursor <TInput> match)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (index < _matches.Count)
            {
                lock (_matches)
                    match = _matches[index];
                return(true);
            }

            return(TryParseUntil(index, out match));
        }
Ejemplo n.º 3
0
        public bool MoveNext()
        {
            if (_cursor == null)
            {
                return(_input.TryGet(0, out _cursor));
            }

            MatchCursor <TInput> nextCursor;

            if (_cursor.TryGetNext(out nextCursor))
            {
                _cursor = nextCursor;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
 public void Reset()
 {
     _cursor = null;
 }
Ejemplo n.º 5
0
 public bool TryGetNext(out MatchCursor <TInput> cursor)
 {
     return(_input.TryGet(_index + 1, out cursor));
 }