Exemplo n.º 1
0
        private Match <TData, TOffset> CreatePatternMatch(TData input, FstResult <TData, TOffset> match)
        {
            TOffset matchStart, matchEnd;

            _fsa.GetOffsets(EntireMatch, match.Registers, out matchStart, out matchEnd);
            Span <TOffset> matchSpan     = _spanFactory.Create(matchStart, matchEnd);
            var            groupCaptures = new List <GroupCapture <TOffset> >();

            foreach (string groupName in _fsa.GroupNames)
            {
                if (groupName == EntireMatch)
                {
                    continue;
                }

                GroupCapture <TOffset> groupCapture = null;
                TOffset start, end;
                if (_fsa.GetOffsets(groupName, match.Registers, out start, out end))
                {
                    if (_spanFactory.IsValidSpan(start, end) && _spanFactory.IsRange(start, end))
                    {
                        Span <TOffset> span = _spanFactory.Create(start, end);
                        if (matchSpan.Contains(span))
                        {
                            groupCapture = new GroupCapture <TOffset>(groupName, span);
                        }
                    }
                }

                if (groupCapture == null)
                {
                    groupCapture = new GroupCapture <TOffset>(groupName, _spanFactory.Empty);
                }
                groupCaptures.Add(groupCapture);
            }

            return(new Match <TData, TOffset>(this, matchSpan, input, groupCaptures,
                                              string.IsNullOrEmpty(match.ID) ? new string[0] : match.ID.Split('*'), match.VariableBindings, match.NextAnnotation));
        }