Esempio n. 1
0
        public bool MoveNext()
        {
            if (_currentIndex < 0)
            {
                while (_innerParser.MoveNext())
                {
                    _allEvents.Add(_innerParser.Current);
                }

                for (int i = _allEvents.Count - 2; i >= 0; --i)
                {
                    var merge = _allEvents[i] as Scalar;
                    if (merge != null && merge.Value == "<<")
                    {
                        var anchorAlias = _allEvents[i + 1] as AnchorAlias;
                        if (anchorAlias != null)
                        {
                            var mergedEvents = GetMappingEvents(anchorAlias.Value);
                            _allEvents.RemoveRange(i, 2);
                            _allEvents.InsertRange(i, mergedEvents);
                            continue;
                        }

                        var sequence = _allEvents[i + 1] as SequenceStart;
                        if (sequence != null)
                        {
                            var mergedEvents = new List<IEnumerable<ParsingEvent>>();
                            var sequenceEndFound = false;
                            for (var itemIndex = i + 2; itemIndex < _allEvents.Count; ++itemIndex)
                            {
                                anchorAlias = _allEvents[itemIndex] as AnchorAlias;
                                if (anchorAlias != null)
                                {
                                    mergedEvents.Add(GetMappingEvents(anchorAlias.Value));
                                    continue;
                                }

                                if (_allEvents[itemIndex] is SequenceEnd)
                                {
                                    _allEvents.RemoveRange(i, itemIndex - i + 1);
                                    _allEvents.InsertRange(i, mergedEvents.SelectMany(e => e));
                                    sequenceEndFound = true;
                                    break;
                                }
                            }

                            if (sequenceEndFound)
                            {
                                continue;
                            }
                        }

                        throw new SemanticErrorException(merge.Start, merge.End, "Unrecognized merge key pattern");
                    }
                }
            }

            var nextIndex = _currentIndex + 1;
            if (nextIndex < _allEvents.Count)
            {
                Current = _allEvents[nextIndex];
                _currentIndex = nextIndex;
                return true;
            }
            return false;
        }
Esempio n. 2
0
 void IParsingEventVisitor.Visit(MappingStart e)
 {
     clonedEvent = new MappingStart(null, e.Tag, e.IsImplicit, e.Style, e.Start, e.End);
 }
Esempio n. 3
0
 void IParsingEventVisitor.Visit(MappingEnd e)
 {
     clonedEvent = new MappingEnd(e.Start, e.End);
 }
Esempio n. 4
0
 void IParsingEventVisitor.Visit(SequenceEnd e)
 {
     clonedEvent = new SequenceEnd(e.Start, e.End);
 }
Esempio n. 5
0
 void IParsingEventVisitor.Visit(SequenceStart e)
 {
     clonedEvent = new SequenceStart(null, e.Tag, e.IsImplicit, e.Style, e.Start, e.End);
 }
Esempio n. 6
0
 void IParsingEventVisitor.Visit(Scalar e)
 {
     clonedEvent = new Scalar(null, e.Tag, e.Value, e.Style, e.IsPlainImplicit, e.IsQuotedImplicit, e.Start, e.End);
 }
Esempio n. 7
0
 void IParsingEventVisitor.Visit(AnchorAlias e)
 {
     clonedEvent = new AnchorAlias(e.Value, e.Start, e.End);
 }
Esempio n. 8
0
 public ParsingEvent Clone(ParsingEvent e)
 {
     e.Accept(this);
     return clonedEvent;
 }