Inheritance: CollectionNode
        //TODO: remove Ruby-specific stuff from this layer
        public RubyArray /*!*/ ConstructSequence(Node /*!*/ sequenceNode)
        {
            SequenceNode seq = sequenceNode as SequenceNode;

            if (seq == null)
            {
                throw new ConstructorException("expected a sequence node, but found: " + sequenceNode);
            }
            IList <Node> @internal = seq.Nodes;
            RubyArray    val       = new RubyArray(@internal.Count);

            foreach (Node node in @internal)
            {
                object   obj      = ConstructObject(node);
                LinkNode linkNode = obj as LinkNode;
                if (linkNode != null)
                {
                    int ix = val.Count;
                    AddFixer(linkNode.Linked, delegate(Node n, object real) {
                        val[ix] = real;
                    });
                }
                val.Add(obj);
            }
            return(val);
        }
Exemple #2
0
                public static object CreateSequence([NotNull]BlockParam/*!*/ block, Out/*!*/ self, [DefaultProtocol]MutableString taguri, object yamlStyle) {
                    var rep = self._representer;
                    var seq = new SequenceNode(rep.ToTag(taguri), new List<Node>(), RubyYaml.ToYamlFlowStyle(yamlStyle));

                    object blockResult;
                    if (block.Yield(seq, out blockResult)) {
                        return blockResult;
                    }

                    return seq;
                }
Exemple #3
0
                public static object CreateSequence([NotNull] BlockParam /*!*/ block, Out /*!*/ self, [DefaultProtocol] MutableString taguri, object yamlStyle)
                {
                    var rep = self._representer;
                    var seq = new SequenceNode(rep.ToTag(taguri), new List <Node>(), RubyYaml.ToYamlFlowStyle(yamlStyle));

                    object blockResult;

                    if (block.Yield(seq, out blockResult))
                    {
                        return(blockResult);
                    }

                    return(seq);
                }
Exemple #4
0
        private Node ComposeNode(Node parent, object index)
        {
            Node      result;
            YamlEvent @event    = _parser.PeekEvent();
            NodeEvent nodeEvent = @event as NodeEvent;

            string anchor = (nodeEvent != null) ? nodeEvent.Anchor : null;

            if (nodeEvent is AliasEvent)
            {
                _parser.GetEvent();
                if (!_anchors.TryGetValue(anchor, out result))
                {
                    throw new ComposerException("found undefined alias: " + anchor);
                }
                return(result);
            }

            result = null;
            //_resolver.descendResolver(parent, index);
            if (@event is ScalarEvent)
            {
                ScalarEvent ev  = (ScalarEvent)_parser.GetEvent();
                string      tag = ev.Tag;
                if (tag == null || tag == "!")
                {
                    tag = Resolver.Resolve(typeof(ScalarNode), ev.Value, ev.Implicit);
                }
                result = new ScalarNode(tag, ev.Value, ev.Style);
                if (null != anchor)
                {
                    AddAnchor(anchor, result);
                }
            }
            else if (@event is SequenceStartEvent)
            {
                SequenceStartEvent start = (SequenceStartEvent)_parser.GetEvent();
                string             tag   = start.Tag;
                if (tag == null || tag == "!")
                {
                    tag = Resolver.Resolve(typeof(SequenceNode), null, start.Implicit);
                }
                SequenceNode seqResult = new SequenceNode(tag, new List <Node>(), start.FlowStyle);
                result = seqResult;
                if (null != anchor)
                {
                    AddAnchor(anchor, seqResult);
                }
                int ix = 0;
                while (!(_parser.PeekEvent() is SequenceEndEvent))
                {
                    seqResult.Nodes.Add(ComposeNode(seqResult, ix++));
                }
                _parser.GetEvent();
            }
            else if (@event is MappingStartEvent)
            {
                MappingStartEvent start = (MappingStartEvent)_parser.GetEvent();
                string            tag   = start.Tag;
                if (tag == null || tag == "!")
                {
                    tag = Resolver.Resolve(typeof(MappingNode), null, start.Implicit);
                }
                MappingNode mapResult = new MappingNode(tag, new Dictionary <Node, Node>(), start.FlowStyle);
                result = mapResult;
                if (null != anchor)
                {
                    AddAnchor(anchor, result);
                }
                while (!(_parser.PeekEvent() is MappingEndEvent))
                {
                    YamlEvent key      = _parser.PeekEvent();
                    Node      itemKey  = ComposeNode(mapResult, null);
                    Node      composed = ComposeNode(mapResult, itemKey);
                    if (!mapResult.Nodes.ContainsKey(itemKey))
                    {
                        mapResult.Nodes.Add(itemKey, composed);
                    }
                }
                _parser.GetEvent();
            }
            //_resolver.ascendResolver();
            return(result);
        }
Exemple #5
0
 public static void Add(YamlCallSiteStorage/*!*/ siteStorage, SequenceNode/*!*/ self, object value) {
     RubyRepresenter rep = new RubyRepresenter(siteStorage);
     self.Nodes.Add(rep.RepresentItem(value));
 }
Exemple #6
0
 public static object SetStyle(SequenceNode/*!*/ self, object value) {
     self.FlowStyle = RubyYaml.ToYamlFlowStyle(value);
     return value;
 }
Exemple #7
0
                public static void Add(YamlCallSiteStorage /*!*/ siteStorage, SequenceNode /*!*/ self, object value)
                {
                    RubyRepresenter rep = new RubyRepresenter(siteStorage);

                    self.Nodes.Add(rep.RepresentItem(value));
                }
Exemple #8
0
 public static object SetStyle(SequenceNode /*!*/ self, object value)
 {
     self.FlowStyle = RubyYaml.ToYamlFlowStyle(value);
     return(value);
 }
Exemple #9
0
        private Node ComposeNode(Node parent, object index) {
            Node result;
            YamlEvent @event = _parser.PeekEvent();
            NodeEvent nodeEvent = @event as NodeEvent;

            string anchor = (nodeEvent != null) ? nodeEvent.Anchor : null;

            if (nodeEvent is AliasEvent) {
                _parser.GetEvent();
                if (!_anchors.TryGetValue(anchor, out result)) {
                    throw new ComposerException("found undefined alias: " + anchor);
                }
                return result;
            }

            result = null;
            //_resolver.descendResolver(parent, index);
            if (@event is ScalarEvent) {
                ScalarEvent ev = (ScalarEvent)_parser.GetEvent();

                string tag = ev.Tag;
                if (ev.Type == ScalarValueType.Unknown) {
                    Debug.Assert(tag == null || tag == "!");
                    tag = ResolverScanner.Recognize(ev.Value) ?? Tags.Str;
                }

                result = new ScalarNode(tag, ev.Value, ev.Style);
                if (anchor != null) {
                    AddAnchor(anchor, result);
                }
            } else if (@event is SequenceStartEvent) {
                SequenceStartEvent start = (SequenceStartEvent)_parser.GetEvent();
                SequenceNode seqResult = new SequenceNode(start.Tag != "!" ? start.Tag : null, new List<Node>(), start.FlowStyle);
                result = seqResult;
                if (anchor != null) {
                    AddAnchor(anchor, seqResult);
                }
                int ix = 0;
                while (!(_parser.PeekEvent() is SequenceEndEvent)) {
                    seqResult.Nodes.Add(ComposeNode(seqResult, ix++));
                }
                _parser.GetEvent();
            } else if (@event is MappingStartEvent) {
                MappingStartEvent start = (MappingStartEvent)_parser.GetEvent();
                MappingNode mapResult = new MappingNode(start.Tag != "!" ? start.Tag : null, new Dictionary<Node, Node>(), start.FlowStyle);
                result = mapResult;
                if (anchor != null) {
                    AddAnchor(anchor, result);
                }
                while (!(_parser.PeekEvent() is MappingEndEvent)) {
                    YamlEvent key = _parser.PeekEvent();
                    Node itemKey = ComposeNode(mapResult, key);
                    Node composed = ComposeNode(mapResult, itemKey);
                    if (!mapResult.Nodes.ContainsKey(itemKey)) {
                        mapResult.Nodes.Add(itemKey, composed);
                    }
                }
                _parser.GetEvent();
            }
            //_resolver.ascendResolver();
            return result;
        }