Exemple #1
0
        protected override Value Apply_OneArg(Value arg)
        {
            if (arg is Str str)
            {
                string cstr = str.Value;
                if (string.IsNullOrEmpty(cstr))
                {
                    throw Error("non empty string is required");
                }

                for (int i = 0; i < cstr.Length; i++)
                {
                    if (Reader.IsNonAtomChar(cstr[i]))
                    {
                        throw Error($"invalid character: '{cstr[i]}'");
                    }
                }

                return(cstr.StartsWith(':') ? Reader.AddSymbol(cstr)
                                            : Reader.AddSymbol(':' + cstr));
            }

            if (arg is Keyword)
            {
                return(arg);
            }

            throw Expected("string/keyword");
        }
Exemple #2
0
        protected override Value Apply_OneArg(Value arg)
        {
            if (arg is Str str)
            {
                string cstr = str.Value;

                if (string.IsNullOrEmpty(cstr))
                {
                    throw Error("non empty string is required");
                }

                if (cstr.StartsWith(':'))
                {
                    throw Error("invalid first character: ':'");
                }

                for (int i = 0; i < cstr.Length; i++)
                {
                    if (Reader.IsNonAtomChar(cstr[i]))
                    {
                        throw Error($"invalid character: '{cstr[i]}'");
                    }
                }

                if (Reader.IsInteger(cstr) || Reader.IsReal(cstr) ||
                    cstr == "true" || cstr == "false" || cstr == "nil")
                {
                    throw Error($"invalid name for symbol: '{cstr}'");
                }

                return(Reader.AddSymbol(cstr));
            }

            throw Expected("string");
        }