UNPKG

@making-sense/antlr-editor

Version:
69 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VocabularyPack = exports.keywordRgx = void 0; exports.keywordRgx = /[a-zA-Z][\w]*/; class VocabularyPack { constructor(lexer, parser) { this.ruleNames = Array.from(parser.ruleNames); const count = lexer.vocabulary.maxTokenType; this.symbolicNames = new Array(count); this.literalNames = new Array(count); this.operatorNames = new Array(count); this.keywordNames = new Array(count); const vocabulary = lexer.vocabulary; lexer.ruleNames.forEach(ruleName => { if (ruleName in lexer) { const index = lexer[ruleName]; if (typeof index === "number" && Number.isInteger(index) && index > 0 && index <= count) { this.symbolicNames[index] = ruleName; this.literalNames[index] = vocabulary.getLiteralName(index); this.operatorNames[index] = this.literalNames[index]?.replace(/^'+|'+$/g, ""); this.keywordNames[index] = exports.keywordRgx.test(this.operatorNames[index] ?? "") ? this.operatorNames[index] : undefined; } } }); } ruleName(index) { return this.ruleNames[index]; } symbolicName(index) { return this.symbolicNames[index]; } operator(index) { return this.operatorNames[index]; } keyword(index) { return this.keywordNames[index]; } getLiteralNames() { return this.literalNames; } getSymbolicNames() { return this.symbolicNames; } isSymbolicName(name) { return this.symbolicNames.includes(name); } isRuleName(name) { return this.ruleNames.includes(name); } symbolicIndex(name) { return this.symbolicNames.indexOf(name); } hasKeyword(index) { return !!this.keywordNames[index]; } hasOperator(index) { return !!this.operatorNames[index]; } getRuleNames() { return this.ruleNames; } } exports.VocabularyPack = VocabularyPack; //# sourceMappingURL=vocabularyPack.js.map