Пример #1
0
 public static object GetValue(ScalarNode/*!*/ self) {
     return MutableString.CreateAscii(self.Value);
 }
Пример #2
0
 public static object GetValue(ScalarNode /*!*/ self)
 {
     return(MutableString.CreateAscii(self.Value));
 }
Пример #3
0
 public static object SetStyle(RubyContext/*!*/ context, ScalarNode/*!*/ self, object value) {
     self.Style = RubyYaml.ToYamlStyle(context, value);
     return value;
 }
Пример #4
0
 public static object SetStyle(RubyContext /*!*/ context, ScalarNode /*!*/ self, object value)
 {
     self.Style = RubyYaml.ToYamlStyle(context, value);
     return(value);
 }
Пример #5
0
        public static object ConstructYamlTimestamp(BaseConstructor ctor, Node node)
        {
            ScalarNode scalar = node as ScalarNode;

            if (scalar == null)
            {
                throw new ConstructorException("can only contruct timestamp from scalar node");
            }

            Match match = TimestampRegex.Match(scalar.Value);

            if (!match.Success)
            {
                return(ctor.ConstructPrivateType(node));
            }

            string year_s      = match.Groups[1].Value;
            string month_s     = match.Groups[2].Value;
            string day_s       = match.Groups[3].Value;
            string hour_s      = match.Groups[4].Value;
            string min_s       = match.Groups[5].Value;
            string sec_s       = match.Groups[6].Value;
            string fract_s     = match.Groups[7].Value;
            string utc         = match.Groups[8].Value;
            string timezoneh_s = match.Groups[9].Value;
            string timezonem_s = match.Groups[10].Value;

            bool isUtc = utc == "Z" || utc == "z";

            DateTime dt = new DateTime(
                year_s != "" ? Int32.Parse(year_s, CultureInfo.InvariantCulture) : 0,
                month_s != "" ? Int32.Parse(month_s, CultureInfo.InvariantCulture) : 1,
                day_s != "" ? Int32.Parse(day_s, CultureInfo.InvariantCulture) : 1,
                hour_s != "" ? Int32.Parse(hour_s, CultureInfo.InvariantCulture) : 0,
                min_s != "" ? Int32.Parse(min_s, CultureInfo.InvariantCulture) : 0,
                sec_s != "" ? Int32.Parse(sec_s, CultureInfo.InvariantCulture) : 0,
                DateTimeKind.Utc
                );

            if (!String.IsNullOrEmpty(fract_s))
            {
                long fract = Int32.Parse(fract_s, CultureInfo.InvariantCulture);
                if (fract > 0)
                {
                    while (fract < 1000000)
                    {
                        fract *= 10;
                    }
                    dt = dt.AddTicks(fract);
                }
            }

            if (!isUtc)
            {
                if (timezoneh_s != "" || timezonem_s != "")
                {
                    int zone = 0;
                    int sign = +1;
                    if (timezoneh_s != "")
                    {
                        if (timezoneh_s.StartsWith("-", StringComparison.Ordinal))
                        {
                            sign = -1;
                        }
                        zone += Int32.Parse(timezoneh_s.Substring(1), CultureInfo.InvariantCulture) * 3600000;
                    }
                    if (timezonem_s != "")
                    {
                        zone += Int32.Parse(timezonem_s, CultureInfo.InvariantCulture) * 60000;
                    }
                    dt = dt.AddMilliseconds(-sign * zone);
                }
                dt = RubyTime.ToLocalTime(dt);
            }
            return(new RubyTime(dt));
        }
Пример #6
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;
        }
Пример #7
0
        private static Range /*!*/ ConstructRubyRange(RubyConstructor /*!*/ ctor, Node /*!*/ node)
        {
            object     begin      = null;
            object     end        = null;
            bool       excludeEnd = false;
            ScalarNode scalar     = node as ScalarNode;

            if (scalar != null)
            {
                string value = scalar.Value;
                int    dotsIdx;
                if ((dotsIdx = value.IndexOf("...", StringComparison.Ordinal)) != -1)
                {
                    begin      = ParseObject(ctor, value.Substring(0, dotsIdx));
                    end        = ParseObject(ctor, value.Substring(dotsIdx + 3));
                    excludeEnd = true;
                }
                else if ((dotsIdx = value.IndexOf("..", StringComparison.Ordinal)) != -1)
                {
                    begin = ParseObject(ctor, value.Substring(0, dotsIdx));
                    end   = ParseObject(ctor, value.Substring(dotsIdx + 2));
                }
                else
                {
                    throw new ConstructorException("Invalid Range: " + value);
                }
            }
            else
            {
                MappingNode mapping = node as MappingNode;
                if (mapping == null)
                {
                    throw new ConstructorException("Invalid Range: " + node);
                }
                foreach (KeyValuePair <Node, Node> n in mapping.Nodes)
                {
                    string key = ctor.ConstructScalar(n.Key).ToString();
                    switch (key)
                    {
                    case "begin":
                        begin = ctor.ConstructObject(n.Value);
                        break;

                    case "end":
                        end = ctor.ConstructObject(n.Value);
                        break;

                    case "excl":
                        if (!TryConstructYamlBool(ctor, n.Value, out excludeEnd))
                        {
                            throw new ConstructorException("Invalid Range: " + node);
                        }
                        break;

                    default:
                        throw new ConstructorException(String.Format("'{0}' is not allowed as an instance variable name for class Range", key));
                    }
                }
            }

            var comparisonStorage = new BinaryOpStorage(ctor.GlobalScope.Context);

            return(new Range(comparisonStorage, ctor.GlobalScope.Context, begin, end, excludeEnd));
        }
Пример #8
0
        public static object ConstructYamlTimestamp(IConstructor ctor, Node node)
        {
            ScalarNode scalar = node as ScalarNode;

            if (scalar == null)
            {
                throw new ConstructorException("can only contruct timestamp from scalar node");
            }

            Match match = TIMESTAMP_REGEXP.Match(scalar.Value);

            if (!match.Success)
            {
                return(ctor.ConstructPrivateType(node));
            }

            string year_s      = match.Groups[1].Value;
            string month_s     = match.Groups[2].Value;
            string day_s       = match.Groups[3].Value;
            string hour_s      = match.Groups[4].Value;
            string min_s       = match.Groups[5].Value;
            string sec_s       = match.Groups[6].Value;
            string fract_s     = match.Groups[7].Value;
            string utc         = match.Groups[8].Value;
            string timezoneh_s = match.Groups[9].Value;
            string timezonem_s = match.Groups[10].Value;

            bool isUtc = utc == "Z" || utc == "z";

            DateTime dt = new DateTime(
                year_s != "" ? int.Parse(year_s) : 0,
                month_s != "" ? int.Parse(month_s) : 1,
                day_s != "" ? int.Parse(day_s) : 1,
                hour_s != "" ? int.Parse(hour_s) : 0,
                min_s != "" ? int.Parse(min_s) : 0,
                sec_s != "" ? int.Parse(sec_s) : 0,
                isUtc? DateTimeKind.Utc : DateTimeKind.Local
                );

            if (!string.IsNullOrEmpty(fract_s))
            {
                long fract = int.Parse(fract_s);
                if (fract > 0)
                {
                    while (fract < 1000000)
                    {
                        fract *= 10;
                    }
                    dt = dt.AddTicks(fract);
                }
            }

            if (!isUtc)
            {
                if (timezoneh_s != "" || timezonem_s != "")
                {
                    int zone = 0;
                    int sign = +1;
                    if (timezoneh_s != "")
                    {
                        if (timezoneh_s.StartsWith("-"))
                        {
                            sign = -1;
                        }
                        zone += int.Parse(timezoneh_s.Substring(1)) * 3600000;
                    }
                    if (timezonem_s != "")
                    {
                        zone += int.Parse(timezonem_s) * 60000;
                    }
                    double utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(dt).TotalMilliseconds;
                    dt = dt.AddMilliseconds(utcOffset - sign * zone);
                }
            }
            return(dt);
        }