@making-sense/antlr-editor
Version:
ANTLR Typescript editor
63 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokensProvider = void 0;
const vocabularyPack_1 = require("./vocabularyPack");
class TokensProvider {
constructor(tools) {
const { Lexer, monarchDefinition = {} } = tools;
this.definition = JSON.parse(JSON.stringify(monarchDefinition), rgxReviver);
this.createCategories();
this.addTokens(Lexer);
}
createCategories() {
this.createCategory("keywords");
this.createCategory("operators");
this.createCategory("specials");
this.createCategory("variables");
this.createCategory("attributes");
this.createCategory("dimensions");
this.createCategory("primaryMeasures");
}
createCategory(category) {
if (!(category in this.definition) || !(this.definition.keywords instanceof Array)) {
this.definition[category] = new Array();
}
}
addTokens(lexer) {
const { vocabulary } = lexer;
const ruleNames = lexer.ruleNames;
ruleNames.forEach((_, index) => {
let tokenName = vocabulary.getLiteralName(++index);
if (tokenName) {
tokenName = tokenName.replace(/^'+|'+$/g, "");
if (vocabularyPack_1.keywordRgx.test(tokenName)) {
this.definition.keywords.push(tokenName);
}
else if (vocabulary.getSymbolicName(index)) {
this.definition.specials.push(tokenName);
}
else {
this.definition.operators.push(tokenName);
}
}
});
}
monarchLanguage() {
return this.definition;
}
addVariables() {
this.definition.variables.push("ds_L_CY", "ErrB", "ds_V_PY");
}
}
exports.TokensProvider = TokensProvider;
const rgxPrefix = "_RGX_";
const rgxRgx = /\/(.*)\/(.*)?/;
function rgxReviver(_, value) {
const strValue = value.toString();
if (strValue.indexOf(rgxPrefix) === 0) {
const matchArray = strValue.split(rgxPrefix)[1].match(rgxRgx);
return new RegExp(matchArray[1], matchArray[2] || "");
}
return value;
}
//# sourceMappingURL=tokensProvider.js.map