export function parseTextMateGrammar(grammar, modeService) {
    const embeddedLanguages = Object.create(null);
    if (grammar.embeddedLanguages) {
        let scopes = Object.keys(grammar.embeddedLanguages);
        for (let i = 0, len = scopes.length; i < len; i++) {
            let scope = scopes[i];
            let language = grammar.embeddedLanguages[scope];
            if (typeof language !== 'string') {
                // never hurts to be too careful
                continue;
            }
            let languageIdentifier = modeService.getLanguageIdentifier(language);
            if (languageIdentifier) {
                embeddedLanguages[scope] = languageIdentifier.id;
            }
        }
    }
    const tokenTypes = Object.create(null);
    if (grammar.tokenTypes) {
        const scopes = Object.keys(grammar.tokenTypes);
        for (const scope of scopes) {
            const tokenType = grammar.tokenTypes[scope];
            switch (tokenType) {
                case 'string':
                    tokenTypes[scope] = 2 /* String */;
                    break;
                case 'other':
                    tokenTypes[scope] = 0 /* Other */;
                    break;
                case 'comment':
                    tokenTypes[scope] = 1 /* Comment */;
                    break;
            }
        }
    }
    let languageIdentifier = null;
    if (grammar.language) {
        languageIdentifier = modeService.getLanguageIdentifier(grammar.language);
    }
    return {
        language: languageIdentifier ? languageIdentifier.id : undefined,
        scopeName: grammar.scopeName,
        embeddedLanguages: embeddedLanguages,
        tokenTypes: tokenTypes,
        injectTo: grammar.injectTo,
    };
}
