First commit
This commit is contained in:
7
node_modules/ret/dist/index.d.ts
generated
vendored
Normal file
7
node_modules/ret/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { types } from './types';
|
||||
export * from './tokenizer';
|
||||
export * from './reconstruct';
|
||||
import { tokenizer } from './tokenizer';
|
||||
export * from './types';
|
||||
export default tokenizer;
|
||||
export { types };
|
||||
26
node_modules/ret/dist/index.js
generated
vendored
Normal file
26
node_modules/ret/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.types = void 0;
|
||||
/* istanbul ignore file */
|
||||
const types_1 = require("./types");
|
||||
Object.defineProperty(exports, "types", { enumerable: true, get: function () { return types_1.types; } });
|
||||
__exportStar(require("./tokenizer"), exports);
|
||||
__exportStar(require("./reconstruct"), exports);
|
||||
const tokenizer_1 = require("./tokenizer");
|
||||
const reconstruct_1 = require("./reconstruct");
|
||||
__exportStar(require("./types"), exports);
|
||||
exports.default = tokenizer_1.tokenizer;
|
||||
module.exports = tokenizer_1.tokenizer;
|
||||
module.exports.types = types_1.types;
|
||||
module.exports.reconstruct = reconstruct_1.reconstruct;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/ret/dist/index.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,0BAA0B;AAC1B,mCAAgC;AAQvB,sFARA,aAAK,OAQA;AAPd,8CAA4B;AAC5B,gDAA8B;AAC9B,2CAAwC;AACxC,+CAA4C;AAC5C,0CAAwB;AAExB,kBAAe,qBAAS,CAAC;AAGzB,MAAM,CAAC,OAAO,GAAG,qBAAS,CAAC;AAC3B,MAAM,CAAC,OAAO,CAAC,KAAK,GAAG,aAAK,CAAC;AAC7B,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,yBAAW,CAAC"}
|
||||
2
node_modules/ret/dist/reconstruct.d.ts
generated
vendored
Normal file
2
node_modules/ret/dist/reconstruct.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Tokens } from './types';
|
||||
export declare const reconstruct: (token: Tokens) => string;
|
||||
76
node_modules/ret/dist/reconstruct.js
generated
vendored
Normal file
76
node_modules/ret/dist/reconstruct.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.reconstruct = void 0;
|
||||
const types_1 = require("./types");
|
||||
const write_set_tokens_1 = require("./write-set-tokens");
|
||||
const reduceStack = (stack) => stack.map(exports.reconstruct).join('');
|
||||
const createAlternate = (token) => {
|
||||
if ('options' in token) {
|
||||
return token.options.map(reduceStack).join('|');
|
||||
}
|
||||
else if ('stack' in token) {
|
||||
return reduceStack(token.stack);
|
||||
}
|
||||
else {
|
||||
throw new Error(`options or stack must be Root or Group token`);
|
||||
}
|
||||
};
|
||||
exports.reconstruct = (token) => {
|
||||
switch (token.type) {
|
||||
case types_1.types.ROOT:
|
||||
return createAlternate(token);
|
||||
case types_1.types.CHAR: {
|
||||
const c = String.fromCharCode(token.value);
|
||||
// Note that the escaping for characters inside classes is handled
|
||||
// in the write-set-tokens module so '-' and ']' are not escaped here
|
||||
return (/[[\\{}$^.|?*+()]/.test(c) ? '\\' : '') + c;
|
||||
}
|
||||
case types_1.types.POSITION:
|
||||
if (token.value === '^' || token.value === '$') {
|
||||
return token.value;
|
||||
}
|
||||
else {
|
||||
return `\\${token.value}`;
|
||||
}
|
||||
case types_1.types.REFERENCE:
|
||||
return `\\${token.value}`;
|
||||
case types_1.types.SET:
|
||||
return write_set_tokens_1.writeSetTokens(token);
|
||||
case types_1.types.GROUP: {
|
||||
// Check token.remember
|
||||
const prefix = token.remember ? '' :
|
||||
token.followedBy ? '?=' :
|
||||
token.notFollowedBy ? '?!' :
|
||||
'?:';
|
||||
return `(${prefix}${createAlternate(token)})`;
|
||||
}
|
||||
case types_1.types.REPETITION: {
|
||||
const { min, max } = token;
|
||||
let endWith;
|
||||
if (min === 0 && max === 1) {
|
||||
endWith = '?';
|
||||
}
|
||||
else if (min === 1 && max === Infinity) {
|
||||
endWith = '+';
|
||||
}
|
||||
else if (min === 0 && max === Infinity) {
|
||||
endWith = '*';
|
||||
}
|
||||
else if (max === Infinity) {
|
||||
endWith = `{${min},}`;
|
||||
}
|
||||
else if (min === max) {
|
||||
endWith = `{${min}}`;
|
||||
}
|
||||
else {
|
||||
endWith = `{${min},${max}}`;
|
||||
}
|
||||
return `${exports.reconstruct(token.value)}${endWith}`;
|
||||
}
|
||||
case types_1.types.RANGE:
|
||||
return `${write_set_tokens_1.setChar(token.from)}-${write_set_tokens_1.setChar(token.to)}`;
|
||||
default:
|
||||
throw new Error(`Invalid token type ${token}`);
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=reconstruct.js.map
|
||||
1
node_modules/ret/dist/reconstruct.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/reconstruct.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"reconstruct.js","sourceRoot":"","sources":["../lib/reconstruct.ts"],"names":[],"mappings":";;;AAAA,mCAA4D;AAC5D,yDAA6D;AAE7D,MAAM,WAAW,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,KAAK,CA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CAAC,EAAE,CAAC;QACvD;YACE,MAAM,IAAI,KAAK,CAAC,sBAAsB,KAAK,EAAE,CAAC,CAAC;KAClD;AACH,CAAC,CAAC"}
|
||||
5
node_modules/ret/dist/sets-lookup.d.ts
generated
vendored
Normal file
5
node_modules/ret/dist/sets-lookup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { SetLookup } from './types';
|
||||
export declare const INTS: SetLookup;
|
||||
export declare const WORDS: SetLookup;
|
||||
export declare const WHITESPACE: SetLookup;
|
||||
export declare const NOTANYCHAR: SetLookup;
|
||||
51
node_modules/ret/dist/sets-lookup.js
generated
vendored
Normal file
51
node_modules/ret/dist/sets-lookup.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NOTANYCHAR = exports.WHITESPACE = exports.WORDS = exports.INTS = void 0;
|
||||
const Sets = __importStar(require("./sets"));
|
||||
const types_1 = require("./types");
|
||||
function setToLookup(tokens) {
|
||||
let lookup = {};
|
||||
let len = 0;
|
||||
for (const token of tokens) {
|
||||
if (token.type === types_1.types.CHAR) {
|
||||
lookup[token.value] = true;
|
||||
}
|
||||
// Note this is in an if statement because
|
||||
// the SetTokens type is (Char | Range | Set)[]
|
||||
// so a type error is thrown if it is not.
|
||||
// If the SetTokens type is modified the if statement
|
||||
// can be removed
|
||||
if (token.type === types_1.types.RANGE) {
|
||||
lookup[`${token.from}-${token.to}`] = true;
|
||||
}
|
||||
len += 1;
|
||||
}
|
||||
return {
|
||||
lookup: () => (Object.assign({}, lookup)),
|
||||
len,
|
||||
};
|
||||
}
|
||||
exports.INTS = setToLookup(Sets.ints().set);
|
||||
exports.WORDS = setToLookup(Sets.words().set);
|
||||
exports.WHITESPACE = setToLookup(Sets.whitespace().set);
|
||||
exports.NOTANYCHAR = setToLookup(Sets.anyChar().set);
|
||||
//# sourceMappingURL=sets-lookup.js.map
|
||||
1
node_modules/ret/dist/sets-lookup.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/sets-lookup.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sets-lookup.js","sourceRoot":"","sources":["../lib/sets-lookup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,mCAAsD;AAEtD,SAAS,WAAW,CAAC,MAAiB;IACpC,IAAI,MAAM,GAAqC,EAAE,CAAC;IAClD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI,KAAK,CAAC,IAAI,KAAK,aAAK,CAAC,IAAI,EAAE;YAC7B,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;SAC5B;QACD,0CAA0C;QAC1C,+CAA+C;QAC/C,0CAA0C;QAC1C,qDAAqD;QACrD,iBAAiB;QACjB,IAAI,KAAK,CAAC,IAAI,KAAK,aAAK,CAAC,KAAK,EAAE;YAC9B,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;SAC5C;QACD,GAAG,IAAI,CAAC,CAAC;KACV;IACD,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,mBAAM,MAAM,EAAG;QAC7B,GAAG;KACJ,CAAC;AACJ,CAAC;AAEY,QAAA,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;AACpC,QAAA,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;AACtC,QAAA,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;AAChD,QAAA,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC"}
|
||||
9
node_modules/ret/dist/sets.d.ts
generated
vendored
Normal file
9
node_modules/ret/dist/sets.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Set } from './types';
|
||||
export declare type SetFunc = () => Set;
|
||||
export declare const words: SetFunc;
|
||||
export declare const notWords: SetFunc;
|
||||
export declare const ints: SetFunc;
|
||||
export declare const notInts: SetFunc;
|
||||
export declare const whitespace: SetFunc;
|
||||
export declare const notWhitespace: SetFunc;
|
||||
export declare const anyChar: SetFunc;
|
||||
43
node_modules/ret/dist/sets.js
generated
vendored
Normal file
43
node_modules/ret/dist/sets.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.anyChar = exports.notWhitespace = exports.whitespace = exports.notInts = exports.ints = exports.notWords = exports.words = void 0;
|
||||
const types_1 = require("./types");
|
||||
const INTS = () => [{ type: types_1.types.RANGE, from: 48, to: 57 }];
|
||||
const WORDS = () => [
|
||||
{ type: types_1.types.CHAR, value: 95 },
|
||||
{ type: types_1.types.RANGE, from: 97, to: 122 },
|
||||
{ type: types_1.types.RANGE, from: 65, to: 90 },
|
||||
{ type: types_1.types.RANGE, from: 48, to: 57 },
|
||||
];
|
||||
const WHITESPACE = () => [
|
||||
{ type: types_1.types.CHAR, value: 9 },
|
||||
{ type: types_1.types.CHAR, value: 10 },
|
||||
{ type: types_1.types.CHAR, value: 11 },
|
||||
{ type: types_1.types.CHAR, value: 12 },
|
||||
{ type: types_1.types.CHAR, value: 13 },
|
||||
{ type: types_1.types.CHAR, value: 32 },
|
||||
{ type: types_1.types.CHAR, value: 160 },
|
||||
{ type: types_1.types.CHAR, value: 5760 },
|
||||
{ type: types_1.types.RANGE, from: 8192, to: 8202 },
|
||||
{ type: types_1.types.CHAR, value: 8232 },
|
||||
{ type: types_1.types.CHAR, value: 8233 },
|
||||
{ type: types_1.types.CHAR, value: 8239 },
|
||||
{ type: types_1.types.CHAR, value: 8287 },
|
||||
{ type: types_1.types.CHAR, value: 12288 },
|
||||
{ type: types_1.types.CHAR, value: 65279 },
|
||||
];
|
||||
const NOTANYCHAR = () => [
|
||||
{ type: types_1.types.CHAR, value: 10 },
|
||||
{ type: types_1.types.CHAR, value: 13 },
|
||||
{ type: types_1.types.CHAR, value: 8232 },
|
||||
{ type: types_1.types.CHAR, value: 8233 },
|
||||
];
|
||||
// Predefined class objects.
|
||||
exports.words = () => ({ type: types_1.types.SET, set: WORDS(), not: false });
|
||||
exports.notWords = () => ({ type: types_1.types.SET, set: WORDS(), not: true });
|
||||
exports.ints = () => ({ type: types_1.types.SET, set: INTS(), not: false });
|
||||
exports.notInts = () => ({ type: types_1.types.SET, set: INTS(), not: true });
|
||||
exports.whitespace = () => ({ type: types_1.types.SET, set: WHITESPACE(), not: false });
|
||||
exports.notWhitespace = () => ({ type: types_1.types.SET, set: WHITESPACE(), not: true });
|
||||
exports.anyChar = () => ({ type: types_1.types.SET, set: NOTANYCHAR(), not: true });
|
||||
//# sourceMappingURL=sets.js.map
|
||||
1
node_modules/ret/dist/sets.js.map
generated
vendored
Normal file
1
node_modules/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GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACzE,QAAA,IAAI,GAAY,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;AACrE,QAAA,OAAO,GAAY,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACvE,QAAA,UAAU,GAAY,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;AACjF,QAAA,aAAa,GAAY,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACnF,QAAA,OAAO,GAAY,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,aAAK,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC"}
|
||||
8
node_modules/ret/dist/tokenizer.d.ts
generated
vendored
Normal file
8
node_modules/ret/dist/tokenizer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Root } from './types';
|
||||
/**
|
||||
* Tokenizes a regular expression (that is currently a string)
|
||||
* @param {string} regexpStr String of regular expression to be tokenized
|
||||
*
|
||||
* @returns {Root}
|
||||
*/
|
||||
export declare const tokenizer: (regexpStr: string) => Root;
|
||||
323
node_modules/ret/dist/tokenizer.js
generated
vendored
Normal file
323
node_modules/ret/dist/tokenizer.js
generated
vendored
Normal file
@@ -0,0 +1,323 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tokenizer = void 0;
|
||||
const util = __importStar(require("./util"));
|
||||
const types_1 = require("./types");
|
||||
const sets = __importStar(require("./sets"));
|
||||
/**
|
||||
* Tokenizes a regular expression (that is currently a string)
|
||||
* @param {string} regexpStr String of regular expression to be tokenized
|
||||
*
|
||||
* @returns {Root}
|
||||
*/
|
||||
exports.tokenizer = (regexpStr) => {
|
||||
let i = 0, c;
|
||||
let start = { type: types_1.types.ROOT, stack: [] };
|
||||
// Keep track of last clause/group and stack.
|
||||
let lastGroup = start;
|
||||
let last = start.stack;
|
||||
let groupStack = [];
|
||||
let referenceQueue = [];
|
||||
let groupCount = 0;
|
||||
const repeatErr = (col) => {
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Nothing to repeat at column ${col - 1}`);
|
||||
};
|
||||
// Decode a few escaped characters.
|
||||
let str = util.strToChars(regexpStr);
|
||||
// Iterate through each character in string.
|
||||
while (i < str.length) {
|
||||
switch (c = str[i++]) {
|
||||
// Handle escaped characters, inclues a few sets.
|
||||
case '\\':
|
||||
if (i === str.length) {
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: \\ at end of pattern`);
|
||||
}
|
||||
switch (c = str[i++]) {
|
||||
case 'b':
|
||||
last.push({ type: types_1.types.POSITION, value: 'b' });
|
||||
break;
|
||||
case 'B':
|
||||
last.push({ type: types_1.types.POSITION, value: 'B' });
|
||||
break;
|
||||
case 'w':
|
||||
last.push(sets.words());
|
||||
break;
|
||||
case 'W':
|
||||
last.push(sets.notWords());
|
||||
break;
|
||||
case 'd':
|
||||
last.push(sets.ints());
|
||||
break;
|
||||
case 'D':
|
||||
last.push(sets.notInts());
|
||||
break;
|
||||
case 's':
|
||||
last.push(sets.whitespace());
|
||||
break;
|
||||
case 'S':
|
||||
last.push(sets.notWhitespace());
|
||||
break;
|
||||
default:
|
||||
// Check if c is integer.
|
||||
// In which case it's a reference.
|
||||
if (/\d/.test(c)) {
|
||||
let digits = c;
|
||||
while (i < str.length && /\d/.test(str[i])) {
|
||||
digits += str[i++];
|
||||
}
|
||||
let value = parseInt(digits, 10);
|
||||
const reference = { type: types_1.types.REFERENCE, value };
|
||||
last.push(reference);
|
||||
referenceQueue.push({ reference, stack: last, index: last.length - 1 });
|
||||
// Escaped character.
|
||||
}
|
||||
else {
|
||||
last.push({ type: types_1.types.CHAR, value: c.charCodeAt(0) });
|
||||
}
|
||||
}
|
||||
break;
|
||||
// Positionals.
|
||||
case '^':
|
||||
last.push({ type: types_1.types.POSITION, value: '^' });
|
||||
break;
|
||||
case '$':
|
||||
last.push({ type: types_1.types.POSITION, value: '$' });
|
||||
break;
|
||||
// Handle custom sets.
|
||||
case '[': {
|
||||
// Check if this class is 'anti' i.e. [^abc].
|
||||
let not;
|
||||
if (str[i] === '^') {
|
||||
not = true;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
not = false;
|
||||
}
|
||||
// Get all the characters in class.
|
||||
let classTokens = util.tokenizeClass(str.slice(i), regexpStr);
|
||||
// Increase index by length of class.
|
||||
i += classTokens[1];
|
||||
last.push({
|
||||
type: types_1.types.SET,
|
||||
set: classTokens[0],
|
||||
not,
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Class of any character except \n.
|
||||
case '.':
|
||||
last.push(sets.anyChar());
|
||||
break;
|
||||
// Push group onto stack.
|
||||
case '(': {
|
||||
// Create group.
|
||||
let group = {
|
||||
type: types_1.types.GROUP,
|
||||
stack: [],
|
||||
remember: true,
|
||||
};
|
||||
// If 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;
|
||||
// Match if not followed by.
|
||||
}
|
||||
else if (c === '!') {
|
||||
group.notFollowedBy = true;
|
||||
}
|
||||
else if (c !== ':') {
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Invalid group, character '${c}'` +
|
||||
` after '?' at column ${i - 1}`);
|
||||
}
|
||||
group.remember = false;
|
||||
}
|
||||
else {
|
||||
groupCount += 1;
|
||||
}
|
||||
// Insert subgroup into current group stack.
|
||||
last.push(group);
|
||||
// Remember the current group for when the group closes.
|
||||
groupStack.push(lastGroup);
|
||||
// Make this new group the current group.
|
||||
lastGroup = group;
|
||||
last = group.stack;
|
||||
break;
|
||||
}
|
||||
// Pop group out of stack.
|
||||
case ')':
|
||||
if (groupStack.length === 0) {
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unmatched ) at column ${i - 1}`);
|
||||
}
|
||||
lastGroup = groupStack.pop();
|
||||
// Check if this group has a PIPE.
|
||||
// To get back the correct last stack.
|
||||
last = lastGroup.options ?
|
||||
lastGroup.options[lastGroup.options.length - 1] :
|
||||
lastGroup.stack;
|
||||
break;
|
||||
// Use pipe character to give more choices.
|
||||
case '|': {
|
||||
// Create array where options are if this is the first PIPE
|
||||
// in this clause.
|
||||
if (!lastGroup.options) {
|
||||
lastGroup.options = [lastGroup.stack];
|
||||
delete lastGroup.stack;
|
||||
}
|
||||
// Create a new stack and add to options for rest of clause.
|
||||
let stack = [];
|
||||
lastGroup.options.push(stack);
|
||||
last = stack;
|
||||
break;
|
||||
}
|
||||
// Repetition.
|
||||
// For every repetition, remove last element from last stack
|
||||
// then insert back a RANGE object.
|
||||
// This design is chosen because there could be more than
|
||||
// one repetition symbols in a regex i.e. `a?+{2,3}`.
|
||||
case '{': {
|
||||
let rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max;
|
||||
if (rs !== null) {
|
||||
if (last.length === 0) {
|
||||
repeatErr(i);
|
||||
}
|
||||
min = parseInt(rs[1], 10);
|
||||
max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min;
|
||||
i += rs[0].length;
|
||||
last.push({
|
||||
type: types_1.types.REPETITION,
|
||||
min,
|
||||
max,
|
||||
value: last.pop(),
|
||||
});
|
||||
}
|
||||
else {
|
||||
last.push({
|
||||
type: types_1.types.CHAR,
|
||||
value: 123,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '?':
|
||||
if (last.length === 0) {
|
||||
repeatErr(i);
|
||||
}
|
||||
last.push({
|
||||
type: types_1.types.REPETITION,
|
||||
min: 0,
|
||||
max: 1,
|
||||
value: last.pop(),
|
||||
});
|
||||
break;
|
||||
case '+':
|
||||
if (last.length === 0) {
|
||||
repeatErr(i);
|
||||
}
|
||||
last.push({
|
||||
type: types_1.types.REPETITION,
|
||||
min: 1,
|
||||
max: Infinity,
|
||||
value: last.pop(),
|
||||
});
|
||||
break;
|
||||
case '*':
|
||||
if (last.length === 0) {
|
||||
repeatErr(i);
|
||||
}
|
||||
last.push({
|
||||
type: types_1.types.REPETITION,
|
||||
min: 0,
|
||||
max: Infinity,
|
||||
value: last.pop(),
|
||||
});
|
||||
break;
|
||||
// Default is a character that is not `\[](){}?+*^$`.
|
||||
default:
|
||||
last.push({
|
||||
type: types_1.types.CHAR,
|
||||
value: c.charCodeAt(0),
|
||||
});
|
||||
}
|
||||
}
|
||||
// Check if any groups have not been closed.
|
||||
if (groupStack.length !== 0) {
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated group`);
|
||||
}
|
||||
updateReferences(referenceQueue, groupCount);
|
||||
return start;
|
||||
};
|
||||
/**
|
||||
* This is a side effecting function that changes references to chars
|
||||
* if there are not enough capturing groups to reference
|
||||
* See: https://github.com/fent/ret.js/pull/39#issuecomment-1006475703
|
||||
* See: https://github.com/fent/ret.js/issues/38
|
||||
* @param {(Reference | Char)[]} referenceQueue
|
||||
* @param {number} groupCount
|
||||
* @returns {void}
|
||||
*/
|
||||
function updateReferences(referenceQueue, groupCount) {
|
||||
// Note: We go through the queue in reverse order so
|
||||
// that index we use is correct even if we have to add
|
||||
// multiple tokens to one stack
|
||||
for (const elem of referenceQueue.reverse()) {
|
||||
if (groupCount < elem.reference.value) {
|
||||
// If there is nothing to reference then turn this into a char token
|
||||
elem.reference.type = types_1.types.CHAR;
|
||||
const valueString = elem.reference.value.toString();
|
||||
elem.reference.value = parseInt(valueString, 8);
|
||||
// If the number is not octal then we need to create multiple tokens
|
||||
// https://github.com/fent/ret.js/pull/39#issuecomment-1008229226
|
||||
if (!/^[0-7]+$/.test(valueString)) {
|
||||
let i = 0;
|
||||
while (valueString[i] !== '8' && valueString[i] !== '9') {
|
||||
i += 1;
|
||||
}
|
||||
if (i === 0) {
|
||||
// Handling case when escaped number starts with 8 or 9
|
||||
elem.reference.value = valueString.charCodeAt(0);
|
||||
i += 1;
|
||||
}
|
||||
else {
|
||||
// If the escaped number does not start with 8 or 9, then all
|
||||
// 0-7 digits before the first 8/9 form the first character code
|
||||
// see: https://github.com/fent/ret.js/pull/39#discussion_r780747085
|
||||
elem.reference.value = parseInt(valueString.slice(0, i), 8);
|
||||
}
|
||||
if (valueString.length > i) {
|
||||
const tail = elem.stack.splice(elem.index + 1);
|
||||
for (const char of valueString.slice(i)) {
|
||||
elem.stack.push({
|
||||
type: types_1.types.CHAR,
|
||||
value: char.charCodeAt(0),
|
||||
});
|
||||
}
|
||||
elem.stack.push(...tail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=tokenizer.js.map
|
||||
1
node_modules/ret/dist/tokenizer.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/tokenizer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
3
node_modules/ret/dist/types/index.d.ts
generated
vendored
Normal file
3
node_modules/ret/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './tokens';
|
||||
export * from './types';
|
||||
export * from './set-lookup';
|
||||
16
node_modules/ret/dist/types/index.js
generated
vendored
Normal file
16
node_modules/ret/dist/types/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./tokens"), exports);
|
||||
__exportStar(require("./types"), exports);
|
||||
__exportStar(require("./set-lookup"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/ret/dist/types/index.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/types/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,+CAA6B"}
|
||||
8
node_modules/ret/dist/types/set-lookup.d.ts
generated
vendored
Normal file
8
node_modules/ret/dist/types/set-lookup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* The number of elements in a set lookup, and a
|
||||
* function that returns the lookup.
|
||||
*/
|
||||
export interface SetLookup {
|
||||
len: number;
|
||||
lookup: () => Record<string | number, boolean>;
|
||||
}
|
||||
3
node_modules/ret/dist/types/set-lookup.js
generated
vendored
Normal file
3
node_modules/ret/dist/types/set-lookup.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=set-lookup.js.map
|
||||
1
node_modules/ret/dist/types/set-lookup.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/types/set-lookup.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"set-lookup.js","sourceRoot":"","sources":["../../lib/types/set-lookup.ts"],"names":[],"mappings":""}
|
||||
40
node_modules/ret/dist/types/tokens.d.ts
generated
vendored
Normal file
40
node_modules/ret/dist/types/tokens.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { types } from './types';
|
||||
declare type Base<T, K> = {
|
||||
type: T;
|
||||
} & K;
|
||||
declare type ValueType<T, K> = Base<T, {
|
||||
value: K;
|
||||
}>;
|
||||
export declare type Root = Base<types.ROOT, {
|
||||
stack?: Token[];
|
||||
options?: Token[][];
|
||||
flags?: string[];
|
||||
}>;
|
||||
export declare type Group = Base<types.GROUP, {
|
||||
stack?: Token[];
|
||||
options?: Token[][];
|
||||
remember: boolean;
|
||||
followedBy?: boolean;
|
||||
notFollowedBy?: boolean;
|
||||
lookBehind?: boolean;
|
||||
}>;
|
||||
export declare type Set = Base<types.SET, {
|
||||
set: SetTokens;
|
||||
not: boolean;
|
||||
}>;
|
||||
export declare type Range = Base<types.RANGE, {
|
||||
from: number;
|
||||
to: number;
|
||||
}>;
|
||||
export declare type Repetition = Base<types.REPETITION, {
|
||||
min: number;
|
||||
max: number;
|
||||
value: Token;
|
||||
}>;
|
||||
export declare type Position = ValueType<types.POSITION, '$' | '^' | 'b' | 'B'>;
|
||||
export declare type Reference = ValueType<types.REFERENCE, number>;
|
||||
export declare type Char = ValueType<types.CHAR, number>;
|
||||
export declare type Token = Group | Position | Set | Range | Repetition | Reference | Char;
|
||||
export declare type Tokens = Root | Token;
|
||||
export declare type SetTokens = (Range | Char | Set)[];
|
||||
export {};
|
||||
3
node_modules/ret/dist/types/tokens.js
generated
vendored
Normal file
3
node_modules/ret/dist/types/tokens.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=tokens.js.map
|
||||
1
node_modules/ret/dist/types/tokens.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/types/tokens.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../lib/types/tokens.ts"],"names":[],"mappings":""}
|
||||
10
node_modules/ret/dist/types/types.d.ts
generated
vendored
Normal file
10
node_modules/ret/dist/types/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export declare enum types {
|
||||
ROOT = 0,
|
||||
GROUP = 1,
|
||||
POSITION = 2,
|
||||
SET = 3,
|
||||
RANGE = 4,
|
||||
REPETITION = 5,
|
||||
REFERENCE = 6,
|
||||
CHAR = 7
|
||||
}
|
||||
15
node_modules/ret/dist/types/types.js
generated
vendored
Normal file
15
node_modules/ret/dist/types/types.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.types = void 0;
|
||||
var types;
|
||||
(function (types) {
|
||||
types[types["ROOT"] = 0] = "ROOT";
|
||||
types[types["GROUP"] = 1] = "GROUP";
|
||||
types[types["POSITION"] = 2] = "POSITION";
|
||||
types[types["SET"] = 3] = "SET";
|
||||
types[types["RANGE"] = 4] = "RANGE";
|
||||
types[types["REPETITION"] = 5] = "REPETITION";
|
||||
types[types["REFERENCE"] = 6] = "REFERENCE";
|
||||
types[types["CHAR"] = 7] = "CHAR";
|
||||
})(types = exports.types || (exports.types = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
node_modules/ret/dist/types/types.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/types/types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,KASX;AATD,WAAY,KAAK;IACf,iCAAI,CAAA;IACJ,mCAAK,CAAA;IACL,yCAAQ,CAAA;IACR,+BAAG,CAAA;IACH,mCAAK,CAAA;IACL,6CAAU,CAAA;IACV,2CAAS,CAAA;IACT,iCAAI,CAAA;AACN,CAAC,EATW,KAAK,GAAL,aAAK,KAAL,aAAK,QAShB"}
|
||||
18
node_modules/ret/dist/util.d.ts
generated
vendored
Normal file
18
node_modules/ret/dist/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { SetTokens } from './types';
|
||||
/**
|
||||
* Finds character representations in str and convert all to
|
||||
* their respective characters.
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
export declare const strToChars: (str: string) => string;
|
||||
/**
|
||||
* Turns class into tokens
|
||||
* reads str until it encounters a ] not preceeded by a \
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {string} regexpStr
|
||||
* @returns {Array.<Array.<Object>, number>}
|
||||
*/
|
||||
export declare const tokenizeClass: (str: string, regexpStr: string) => [SetTokens, number];
|
||||
82
node_modules/ret/dist/util.js
generated
vendored
Normal file
82
node_modules/ret/dist/util.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tokenizeClass = exports.strToChars = void 0;
|
||||
const types_1 = require("./types");
|
||||
const sets = __importStar(require("./sets"));
|
||||
const CTRL = '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?';
|
||||
/**
|
||||
* Finds character representations in str and convert all to
|
||||
* their respective characters.
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
exports.strToChars = (str) => {
|
||||
const charsRegex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;
|
||||
return str.replace(charsRegex, (s, b, lbs, a16, b16, dctrl, eslsh) => {
|
||||
if (lbs) {
|
||||
return s;
|
||||
}
|
||||
let code = b ? 8 :
|
||||
a16 ? parseInt(a16, 16) :
|
||||
b16 ? parseInt(b16, 16) :
|
||||
dctrl ? CTRL.indexOf(dctrl) : {
|
||||
0: 0,
|
||||
t: 9,
|
||||
n: 10,
|
||||
v: 11,
|
||||
f: 12,
|
||||
r: 13,
|
||||
}[eslsh];
|
||||
let c = String.fromCharCode(code);
|
||||
// Escape special regex characters.
|
||||
return /[[\]{}^$.|?*+()]/.test(c) ? `\\${c}` : c;
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Turns class into tokens
|
||||
* reads str until it encounters a ] not preceeded by a \
|
||||
*
|
||||
* @param {string} str
|
||||
* @param {string} regexpStr
|
||||
* @returns {Array.<Array.<Object>, number>}
|
||||
*/
|
||||
exports.tokenizeClass = (str, regexpStr) => {
|
||||
var _a, _b, _c, _d, _e, _f, _g;
|
||||
let tokens = [], rs, c;
|
||||
const regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(((?:\\)])|(((?:\\)?([^\]])))))|(\])|(?:\\)?([^])/g;
|
||||
while ((rs = regexp.exec(str)) !== null) {
|
||||
const p = (_g = (_f = (_e = (_d = (_c = (_b = (_a = (rs[1] && sets.words())) !== null && _a !== void 0 ? _a : (rs[2] && sets.ints())) !== null && _b !== void 0 ? _b : (rs[3] && sets.whitespace())) !== null && _c !== void 0 ? _c : (rs[4] && sets.notWords())) !== null && _d !== void 0 ? _d : (rs[5] && sets.notInts())) !== null && _e !== void 0 ? _e : (rs[6] && sets.notWhitespace())) !== null && _f !== void 0 ? _f : (rs[7] && {
|
||||
type: types_1.types.RANGE,
|
||||
from: (rs[8] || rs[9]).charCodeAt(0),
|
||||
to: (c = rs[10]).charCodeAt(c.length - 1),
|
||||
})) !== null && _g !== void 0 ? _g : ((c = rs[16]) && { type: types_1.types.CHAR, value: c.charCodeAt(0) });
|
||||
if (p) {
|
||||
tokens.push(p);
|
||||
}
|
||||
else {
|
||||
return [tokens, regexp.lastIndex];
|
||||
}
|
||||
}
|
||||
throw new SyntaxError(`Invalid regular expression: /${regexpStr}/: Unterminated character class`);
|
||||
};
|
||||
//# sourceMappingURL=util.js.map
|
||||
1
node_modules/ret/dist/util.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/util.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../lib/util.ts"],"names":[],"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CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;SACnC;KACF;IACD,MAAM,IAAI,WAAW,CAAC,gCAAgC,SAAS,iCAAiC,CAAC,CAAC;AACpG,CAAC,CAAC"}
|
||||
14
node_modules/ret/dist/write-set-tokens.d.ts
generated
vendored
Normal file
14
node_modules/ret/dist/write-set-tokens.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Set } from './types';
|
||||
/**
|
||||
* Takes character code and returns character to be displayed in a set
|
||||
* @param {number} charCode Character code of set element
|
||||
* @returns {string} The string for the sets character
|
||||
*/
|
||||
export declare function setChar(charCode: number): string;
|
||||
/**
|
||||
* Writes the tokens for a set
|
||||
* @param {Set} set The set to display
|
||||
* @param {boolean} isNested Whether the token is nested inside another set token
|
||||
* @returns {string} The tokens for the set
|
||||
*/
|
||||
export declare function writeSetTokens(set: Set, isNested?: boolean): string;
|
||||
108
node_modules/ret/dist/write-set-tokens.js
generated
vendored
Normal file
108
node_modules/ret/dist/write-set-tokens.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.writeSetTokens = exports.setChar = void 0;
|
||||
const types_1 = require("./types");
|
||||
const sets = __importStar(require("./sets-lookup"));
|
||||
/**
|
||||
* Takes character code and returns character to be displayed in a set
|
||||
* @param {number} charCode Character code of set element
|
||||
* @returns {string} The string for the sets character
|
||||
*/
|
||||
function setChar(charCode) {
|
||||
return charCode === 94 ? '\\^' :
|
||||
charCode === 92 ? '\\\\' :
|
||||
charCode === 93 ? '\\]' :
|
||||
charCode === 45 ? '\\-' :
|
||||
String.fromCharCode(charCode);
|
||||
}
|
||||
exports.setChar = setChar;
|
||||
/**
|
||||
* Test if a character set matches a 'set-lookup'
|
||||
* @param {SetTokens} set The set to be tested
|
||||
* @param {SetLookup} param The predefined 'set-lookup' & the number of elements in the lookup
|
||||
* @returns {boolean} True if the character set corresponds to the 'set-lookup'
|
||||
*/
|
||||
function isSameSet(set, { lookup, len }) {
|
||||
// If the set and the lookup are not of the same length
|
||||
// then we immediately know that the lookup will be false
|
||||
if (len !== set.length) {
|
||||
return false;
|
||||
}
|
||||
const map = lookup();
|
||||
for (const elem of set) {
|
||||
if (elem.type === types_1.types.SET) {
|
||||
return false;
|
||||
}
|
||||
const key = elem.type === types_1.types.CHAR ? elem.value : `${elem.from}-${elem.to}`;
|
||||
if (map[key]) {
|
||||
map[key] = false;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Writes the tokens for a set
|
||||
* @param {Set} set The set to display
|
||||
* @param {boolean} isNested Whether the token is nested inside another set token
|
||||
* @returns {string} The tokens for the set
|
||||
*/
|
||||
function writeSetTokens(set, isNested = false) {
|
||||
if (isSameSet(set.set, sets.INTS)) {
|
||||
return set.not ? '\\D' : '\\d';
|
||||
}
|
||||
if (isSameSet(set.set, sets.WORDS)) {
|
||||
return set.not ? '\\W' : '\\w';
|
||||
}
|
||||
// Notanychar is only relevant when not nested inside another set token
|
||||
if (set.not && isSameSet(set.set, sets.NOTANYCHAR)) {
|
||||
return '.';
|
||||
}
|
||||
if (isSameSet(set.set, sets.WHITESPACE)) {
|
||||
return set.not ? '\\S' : '\\s';
|
||||
}
|
||||
let tokenString = '';
|
||||
for (let i = 0; i < set.set.length; i++) {
|
||||
const subset = set.set[i];
|
||||
tokenString += writeSetToken(subset);
|
||||
}
|
||||
const contents = `${set.not ? '^' : ''}${tokenString}`;
|
||||
return isNested ? contents : `[${contents}]`;
|
||||
}
|
||||
exports.writeSetTokens = writeSetTokens;
|
||||
/**
|
||||
* Writes a token within a set
|
||||
* @param {Range | Char | Set} set The set token to display
|
||||
* @returns {string} The token as a string
|
||||
*/
|
||||
function writeSetToken(set) {
|
||||
if (set.type === types_1.types.CHAR) {
|
||||
return setChar(set.value);
|
||||
}
|
||||
else if (set.type === types_1.types.RANGE) {
|
||||
return `${setChar(set.from)}-${setChar(set.to)}`;
|
||||
}
|
||||
return writeSetTokens(set, true);
|
||||
}
|
||||
//# sourceMappingURL=write-set-tokens.js.map
|
||||
1
node_modules/ret/dist/write-set-tokens.js.map
generated
vendored
Normal file
1
node_modules/ret/dist/write-set-tokens.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"write-set-tokens.js","sourceRoot":"","sources":["../lib/write-set-tokens.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA6D;AAC7D,oDAAsC;AAGtC;;;;GAIG;AACH,SAAgB,OAAO,CAAC,QAAgB;IACtC,OAAO,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC9B,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YACxB,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBACvB,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;oBACvB,MAAM,CAAC,YAAY,CAAC,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