public static Range ConstructRubyRange(IConstructor /*!*/ 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)); } } } return(new Range(ctor.Scope.RubyContext, begin, end, excludeEnd)); }
private static object ParseObject(IConstructor 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); } }
public static Range ConstructRubyRange(IConstructor/*!*/ 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(); return new Range(comparisonStorage, ctor.GlobalScope.Context, begin, end, excludeEnd); }
private static object ParseObject(IConstructor 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); } }