Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 8x 8x 8x 10x 10x 10x 10x | // import Parser from 'web-tree-sitter';
// Cache parsers by grammar path to avoid re-initialization.
import { Language, Parser } from 'web-tree-sitter';
const parsers = new Map<string, Parser>();
export async function initializeParser(grammarPath: string): Promise<Parser> {
Iif (parsers.has(grammarPath)) {
return parsers.get(grammarPath)!;
}
await Parser.init();
const newParser = new Parser();
const language = await Language.load(grammarPath);
newParser.setLanguage(language);
parsers.set(grammarPath, newParser);
return newParser;
}
|