private static object ParseObject(RubyConstructor /*!*/ ctor, string /*!*/ value) { Composer composer = RubyYaml.MakeComposer(new StringReader(value), ctor.Encoding); if (composer.CheckNode()) { return(ctor.ConstructObject(composer.GetNode())); } else { throw new ConstructorException("Invalid YAML element: " + value); } }
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("...")) != -1) { begin = ParseObject(ctor, value.Substring(0, dotsIdx)); end = ParseObject(ctor, value.Substring(dotsIdx + 3)); excludeEnd = true; } else if ((dotsIdx = value.IndexOf("..")) != -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": TryConstructYamlBool(ctor, n.Value, out excludeEnd); 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); }
private static object ParseObject(RubyConstructor/*!*/ ctor, string value) { Composer composer = RubyYaml.MakeComposer(new StringReader(value)); if (composer.CheckNode()) { return ctor.ConstructObject(composer.GetNode()); } else { throw new ConstructorException("Invalid YAML element: " + value); } }
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)); }