@erml/parser
Version:
Parser implementation of ERML
37 lines (36 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringLiteralRegexp = void 0;
var tokensRegexs = [
"\\w+",
"{",
"}",
"<",
">",
"\\(",
"\\)",
",",
"(\\+|-)?(\\d+|Infinity)",
'"((?:[^"\\\\]|\\\\.)*)"',
"//.*|\\/\\*[^]*?\\*\\/|\\s",
"[^]", // Everything else
];
var tokenizerRegex = new RegExp(tokensRegexs.join("|"), "g");
var newLineRegexp = /\n/g;
var ignorablesRegex = /^\/\/.*|\/\*[^]*?\*\/|\s$/;
exports.stringLiteralRegexp = new RegExp(tokensRegexs[9]);
function default_1(ERML) {
var matches = ERML.matchAll(tokenizerRegex);
return Array.from(matches)
.map(function (_a) {
var _b;
var value = _a[0], position = _a.index;
var line = (((_b = ERML.slice(0, position).match(newLineRegexp)) === null || _b === void 0 ? void 0 : _b.length) || 0) + 1;
return { value: value, position: position, line: line };
})
.filter(function (_a) {
var value = _a.value;
return ignorablesRegex.test(value) === false;
});
}
exports.default = default_1;