Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -23,6 +23,15 @@ exports.tokenizer = void 0;
const util = __importStar(require("./util"));
const types_1 = require("./types");
const sets = __importStar(require("./sets"));
/**
* Valid opening characters for capture group names.
*/
const captureGroupFirstChar = /^[a-zA-Z_$]$/i;
/**
* Valid characters for capture group names.
*/
const captureGroupChars = /^[a-zA-Z0-9_$]$/i;
const digit = /\d/;
/**
* Tokenizes a regular expression (that is currently a string)
* @param {string} regexpStr String of regular expression to be tokenized
@@ -79,9 +88,9 @@ exports.tokenizer = (regexpStr) => {
default:
// Check if c is integer.
// In which case it's a reference.
if (/\d/.test(c)) {
if (digit.test(c)) {
let digits = c;
while (i < str.length && /\d/.test(str[i])) {
while (i < str.length && digit.test(str[i])) {
digits += str[i++];
}
let value = parseInt(digits, 10);
@@ -136,23 +145,52 @@ exports.tokenizer = (regexpStr) => {
stack: [],
remember: true,
};
// If if this is a special kind of group.
// If this is a special kind of group.
if (str[i] === '?') {
c = str[i + 1];
i += 2;
// Match if followed by.
if (c === '=') {
group.followedBy = true;
group.remember = false;
// Match if not followed by.
}
else if (c === '!') {
group.notFollowedBy = true;
group.remember = false;
}
else if (c !== ':') {
else if (c === '<') {
let name = '';
if (captureGroupFirstChar.test(str[i])) {
name += str[i];
i++;
}
else {
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid capture group name, character '${str[i]}'` +
` after '<' at column ${i + 1}`);
}
while (i < str.length && captureGroupChars.test(str[i])) {
name += str[i];
i++;
}
if (!name) {
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid capture group name, character '${str[i]}'` +
` after '<' at column ${i + 1}`);
}
if (str[i] !== '>') {
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unclosed capture group name, expected '>', found` +
` '${str[i]}' at column ${i + 1}`);
}
group.name = name;
i++;
}
else if (c === ':') {
group.remember = false;
}
else {
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid group, character '${c}'` +
` after '?' at column ${i - 1}`);
}
group.remember = false;
}
else {
groupCount += 1;