예제 #1
0
파일: Locale.cs 프로젝트: jimjag/crayon
        private Locale(string name)
        {
            this.ID = name;
            bool invalid = false;

            if (name.Length > 100)
            {
                for (int i = 0; i < name.Length; ++i)
                {
                    char c = name[i];
                    if ((c < 'a' || c > 'z') &&
                        (c < 'A' || c > 'Z'))
                    {
                        invalid = true;
                        break;
                    }
                }
            }
            string keywordsRaw = ResourceReader.GetFile(name.ToLowerInvariant() + "/keywords.txt");

            if (keywordsRaw == null)
            {
                invalid = true;
            }

            if (invalid)
            {
                throw new InvalidOperationException("Unknown locale: '" + name + "'");
            }

            Dictionary <string, string> keywords = new Dictionary <string, string>();

            foreach (string keywordRow in keywordsRaw.Trim().Split('\n'))
            {
                string row = keywordRow.Trim();
                if (row.Length > 0)
                {
                    string[] parts = keywordRow.Split(':');
                    if (parts.Length != 2)
                    {
                        throw new Exception("Unknown line in keywords: " + keywordRow);
                    }

                    keywords.Add(parts[0].Trim(), parts[1].Trim());
                }
            }
            this.keywordsDictionary = keywords;

            this.Keywords = new KeywordsLookup()
            {
                Lookup = new HashSet <string>(keywords.Values),
                ValidIdentifierNames = new HashSet <string>(
                    new string[] {
                    "FIELD_ENUM_LENGTH",
                    "FIELD_ENUM_MAX",
                    "FIELD_ENUM_VALUES",
                    "MAIN_FUNCTION",
                }.Select(k => keywords[k])),

                ABSTRACT          = keywords["ABSTRACT"],
                BASE              = keywords["BASE"],
                BREAK             = keywords["BREAK"],
                CASE              = keywords["CASE"],
                CATCH             = keywords["CATCH"],
                CLASS             = keywords["CLASS"],
                CONST             = keywords["CONST"],
                CONSTRUCTOR       = keywords["CONSTRUCTOR"],
                CONTINUE          = keywords["CONTINUE"],
                DEFAULT           = keywords["DEFAULT"],
                DO                = keywords["DO"],
                DO_WHILE_END      = keywords["DO_WHILE_END"],
                ELSE              = keywords["ELSE"],
                ENUM              = keywords["ENUM"],
                FALSE             = keywords["FALSE"],
                FIELD             = keywords["FIELD"],
                FIELD_ENUM_LENGTH = keywords["FIELD_ENUM_LENGTH"],
                FIELD_ENUM_MAX    = keywords["FIELD_ENUM_MAX"],
                FIELD_ENUM_VALUES = keywords["FIELD_ENUM_VALUES"],
                FINAL             = keywords["FINAL"],
                FINALLY           = keywords["FINALLY"],
                FOR               = keywords["FOR"],
                FUNCTION          = keywords["FUNCTION"],
                IF                = keywords["IF"],
                IMPORT            = keywords["IMPORT"],
                INTERFACE         = keywords["INTERFACE"],
                IS                = keywords["IS"],
                MAIN_FUNCTION     = keywords["MAIN_FUNCTION"],
                NAMESPACE         = keywords["NAMESPACE"],
                NEW               = keywords["NEW"],
                NULL              = keywords["NULL"],
                PRIVATE           = keywords["PRIVATE"],
                RETURN            = keywords["RETURN"],
                STATIC            = keywords["STATIC"],
                SWITCH            = keywords["SWITCH"],
                THIS              = keywords["THIS"],
                THROW             = keywords["THROW"],
                TRUE              = keywords["TRUE"],
                TRY               = keywords["TRY"],
                WHILE             = keywords["WHILE"],
            };

            this.Strings = new StringTable(name);
        }