{"version":3,"sources":["browser/textmate/textmate-tokenizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;;AAElF,OAAO,EAAC,QAAQ,EAAW,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAEhE,qBAAa,cAAe,YAAW,MAAM,CAAC,SAAS,CAAC,MAAM;aAGtC,SAAS,EAAE,YAAY;gBAAvB,SAAS,EAAE,YAAY;IAI3C,KAAK,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM;IAIhC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,OAAO;CAIlD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAE5B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CAEtB;AAED,yBAAiB,eAAe,CAAC;IAC7B;;;;OAIG;IACI,MAAM,OAAO,EAAE,eAErB,CAAC;CACL;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,qBAAqB,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAkC7J","file":"../../../src/browser/textmate/textmate-tokenizer.d.ts","sourcesContent":["/********************************************************************************\n * Copyright (C) 2018 Ericsson and others.\n *\n * This program and the accompanying materials are made available under the\n * terms of the Eclipse Public License v. 2.0 which is available at\n * http://www.eclipse.org/legal/epl-2.0.\n *\n * This Source Code may also be made available under the following Secondary\n * Licenses when the conditions for such availability set forth in the Eclipse\n * Public License v. 2.0 are satisfied: GNU General Public License, version 2\n * with the GNU Classpath Exception which is available at\n * https://www.gnu.org/software/classpath/license.html.\n *\n * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0\n ********************************************************************************/\n\nimport {IGrammar, INITIAL, StackElement} from 'vscode-textmate';\n\nexport class TokenizerState implements monaco.languages.IState {\n\n    constructor(\n        public readonly ruleStack: StackElement\n    ) {\n    }\n\n    clone(): monaco.languages.IState {\n        return new TokenizerState(this.ruleStack);\n    }\n\n    equals(other: monaco.languages.IState): boolean {\n        return other instanceof TokenizerState && (other === this || other.ruleStack === this.ruleStack);\n    }\n\n}\n\n/**\n * Options for the TextMate tokenizer.\n */\nexport interface TokenizerOption {\n\n    /**\n     * Maximum line length that will be handled by the TextMate tokenizer. If the length of the actual line exceeds this\n     * limit, the tokenizer terminates and the tokenization of any subsequent lines might be broken.\n     *\n     * If the `lineLimit` is not defined, it means, there are no line length limits. Otherwise, it must be a positive\n     * integer or an error will be thrown.\n     */\n    lineLimit?: number;\n\n}\n\nexport namespace TokenizerOption {\n    /**\n     * The default TextMate tokenizer option.\n     *\n     * @deprecated Use the current value of `editor.maxTokenizationLineLength` preference instead.\n     */\n    export const DEFAULT: TokenizerOption = {\n        lineLimit: 400\n    };\n}\n\nexport function createTextmateTokenizer(grammar: IGrammar, options: TokenizerOption): monaco.languages.EncodedTokensProvider & monaco.languages.TokensProvider {\n    if (options.lineLimit !== undefined && (options.lineLimit <= 0 || !Number.isInteger(options.lineLimit))) {\n        throw new Error(`The 'lineLimit' must be a positive integer. It was ${options.lineLimit}.`);\n    }\n    return {\n        getInitialState: () => new TokenizerState(INITIAL),\n        tokenizeEncoded(line: string, state: TokenizerState): monaco.languages.IEncodedLineTokens {\n            let processedLine = line;\n            if (options.lineLimit !== undefined && line.length > options.lineLimit) {\n                // Line is too long to be tokenized\n                processedLine = line.substr(0, options.lineLimit);\n            }\n            const result = grammar.tokenizeLine2(processedLine, state.ruleStack);\n            return {\n                endState: new TokenizerState(result.ruleStack),\n                tokens: result.tokens\n            };\n        },\n        tokenize(line: string, state: TokenizerState): monaco.languages.ILineTokens {\n            let processedLine = line;\n            if (options.lineLimit !== undefined && line.length > options.lineLimit) {\n                // Line is too long to be tokenized\n                processedLine = line.substr(0, options.lineLimit);\n            }\n            const result = grammar.tokenizeLine(processedLine, state.ruleStack);\n            return {\n                endState: new TokenizerState(result.ruleStack),\n                tokens: result.tokens.map(t => ({\n                    startIndex: t.startIndex,\n                    scopes: t.scopes.reverse().join(' ')\n                }))\n            };\n        }\n    };\n}\n"]}