Exemplo n.º 1
0
        /// <summary>
        /// Returns MutableString or RubySymbol.
        /// </summary>
        private static object ConstructRubyString(RubyConstructor /*!*/ ctor, Node /*!*/ node)
        {
            ScalarNode scalar = (ScalarNode)node;
            string     value  = ctor.ConstructScalar(node);

            if (value == null)
            {
                return(null);
            }

            if (value.Length > 1 && value[0] == ':' && scalar.Style == ScalarQuotingStyle.None)
            {
                return(ctor.GlobalScope.Context.CreateAsciiSymbol(value.Substring(1)));
            }

            return(MutableString.CreateMutable(value, ctor.RubyEncoding));
        }
Exemplo n.º 2
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("...")) != -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);            
        }
Exemplo n.º 3
0
 private static object ConstructRubyScalar(RubyConstructor/*!*/ ctor, Node node) {
     object value = ctor.ConstructScalar(node);
     if (value == null) {
         return value;
     }
     string str = value as string;
     if (str != null) {
         return MutableString.Create(str, RubyEncoding.UTF8);
     }
     return value;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns MutableString or RubySymbol.
        /// </summary>
        private static object ConstructRubyString(RubyConstructor/*!*/ ctor, Node/*!*/ node) {
            ScalarNode scalar = (ScalarNode)node;
            string value = ctor.ConstructScalar(node);

            if (value == null) {
                return null;
            }

            if (value.Length > 1 && value[0] == ':' && scalar.Style == ScalarQuotingStyle.None) {
                return ctor.GlobalScope.Context.CreateAsciiSymbol(value.Substring(1));
            }

            return MutableString.CreateMutable(value, ctor.RubyEncoding);
        }
Exemplo n.º 5
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));
        }