Пример #1
0
 private Token FetchFlowScalar(ScalarQuotingStyle style)
 {
     _docStart = false;
     SavePossibleSimpleKey();
     _allowSimpleKey = false;
     return(AddToken(ScanFlowScalar(style)));
 }
Пример #2
0
 private Token FetchBlockScalar(ScalarQuotingStyle style)
 {
     _docStart       = false;
     _allowSimpleKey = true;
     RemovePossibleSimpleKey();
     return(AddToken(ScanBlockScalar(style)));
 }
Пример #3
0
        private ScalarProperties?_analysis;  // lazy

        public ScalarEvent(string anchor, string tag, ScalarValueType type, string value, ScalarQuotingStyle style)
            : base(anchor)
        {
            _tag   = tag;
            _type  = type;
            _value = value;
            _style = style;
        }
Пример #4
0
        private Token ScanFlowScalar(ScalarQuotingStyle style)
        {
            StringBuilder chunks = new StringBuilder();

            char quote = Peek();

            Forward();
            ScanFlowScalarNonSpaces(chunks, style == ScalarQuotingStyle.Double);
            while (Peek() != quote)
            {
                ScanFlowScalarSpaces(chunks);
                ScanFlowScalarNonSpaces(chunks, style == ScalarQuotingStyle.Double);
            }
            Forward();
            return(new ScalarToken(chunks.ToString(), style));
        }
Пример #5
0
        public static Node /*!*/ ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep)
        {
            if (!self.IsEmpty && ContainsBinaryData(self))
            {
                return(rep.BaseCreateNode(self.ToByteArray()));
            }

            Debug.Assert(self.IsAscii());
            string str = self.ToString();

            ScalarQuotingStyle style = ScalarQuotingStyle.None;

            if (str.StartsWith(":", StringComparison.Ordinal))
            {
                style = ScalarQuotingStyle.Double;
            }
            else
            {
                style = rep.GetYamlStyle(self);
            }

            var   tag = rep.GetTagUri(self, Tags.Str, typeof(MutableString));
            IList instanceVariableNames = rep.ToYamlProperties(self);

            if (instanceVariableNames.Count == 0)
            {
                return(rep.Scalar(tag, str, style));
            }

            var map = new Dictionary <object, object>();

            rep.AddYamlProperties(map, self, instanceVariableNames, false);
            return(rep.Map(
                       new Dictionary <Node, Node> {
                { rep.Scalar(null, "str", style), rep.Scalar(null, str, style) }
            },
                       tag,
                       map,
                       FlowStyle.Block
                       ));
        }
Пример #6
0
        private void SerializeNode(Node node, Node parent, object index)
        {
            while (node is LinkNode)
            {
                node = ((LinkNode)node).Linked;
            }

            string tAlias;

            _anchors.TryGetValue(node, out tAlias);

            if (_serializedNodes.ContainsKey(node) && tAlias != null)
            {
                _emitter.Emit(new AliasEvent(tAlias));
            }
            else
            {
                _serializedNodes[node] = null;
                //_resolver.descendResolver(parent, index);

                ScalarNode   scalar;
                SequenceNode seq;
                MappingNode  map;

                if ((scalar = node as ScalarNode) != null)
                {
                    string             tag   = node.Tag;
                    ScalarQuotingStyle style = scalar.Style;
                    ScalarValueType    type;
                    if (tag == null)
                    {
                        // quote an untagged sctring scalar that might be parsed as a different scalar type if not quoted:
                        if (style == ScalarQuotingStyle.None && ResolverScanner.Recognize(scalar.Value) != null)
                        {
                            style = ScalarQuotingStyle.Double;
                        }
                        type = ScalarValueType.String;
                    }
                    else if (tag == Tags.Str)
                    {
                        // omit the tag for strings that are not recognizable as other scalars:
                        if (ResolverScanner.Recognize(scalar.Value) == null)
                        {
                            tag = null;
                        }
                        type = ScalarValueType.String;
                    }
                    else if (scalar.Value == null)
                    {
                        tag  = null;
                        type = ScalarValueType.Other;
                    }
                    else
                    {
                        // omit the tag for non-string scalars whose type can be recognized from their value:
                        string detectedTag = ResolverScanner.Recognize(scalar.Value);
                        if (detectedTag != null && tag.StartsWith(detectedTag, StringComparison.Ordinal))
                        {
                            tag = null;
                        }
                        type = ScalarValueType.Other;
                    }

                    _emitter.Emit(new ScalarEvent(tAlias, tag, type, scalar.Value, style));
                }
                else if ((seq = node as SequenceNode) != null)
                {
                    _emitter.Emit(new SequenceStartEvent(tAlias, node.Tag, seq.FlowStyle));
                    int ix = 0;
                    foreach (Node n in seq.Nodes)
                    {
                        SerializeNode(n, node, ix++);
                    }
                    _emitter.Emit(SequenceEndEvent.Instance);
                }
                else if ((map = node as MappingNode) != null)
                {
                    _emitter.Emit(new MappingStartEvent(tAlias, node.Tag, map.FlowStyle));
                    foreach (KeyValuePair <Node, Node> e in map.Nodes)
                    {
                        SerializeNode(e.Key, node, null);
                        SerializeNode(e.Value, node, e.Key);
                    }
                    _emitter.Emit(MappingEndEvent.Instance);
                }
            }
        }
Пример #7
0
 public ScalarNode/*!*/ Scalar(string tag, string value, ScalarQuotingStyle style) {
     return new ScalarNode(tag, value, style);
 }
Пример #8
0
        private ScalarProperties? _analysis; // lazy

        #endregion Fields

        #region Constructors

        public ScalarEvent(string anchor, string tag, ScalarValueType type, string value, ScalarQuotingStyle style)
            : base(anchor)
        {
            _tag = tag;
            _type = type;
            _value = value;
            _style = style;
        }
Пример #9
0
 /*!*/
 internal Node Map(string tag, IDictionary/*!*/ map, ScalarQuotingStyle style)
 {
     return Map(tag, map, style != ScalarQuotingStyle.None ? FlowStyle.Inline : FlowStyle.Block);
 }
Пример #10
0
 public ScalarNode(string tag, string value, ScalarQuotingStyle style)
     : base(tag)
 {
     Style  = style;
     _value = value;
 }
Пример #11
0
        private Token ScanBlockScalar(ScalarQuotingStyle style)
        {
            bool          folded = style == ScalarQuotingStyle.Folded;
            StringBuilder chunks = new StringBuilder();

            bool?chomping;
            int  increment;

            if (!ScanBlockScalarIndicators(out chomping, out increment))
            {
                return(ScanPlain());
            }

            bool sameLine = ScanBlockScalarIgnoredLine();

            int minIndent = _indent + 1;

            if (minIndent < 0)
            {
                minIndent = 0;
            }

            int maxIndent = 0;
            int ind       = 0;

            if (sameLine)
            {
                bool leadingNonSpace = !BLANK_T(Peek());
                int  length          = 0;
                while (!NULL_OR_LINEBR(Peek(length)))
                {
                    length++;
                }
                Ensure(length, false);
                chunks.Append(_buffer, _pointer, length);
                Forward(length);
            }

            string breaks;

            if (increment == -1)
            {
                ScanBlockScalarIndentation(out breaks, out maxIndent);
                if (minIndent > maxIndent)
                {
                    ind = minIndent;
                }
                else
                {
                    ind = maxIndent;
                }
            }
            else
            {
                ind    = minIndent + increment - 1;
                breaks = ScanBlockScalarBreaks(ind);
            }

            string lineBreak = "";

            while (_column == ind && Peek() != '\0')
            {
                chunks.Append(breaks);
                bool leadingNonSpace = !BLANK_T(Peek());
                int  length          = 0;
                while (!NULL_OR_LINEBR(Peek(length)))
                {
                    length++;
                }
                Ensure(length, false);
                chunks.Append(_buffer, _pointer, length);
                Forward(length);
                lineBreak = ScanLineBreak();
                breaks    = ScanBlockScalarBreaks(ind);
                if (_column == ind && Peek() != '\0')
                {
                    if (folded && lineBreak.Length == 1 && lineBreak[0] == '\n' && leadingNonSpace && !BLANK_T(Peek()))
                    {
                        if (breaks.Length == 0)
                        {
                            chunks.Append(" ");
                        }
                    }
                    else
                    {
                        chunks.Append(lineBreak);
                    }
                }
                else
                {
                    break;
                }
            }

            if (chomping.GetValueOrDefault(true))
            {
                chunks.Append(lineBreak);
            }
            if (chomping.GetValueOrDefault(false))
            {
                chunks.Append(breaks);
            }

            return(new ScalarToken(chunks.ToString(), style));
        }
Пример #12
0
 public ScalarNode /*!*/ Scalar(string tag, string value, ScalarQuotingStyle style)
 {
     return(new ScalarNode(tag, value, style));
 }
Пример #13
0
 public ScalarNode(string tag, string value, ScalarQuotingStyle style)
     : base(tag) {
     Style = style;
     _value = value;
 }
Пример #14
0
 internal Node /*!*/ Map(string tag, IDictionary /*!*/ map, ScalarQuotingStyle style)
 {
     return(Map(tag, map, style != ScalarQuotingStyle.None ? FlowStyle.Inline : FlowStyle.Block));
 }
Пример #15
0
 public ScalarToken(string value, ScalarQuotingStyle style) {
     _value = value;
     _style = style;
 }
Пример #16
0
 public ScalarToken(string value, ScalarQuotingStyle style)
 {
     _value = value;
     _style = style;
 }