full site update
This commit is contained in:
62
node_modules/regex/src/atomic.js
generated
vendored
62
node_modules/regex/src/atomic.js
generated
vendored
@@ -1,5 +1,4 @@
|
||||
import {emulationGroupMarker} from './subclass.js';
|
||||
import {noncapturingDelim, spliceStr} from './utils-internals.js';
|
||||
import {incrementIfAtLeast, noncapturingDelim, spliceStr} from './utils-internals.js';
|
||||
import {Context, replaceUnescaped} from 'regex-utilities';
|
||||
|
||||
const atomicPluginToken = new RegExp(String.raw`(?<noncapturingStart>${noncapturingDelim})|(?<capturingStart>\((?:\?<[^>]+>)?)|\\?.`, 'gsu');
|
||||
@@ -8,15 +7,24 @@ const atomicPluginToken = new RegExp(String.raw`(?<noncapturingStart>${noncaptur
|
||||
Apply transformations for atomic groups: `(?>…)`.
|
||||
@param {string} expression
|
||||
@param {import('./regex.js').PluginData} [data]
|
||||
@returns {string}
|
||||
@returns {Required<import('./regex.js').PluginResult>}
|
||||
*/
|
||||
function atomic(expression, data) {
|
||||
const hiddenCaptures = data?.hiddenCaptures ?? [];
|
||||
// Capture transfer is used by <github.com/slevithan/oniguruma-to-es>
|
||||
let captureTransfers = data?.captureTransfers ?? new Map();
|
||||
if (!/\(\?>/.test(expression)) {
|
||||
return expression;
|
||||
return {
|
||||
pattern: expression,
|
||||
captureTransfers,
|
||||
hiddenCaptures,
|
||||
};
|
||||
}
|
||||
|
||||
const aGDelim = '(?>';
|
||||
const emulatedAGDelim = `(?:(?=(${data?.useEmulationGroups ? emulationGroupMarker : ''}`;
|
||||
const emulatedAGDelim = '(?:(?=(';
|
||||
const captureNumMap = [0];
|
||||
const addedHiddenCaptures = [];
|
||||
let numCapturesBeforeAG = 0;
|
||||
let numAGs = 0;
|
||||
let aGPos = NaN;
|
||||
@@ -49,14 +57,27 @@ function atomic(expression, data) {
|
||||
} else if (m === ')' && inAG) {
|
||||
if (!numGroupsOpenInAG) {
|
||||
numAGs++;
|
||||
const addedCaptureNum = numCapturesBeforeAG + numAGs;
|
||||
// Replace `expression` and use `<$$N>` as a temporary wrapper for the backref so it
|
||||
// can avoid backref renumbering afterward. Need to wrap the whole substitution
|
||||
// (including the lookahead and following backref) in a noncapturing group to handle
|
||||
// following quantifiers and literal digits
|
||||
// can avoid backref renumbering afterward. Wrap the whole substitution (including the
|
||||
// lookahead and following backref) in a noncapturing group to handle following
|
||||
// quantifiers and literal digits
|
||||
expression = `${expression.slice(0, aGPos)}${emulatedAGDelim}${
|
||||
expression.slice(aGPos + aGDelim.length, index)
|
||||
}))<$$${numAGs + numCapturesBeforeAG}>)${expression.slice(index + 1)}`;
|
||||
}))<$$${addedCaptureNum}>)${expression.slice(index + 1)}`;
|
||||
hasProcessedAG = true;
|
||||
addedHiddenCaptures.push(addedCaptureNum);
|
||||
incrementIfAtLeast(hiddenCaptures, addedCaptureNum);
|
||||
if (captureTransfers.size) {
|
||||
const newCaptureTransfers = new Map();
|
||||
captureTransfers.forEach((from, to) => {
|
||||
newCaptureTransfers.set(
|
||||
to >= addedCaptureNum ? to + 1 : to,
|
||||
from.map(f => f >= addedCaptureNum ? f + 1 : f)
|
||||
);
|
||||
});
|
||||
captureTransfers = newCaptureTransfers;
|
||||
}
|
||||
break;
|
||||
}
|
||||
numGroupsOpenInAG--;
|
||||
@@ -66,10 +87,12 @@ function atomic(expression, data) {
|
||||
numCharClassesOpen--;
|
||||
}
|
||||
}
|
||||
// Start over from the beginning of the last atomic group's contents, in case the processed group
|
||||
// Start over from the beginning of the atomic group's contents, in case the processed group
|
||||
// contains additional atomic groups
|
||||
} while (hasProcessedAG);
|
||||
|
||||
hiddenCaptures.push(...addedHiddenCaptures);
|
||||
|
||||
// Second pass to adjust numbered backrefs
|
||||
expression = replaceUnescaped(
|
||||
expression,
|
||||
@@ -86,7 +109,12 @@ function atomic(expression, data) {
|
||||
},
|
||||
Context.DEFAULT
|
||||
);
|
||||
return expression;
|
||||
|
||||
return {
|
||||
pattern: expression,
|
||||
captureTransfers,
|
||||
hiddenCaptures,
|
||||
};
|
||||
}
|
||||
|
||||
const baseQuantifier = String.raw`(?:[?*+]|\{\d+(?:,\d*)?\})`;
|
||||
@@ -114,12 +142,15 @@ Transform posessive quantifiers into atomic groups. The posessessive quantifiers
|
||||
This follows Java, PCRE, Perl, and Python.
|
||||
Possessive quantifiers in Oniguruma and Onigmo are only: `?+`, `*+`, `++`.
|
||||
@param {string} expression
|
||||
@returns {string}
|
||||
@returns {import('./regex.js').PluginResult}
|
||||
*/
|
||||
function possessive(expression) {
|
||||
if (!(new RegExp(`${baseQuantifier}\\+`).test(expression))) {
|
||||
return expression;
|
||||
return {
|
||||
pattern: expression,
|
||||
};
|
||||
}
|
||||
|
||||
const openGroupIndices = [];
|
||||
let lastGroupIndex = null;
|
||||
let lastCharClassIndex = null;
|
||||
@@ -178,7 +209,10 @@ function possessive(expression) {
|
||||
}
|
||||
lastToken = m;
|
||||
}
|
||||
return expression;
|
||||
|
||||
return {
|
||||
pattern: expression,
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
|
Reference in New Issue
Block a user