Пример #1
0
        public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, RubySymbol /*!*/ self)
        {
            var  str = self.ToString();
            bool allowMultiByteCharacters = context.RubyOptions.Compatibility >= RubyCompatibility.Ruby19 || context.KCode != null;

            var result = self.ToMutableString();

            // simple cases:
            if (
                Tokenizer.IsMethodName(str, allowMultiByteCharacters) ||
                Tokenizer.IsConstantName(str, allowMultiByteCharacters) ||
                Tokenizer.IsInstanceVariableName(str, allowMultiByteCharacters) ||
                Tokenizer.IsClassVariableName(str, allowMultiByteCharacters) ||
                Tokenizer.IsGlobalVariableName(str, allowMultiByteCharacters)
                )
            {
                result.Insert(0, ':');
            }
            else
            {
                // TODO: this is neither efficient nor complete.
                // Any string that parses as 'sym' should not be quoted.
                switch (str)
                {
                case null:
                    // Ruby doesn't allow empty symbols, we can get one from outside though:
                    return(MutableString.CreateAscii(":\"\""));

                case "|":
                case "^":
                case "&":
                case "<=>":
                case "==":
                case "===":
                case "=~":
                case ">":
                case ">=":
                case "<":
                case "<=":
                case "<<":
                case ">>":
                case "+":
                case "-":
                case "*":
                case "/":
                case "%":
                case "**":
                case "~":
                case "+@":
                case "-@":
                case "[]":
                case "[]=":
                case "`":

                case "$!":
                case "$@":
                case "$,":
                case "$;":
                case "$/":
                case "$\\":
                case "$*":
                case "$$":
                case "$?":
                case "$=":
                case "$:":
                case "$\"":
                case "$<":
                case "$>":
                case "$.":
                case "$~":
                case "$&":
                case "$`":
                case "$'":
                case "$+":
                    result.Insert(0, ':');
                    break;

                default:
                    result.Insert(0, ":\"").Append('"');
                    break;
                }
            }

            if (context.RuntimeId != self.RuntimeId)
            {
                result.Append(" @").Append(self.RuntimeId.ToString(CultureInfo.InvariantCulture));
            }

            return(result);
        }
Пример #2
0
 public static MutableString /*!*/ ToString(RubySymbol /*!*/ self)
 {
     return(self.ToMutableString());
 }
Пример #3
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, [NotNull] RubyRegex /*!*/ regex)
 {
     return(MutableStringOps.Match(storage, scope, self.ToMutableString(), regex));
 }
Пример #4
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ pattern)
 {
     return(MutableStringOps.Match(storage, scope, self.ToMutableString(), pattern));
 }
Пример #5
0
 public static object Match(BinaryOpStorageWithScope /*!*/ storage, RubyScope /*!*/ scope, RubySymbol /*!*/ self, object obj)
 {
     return(MutableStringOps.Match(storage, scope, self.ToMutableString(), obj));
 }