mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 21:33:06 +07:00
1403 lines
101 KiB
JavaScript
1403 lines
101 KiB
JavaScript
|
/**
|
||
|
* LR parser generated by the Syntax tool.
|
||
|
*
|
||
|
* https://www.npmjs.com/package/syntax-cli
|
||
|
*
|
||
|
* npm install -g syntax-cli
|
||
|
*
|
||
|
* syntax-cli --help
|
||
|
*
|
||
|
* To regenerate run:
|
||
|
*
|
||
|
* syntax-cli \
|
||
|
* --grammar ~/path-to-grammar-file \
|
||
|
* --mode <parsing-mode> \
|
||
|
* --output ~/path-to-output-parser-file.js
|
||
|
*/
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/**
|
||
|
* Matched token text.
|
||
|
*/
|
||
|
|
||
|
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||
|
|
||
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
||
|
|
||
|
var yytext = void 0;
|
||
|
|
||
|
/**
|
||
|
* Length of the matched token text.
|
||
|
*/
|
||
|
var yyleng = void 0;
|
||
|
|
||
|
/**
|
||
|
* Storage object.
|
||
|
*/
|
||
|
var yy = {};
|
||
|
|
||
|
/**
|
||
|
* Result of semantic action.
|
||
|
*/
|
||
|
var __ = void 0;
|
||
|
|
||
|
/**
|
||
|
* Result location object.
|
||
|
*/
|
||
|
var __loc = void 0;
|
||
|
|
||
|
function yyloc(start, end) {
|
||
|
if (!yy.options.captureLocations) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
// Epsilon doesn't produce location.
|
||
|
if (!start || !end) {
|
||
|
return start || end;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
startOffset: start.startOffset,
|
||
|
endOffset: end.endOffset,
|
||
|
startLine: start.startLine,
|
||
|
endLine: end.endLine,
|
||
|
startColumn: start.startColumn,
|
||
|
endColumn: end.endColumn
|
||
|
};
|
||
|
}
|
||
|
|
||
|
var EOF = '$';
|
||
|
|
||
|
/**
|
||
|
* List of productions (generated by Syntax tool).
|
||
|
*/
|
||
|
var productions = [[-1, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [0, 4, function (_1, _2, _3, _4, _1loc, _2loc, _3loc, _4loc) {
|
||
|
__loc = yyloc(_1loc, _4loc);
|
||
|
__ = Node({
|
||
|
type: 'RegExp',
|
||
|
body: _2,
|
||
|
flags: checkFlags(_4)
|
||
|
}, loc(_1loc, _4loc || _3loc));
|
||
|
}], [1, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [1, 0, function () {
|
||
|
__loc = null;__ = '';
|
||
|
}], [2, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [2, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);__ = _1 + _2;
|
||
|
}], [3, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [4, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [4, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
// Location for empty disjunction: /|/
|
||
|
var _loc = null;
|
||
|
|
||
|
if (_2loc) {
|
||
|
_loc = loc(_1loc || _2loc, _3loc || _2loc);
|
||
|
};
|
||
|
|
||
|
__ = Node({
|
||
|
type: 'Disjunction',
|
||
|
left: _1,
|
||
|
right: _3
|
||
|
}, _loc);
|
||
|
}], [5, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
if (_1.length === 0) {
|
||
|
__ = null;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (_1.length === 1) {
|
||
|
__ = Node(_1[0], __loc);
|
||
|
} else {
|
||
|
__ = Node({
|
||
|
type: 'Alternative',
|
||
|
expressions: _1
|
||
|
}, __loc);
|
||
|
}
|
||
|
}], [6, 0, function () {
|
||
|
__loc = null;__ = [];
|
||
|
}], [6, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);__ = _1.concat(_2);
|
||
|
}], [7, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Node(Object.assign({ type: 'Assertion' }, _1), __loc);
|
||
|
}], [7, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);
|
||
|
__ = _1;
|
||
|
|
||
|
if (_2) {
|
||
|
__ = Node({
|
||
|
type: 'Repetition',
|
||
|
expression: _1,
|
||
|
quantifier: _2
|
||
|
}, __loc);
|
||
|
}
|
||
|
}], [8, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = { kind: '^' };
|
||
|
}], [8, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = { kind: '$' };
|
||
|
}], [8, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = { kind: '\\b' };
|
||
|
}], [8, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = { kind: '\\B' };
|
||
|
}], [8, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = {
|
||
|
kind: 'Lookahead',
|
||
|
assertion: _2
|
||
|
};
|
||
|
}], [8, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = {
|
||
|
kind: 'Lookahead',
|
||
|
negative: true,
|
||
|
assertion: _2
|
||
|
};
|
||
|
}], [8, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = {
|
||
|
kind: 'Lookbehind',
|
||
|
assertion: _2
|
||
|
};
|
||
|
}], [8, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = {
|
||
|
kind: 'Lookbehind',
|
||
|
negative: true,
|
||
|
assertion: _2
|
||
|
};
|
||
|
}], [9, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [9, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [9, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'simple', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1.slice(1), 'simple', __loc);__.escaped = true;
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'unicode', __loc);__.isSurrogatePair = true;
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'unicode', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = UnicodeProperty(_1, __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'control', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'hex', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'oct', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = GroupRefOrDecChar(_1, __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'meta', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'meta', __loc);
|
||
|
}], [10, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = NamedGroupRefOrChars(_1, _1loc);
|
||
|
}], [11, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [11, 0], [12, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [12, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);
|
||
|
_1.greedy = false;
|
||
|
__ = _1;
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: _1,
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: _1,
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: _1,
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
var range = getRange(_1);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: 'Range',
|
||
|
from: range[0],
|
||
|
to: range[0],
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: 'Range',
|
||
|
from: getRange(_1)[0],
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [13, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);
|
||
|
var range = getRange(_1);
|
||
|
__ = Node({
|
||
|
type: 'Quantifier',
|
||
|
kind: 'Range',
|
||
|
from: range[0],
|
||
|
to: range[1],
|
||
|
greedy: true
|
||
|
}, __loc);
|
||
|
}], [14, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [14, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [15, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
var nameRaw = String(_1);
|
||
|
var name = decodeUnicodeGroupName(nameRaw);
|
||
|
if (namedGroups.hasOwnProperty(name)) {
|
||
|
throw new SyntaxError('Duplicate of the named group "' + name + '".');
|
||
|
}
|
||
|
|
||
|
namedGroups[name] = _1.groupNumber;
|
||
|
|
||
|
__ = Node({
|
||
|
type: 'Group',
|
||
|
capturing: true,
|
||
|
name: name,
|
||
|
nameRaw: nameRaw,
|
||
|
number: _1.groupNumber,
|
||
|
expression: _2
|
||
|
}, __loc);
|
||
|
}], [15, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = Node({
|
||
|
type: 'Group',
|
||
|
capturing: true,
|
||
|
number: _1.groupNumber,
|
||
|
expression: _2
|
||
|
}, __loc);
|
||
|
}], [16, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = Node({
|
||
|
type: 'Group',
|
||
|
capturing: false,
|
||
|
expression: _2
|
||
|
}, __loc);
|
||
|
}], [17, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = Node({
|
||
|
type: 'CharacterClass',
|
||
|
negative: true,
|
||
|
expressions: _2
|
||
|
}, __loc);
|
||
|
}], [17, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
|
||
|
__loc = yyloc(_1loc, _3loc);
|
||
|
__ = Node({
|
||
|
type: 'CharacterClass',
|
||
|
expressions: _2
|
||
|
}, __loc);
|
||
|
}], [18, 0, function () {
|
||
|
__loc = null;__ = [];
|
||
|
}], [18, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [19, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = [_1];
|
||
|
}], [19, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);__ = [_1].concat(_2);
|
||
|
}], [19, 4, function (_1, _2, _3, _4, _1loc, _2loc, _3loc, _4loc) {
|
||
|
__loc = yyloc(_1loc, _4loc);
|
||
|
checkClassRange(_1, _3);
|
||
|
|
||
|
__ = [Node({
|
||
|
type: 'ClassRange',
|
||
|
from: _1,
|
||
|
to: _3
|
||
|
}, loc(_1loc, _3loc))];
|
||
|
|
||
|
if (_4) {
|
||
|
__ = __.concat(_4);
|
||
|
}
|
||
|
}], [20, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [20, 2, function (_1, _2, _1loc, _2loc) {
|
||
|
__loc = yyloc(_1loc, _2loc);__ = [_1].concat(_2);
|
||
|
}], [20, 4, function (_1, _2, _3, _4, _1loc, _2loc, _3loc, _4loc) {
|
||
|
__loc = yyloc(_1loc, _4loc);
|
||
|
checkClassRange(_1, _3);
|
||
|
|
||
|
__ = [Node({
|
||
|
type: 'ClassRange',
|
||
|
from: _1,
|
||
|
to: _3
|
||
|
}, loc(_1loc, _3loc))];
|
||
|
|
||
|
if (_4) {
|
||
|
__ = __.concat(_4);
|
||
|
}
|
||
|
}], [21, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'simple', __loc);
|
||
|
}], [21, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [22, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = _1;
|
||
|
}], [22, 1, function (_1, _1loc) {
|
||
|
__loc = yyloc(_1loc, _1loc);__ = Char(_1, 'meta', __loc);
|
||
|
}]];
|
||
|
|
||
|
/**
|
||
|
* Encoded tokens map.
|
||
|
*/
|
||
|
var tokens = { "SLASH": "23", "CHAR": "24", "BAR": "25", "BOS": "26", "EOS": "27", "ESC_b": "28", "ESC_B": "29", "POS_LA_ASSERT": "30", "R_PAREN": "31", "NEG_LA_ASSERT": "32", "POS_LB_ASSERT": "33", "NEG_LB_ASSERT": "34", "ESC_CHAR": "35", "U_CODE_SURROGATE": "36", "U_CODE": "37", "U_PROP_VALUE_EXP": "38", "CTRL_CH": "39", "HEX_CODE": "40", "OCT_CODE": "41", "DEC_CODE": "42", "META_CHAR": "43", "ANY": "44", "NAMED_GROUP_REF": "45", "Q_MARK": "46", "STAR": "47", "PLUS": "48", "RANGE_EXACT": "49", "RANGE_OPEN": "50", "RANGE_CLOSED": "51", "NAMED_CAPTURE_GROUP": "52", "L_PAREN": "53", "NON_CAPTURE_GROUP": "54", "NEG_CLASS": "55", "R_BRACKET": "56", "L_BRACKET": "57", "DASH": "58", "$": "59" };
|
||
|
|
||
|
/**
|
||
|
* Parsing table (generated by Syntax tool).
|
||
|
*/
|
||
|
var table = [{ "0": 1, "23": "s2" }, { "59": "acc" }, { "3": 3, "4": 4, "5": 5, "6": 6, "23": "r10", "24": "r10", "25": "r10", "26": "r10", "27": "r10", "28": "r10", "29": "r10", "30": "r10", "32": "r10", "33": "r10", "34": "r10", "35": "r10", "36": "r10", "37": "r10", "38": "r10", "39": "r10", "40": "r10", "41": "r10", "42": "r10", "43": "r10", "44": "r10", "45": "r10", "52": "r10", "53": "r10", "54": "r10", "55": "r10", "57": "r10" }, { "23": "s7" }, { "23": "r6", "25": "s12" }, { "23": "r7", "25": "r7", "31": "r7" }, { "7": 14, "8": 15, "9": 16, "10": 25, "14": 27, "15": 42, "16": 43, "17": 26, "23": "r9", "24": "s28", "25": "r9", "26": "s17", "27": "s18", "28": "s19", "29": "s20", "30": "s21", "31": "r9", "32": "s22", "33": "s23", "34": "s24", "35": "s29", "36": "s30", "37": "s31", "38": "s32", "39": "s33", "40": "s34", "41": "s35", "42": "s36", "43": "s37", "44": "s38", "45": "s39", "52": "s44", "53": "s45", "54": "s46", "55": "s40", "57": "s41" }, { "1": 8, "2": 9, "24": "s10", "59": "r3" }, { "59": "r1" }, { "24": "s11", "59": "r2" }, { "24": "r4", "59": "r4" }, { "24": "r5", "59": "r5" }, { "5": 13, "6": 6, "23": "r10", "24": "r10", "25": "r10", "26": "r10", "27": "r10", "28": "r10", "29": "r10", "30": "r10", "31": "r10", "32": "r10", "33": "r10", "34": "r10", "35": "r10", "36": "r10", "37": "r10", "38": "r10", "39": "r10", "40": "r10", "41": "r10", "42": "r10", "43": "r10", "44": "r10", "45": "r10", "52": "r10", "53": "r10", "54": "r10", "55": "r10", "57": "r10" }, { "23": "r8", "25": "r8", "31": "r8" }, { "23": "r11", "24": "r11", "25": "r11", "26": "r11", "27": "r11", "28": "r11", "29": "r11", "30": "r11", "31": "r11", "32": "r11", "33": "r11", "34": "r11", "35": "r11", "36": "r11", "37": "r11", "38": "r11", "39": "r11", "40": "r11", "41": "r11", "42": "r11", "43": "r11", "44": "r11", "45": "r11", "52": "r11", "53": "r11", "54": "r11", "55": "r11", "57": "r11" }, { "23": "r12", "24": "r12", "25": "r12", "26": "r12", "27": "r12", "28": "r12", "29": "r12", "30": "r12", "31": "r12", "32": "r12", "33": "r12", "34": "r12", "35": "r12", "36": "r12", "37": "r12", "38": "r12", "39": "r12", "40": "r12", "41": "r12", "42": "r12", "43": "r12", "44": "r12", "45": "r12", "52": "r12", "53": "r12", "54": "r12", "55": "r12", "57": "r12" }, { "11": 47, "12": 48, "13": 49, "23": "r38", "24": "r38", "25": "r38", "26": "r38", "27": "r38", "28": "r38", "29": "r38", "30": "r38", "31": "r38", "32": "r38", "33": "r38", "34": "r38", "35": "r38", "36": "r38", "37": "r38", "38": "r38", "39": "r38", "40": "r38", "41": "r38", "42": "r38", "43": "r38", "44": "r38", "45": "r38", "46": "s52", "47": "s50", "48": "s51", "49": "s53", "50": "s54", "51": "s55", "52": "r38", "53": "r38", "54": "r38", "55": "r38", "57": "r38" }, { "23": "r14", "24": "r14", "25": "r14", "26": "r14", "27": "r14", "28": "r14", "29": "r14", "30": "r14", "31": "r14", "32": "r14", "33": "r14", "34": "r14", "35": "r14", "36": "r14", "37": "r14", "38": "r14", "39": "r14", "40": "r14", "41": "r14", "42": "r14", "43": "r14", "44": "r14", "45": "r14", "52": "r14", "53": "r14", "54": "r14", "55": "r14", "57": "r14" }, { "23": "r15", "24": "r15", "25": "r15", "26": "r15", "27": "r15", "28": "r15", "29": "r15", "30": "r15", "31": "r15", "32": "r15", "33": "r15", "34": "r15", "35": "r15", "36": "r15", "37": "r15", "38": "r15", "39": "r15", "40": "r15", "41": "r15", "42": "r15", "43": "r15", "44": "r15", "45": "r15", "52": "r15", "53": "r15", "54": "r15", "55": "r15", "57": "r15" }, { "23": "r16", "24": "r16", "25": "r16", "26": "r16", "27": "r16", "28": "r16", "29": "r16", "30": "r16", "31": "r16", "32": "r16", "33": "r16", "34": "r16", "35": "r16", "36": "r16", "37": "r16", "38": "r16", "39": "r16", "40": "r16", "41": "r16", "42": "r16", "43": "r16", "44": "r16", "45": "r16", "52": "r16", "53": "r16", "54": "r16", "55": "r16", "57": "r16" }, { "23": "r17", "24": "r17", "25": "r17", "26": "r17", "27": "r17", "28": "r17", "29": "r17", "30": "r17", "31": "r17", "32": "r17", "33": "r17", "34": "r17", "35": "r17", "36": "r17", "37": "r17", "38": "r17", "39": "r17", "40": "r17", "41"
|
||
|
|
||
|
/**
|
||
|
* Parsing stack.
|
||
|
*/
|
||
|
var stack = [];
|
||
|
|
||
|
/**
|
||
|
* Tokenizer instance.
|
||
|
*/
|
||
|
var tokenizer = void 0;
|
||
|
/**
|
||
|
* Generic tokenizer used by the parser in the Syntax tool.
|
||
|
*
|
||
|
* https://www.npmjs.com/package/syntax-cli
|
||
|
*
|
||
|
* See `--custom-tokinzer` to skip this generation, and use a custom one.
|
||
|
*/
|
||
|
|
||
|
var lexRules = [[/^#[^\n]+/, function () {/* skip comments */}], [/^\s+/, function () {/* skip whitespace */}], [/^-/, function () {
|
||
|
return 'DASH';
|
||
|
}], [/^\//, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^#/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\|/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\./, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\{/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\{\d+\}/, function () {
|
||
|
return 'RANGE_EXACT';
|
||
|
}], [/^\{\d+,\}/, function () {
|
||
|
return 'RANGE_OPEN';
|
||
|
}], [/^\{\d+,\d+\}/, function () {
|
||
|
return 'RANGE_CLOSED';
|
||
|
}], [/^\\k<(([\u0041-\u005a\u0061-\u007a\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376-\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4-\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u09fc\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0af9\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60-\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0cf1-\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5-\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a-\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd-\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5-\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb0
|
||
|
var groupName = yytext.slice(3, -1);
|
||
|
validateUnicodeGroupName(groupName, this.getCurrentState());
|
||
|
return 'NAMED_GROUP_REF';
|
||
|
}], [/^\\b/, function () {
|
||
|
return 'ESC_b';
|
||
|
}], [/^\\B/, function () {
|
||
|
return 'ESC_B';
|
||
|
}], [/^\\c[a-zA-Z]/, function () {
|
||
|
return 'CTRL_CH';
|
||
|
}], [/^\\0\d{1,2}/, function () {
|
||
|
return 'OCT_CODE';
|
||
|
}], [/^\\0/, function () {
|
||
|
return 'DEC_CODE';
|
||
|
}], [/^\\\d{1,3}/, function () {
|
||
|
return 'DEC_CODE';
|
||
|
}], [/^\\u[dD][89abAB][0-9a-fA-F]{2}\\u[dD][c-fC-F][0-9a-fA-F]{2}/, function () {
|
||
|
return 'U_CODE_SURROGATE';
|
||
|
}], [/^\\u\{[0-9a-fA-F]{1,}\}/, function () {
|
||
|
return 'U_CODE';
|
||
|
}], [/^\\u[0-9a-fA-F]{4}/, function () {
|
||
|
return 'U_CODE';
|
||
|
}], [/^\\[pP]\{\w+(?:=\w+)?\}/, function () {
|
||
|
return 'U_PROP_VALUE_EXP';
|
||
|
}], [/^\\x[0-9a-fA-F]{2}/, function () {
|
||
|
return 'HEX_CODE';
|
||
|
}], [/^\\[tnrdDsSwWvf]/, function () {
|
||
|
return 'META_CHAR';
|
||
|
}], [/^\\\//, function () {
|
||
|
return 'ESC_CHAR';
|
||
|
}], [/^\\[ #]/, function () {
|
||
|
return 'ESC_CHAR';
|
||
|
}], [/^\\[\^\$\.\*\+\?\(\)\\\[\]\{\}\|\/]/, function () {
|
||
|
return 'ESC_CHAR';
|
||
|
}], [/^\\[^*?+\[()\\|]/, function () {
|
||
|
var s = this.getCurrentState();
|
||
|
if (s === 'u' || s === 'xu' || s === 'u_class') {
|
||
|
throw new SyntaxError('invalid Unicode escape ' + yytext);
|
||
|
}
|
||
|
return 'ESC_CHAR';
|
||
|
}], [/^\(/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\)/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\(\?=/, function () {
|
||
|
return 'POS_LA_ASSERT';
|
||
|
}], [/^\(\?!/, function () {
|
||
|
return 'NEG_LA_ASSERT';
|
||
|
}], [/^\(\?<=/, function () {
|
||
|
return 'POS_LB_ASSERT';
|
||
|
}], [/^\(\?<!/, function () {
|
||
|
return 'NEG_LB_ASSERT';
|
||
|
}], [/^\(\?:/, function () {
|
||
|
return 'NON_CAPTURE_GROUP';
|
||
|
}], [/^\(\?<(([\u0041-\u005a\u0061-\u007a\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376-\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4-\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08bd\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u09fc\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0af9\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60-\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0cf1-\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065-\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae-\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5-\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2-\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fef\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a-\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7c6\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd-\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5-\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab67\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb
|
||
|
yytext = yytext.slice(3, -1);
|
||
|
validateUnicodeGroupName(yytext, this.getCurrentState());
|
||
|
return 'NAMED_CAPTURE_GROUP';
|
||
|
}], [/^\(/, function () {
|
||
|
return 'L_PAREN';
|
||
|
}], [/^\)/, function () {
|
||
|
return 'R_PAREN';
|
||
|
}], [/^[*?+[^$]/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\\\]/, function () {
|
||
|
return 'ESC_CHAR';
|
||
|
}], [/^\]/, function () {
|
||
|
this.popState();return 'R_BRACKET';
|
||
|
}], [/^\^/, function () {
|
||
|
return 'BOS';
|
||
|
}], [/^\$/, function () {
|
||
|
return 'EOS';
|
||
|
}], [/^\*/, function () {
|
||
|
return 'STAR';
|
||
|
}], [/^\?/, function () {
|
||
|
return 'Q_MARK';
|
||
|
}], [/^\+/, function () {
|
||
|
return 'PLUS';
|
||
|
}], [/^\|/, function () {
|
||
|
return 'BAR';
|
||
|
}], [/^\./, function () {
|
||
|
return 'ANY';
|
||
|
}], [/^\//, function () {
|
||
|
return 'SLASH';
|
||
|
}], [/^[^*?+\[()\\|]/, function () {
|
||
|
return 'CHAR';
|
||
|
}], [/^\[\^/, function () {
|
||
|
var s = this.getCurrentState();this.pushState(s === 'u' || s === 'xu' ? 'u_class' : 'class');return 'NEG_CLASS';
|
||
|
}], [/^\[/, function () {
|
||
|
var s = this.getCurrentState();this.pushState(s === 'u' || s === 'xu' ? 'u_class' : 'class');return 'L_BRACKET';
|
||
|
}]];
|
||
|
var lexRulesByConditions = { "INITIAL": [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 23, 24, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "u": [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "xu": [0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "x": [0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 23, 24, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "u_class": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], "class": [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51] };
|
||
|
|
||
|
var EOF_TOKEN = {
|
||
|
type: EOF,
|
||
|
value: ''
|
||
|
};
|
||
|
|
||
|
tokenizer = {
|
||
|
initString: function initString(string) {
|
||
|
this._string = string;
|
||
|
this._cursor = 0;
|
||
|
|
||
|
this._states = ['INITIAL'];
|
||
|
this._tokensQueue = [];
|
||
|
|
||
|
this._currentLine = 1;
|
||
|
this._currentColumn = 0;
|
||
|
this._currentLineBeginOffset = 0;
|
||
|
|
||
|
/**
|
||
|
* Matched token location data.
|
||
|
*/
|
||
|
this._tokenStartOffset = 0;
|
||
|
this._tokenEndOffset = 0;
|
||
|
this._tokenStartLine = 1;
|
||
|
this._tokenEndLine = 1;
|
||
|
this._tokenStartColumn = 0;
|
||
|
this._tokenEndColumn = 0;
|
||
|
|
||
|
return this;
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns tokenizer states.
|
||
|
*/
|
||
|
getStates: function getStates() {
|
||
|
return this._states;
|
||
|
},
|
||
|
getCurrentState: function getCurrentState() {
|
||
|
return this._states[this._states.length - 1];
|
||
|
},
|
||
|
pushState: function pushState(state) {
|
||
|
this._states.push(state);
|
||
|
},
|
||
|
begin: function begin(state) {
|
||
|
this.pushState(state);
|
||
|
},
|
||
|
popState: function popState() {
|
||
|
if (this._states.length > 1) {
|
||
|
return this._states.pop();
|
||
|
}
|
||
|
return this._states[0];
|
||
|
},
|
||
|
getNextToken: function getNextToken() {
|
||
|
// Something was queued, return it.
|
||
|
if (this._tokensQueue.length > 0) {
|
||
|
return this.onToken(this._toToken(this._tokensQueue.shift()));
|
||
|
}
|
||
|
|
||
|
if (!this.hasMoreTokens()) {
|
||
|
return this.onToken(EOF_TOKEN);
|
||
|
}
|
||
|
|
||
|
var string = this._string.slice(this._cursor);
|
||
|
var lexRulesForState = lexRulesByConditions[this.getCurrentState()];
|
||
|
|
||
|
for (var i = 0; i < lexRulesForState.length; i++) {
|
||
|
var lexRuleIndex = lexRulesForState[i];
|
||
|
var lexRule = lexRules[lexRuleIndex];
|
||
|
|
||
|
var matched = this._match(string, lexRule[0]);
|
||
|
|
||
|
// Manual handling of EOF token (the end of string). Return it
|
||
|
// as `EOF` symbol.
|
||
|
if (string === '' && matched === '') {
|
||
|
this._cursor++;
|
||
|
}
|
||
|
|
||
|
if (matched !== null) {
|
||
|
yytext = matched;
|
||
|
yyleng = yytext.length;
|
||
|
var token = lexRule[1].call(this);
|
||
|
|
||
|
if (!token) {
|
||
|
return this.getNextToken();
|
||
|
}
|
||
|
|
||
|
// If multiple tokens are returned, save them to return
|
||
|
// on next `getNextToken` call.
|
||
|
|
||
|
if (Array.isArray(token)) {
|
||
|
var tokensToQueue = token.slice(1);
|
||
|
token = token[0];
|
||
|
if (tokensToQueue.length > 0) {
|
||
|
var _tokensQueue;
|
||
|
|
||
|
(_tokensQueue = this._tokensQueue).unshift.apply(_tokensQueue, _toConsumableArray(tokensToQueue));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return this.onToken(this._toToken(token, yytext));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (this.isEOF()) {
|
||
|
this._cursor++;
|
||
|
return EOF_TOKEN;
|
||
|
}
|
||
|
|
||
|
this.throwUnexpectedToken(string[0], this._currentLine, this._currentColumn);
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Throws default "Unexpected token" exception, showing the actual
|
||
|
* line from the source, pointing with the ^ marker to the bad token.
|
||
|
* In addition, shows `line:column` location.
|
||
|
*/
|
||
|
throwUnexpectedToken: function throwUnexpectedToken(symbol, line, column) {
|
||
|
var lineSource = this._string.split('\n')[line - 1];
|
||
|
var lineData = '';
|
||
|
|
||
|
if (lineSource) {
|
||
|
var pad = ' '.repeat(column);
|
||
|
lineData = '\n\n' + lineSource + '\n' + pad + '^\n';
|
||
|
}
|
||
|
|
||
|
throw new SyntaxError(lineData + 'Unexpected token: "' + symbol + '" ' + ('at ' + line + ':' + column + '.'));
|
||
|
},
|
||
|
getCursor: function getCursor() {
|
||
|
return this._cursor;
|
||
|
},
|
||
|
getCurrentLine: function getCurrentLine() {
|
||
|
return this._currentLine;
|
||
|
},
|
||
|
getCurrentColumn: function getCurrentColumn() {
|
||
|
return this._currentColumn;
|
||
|
},
|
||
|
_captureLocation: function _captureLocation(matched) {
|
||
|
var nlRe = /\n/g;
|
||
|
|
||
|
// Absolute offsets.
|
||
|
this._tokenStartOffset = this._cursor;
|
||
|
|
||
|
// Line-based locations, start.
|
||
|
this._tokenStartLine = this._currentLine;
|
||
|
this._tokenStartColumn = this._tokenStartOffset - this._currentLineBeginOffset;
|
||
|
|
||
|
// Extract `\n` in the matched token.
|
||
|
var nlMatch = void 0;
|
||
|
while ((nlMatch = nlRe.exec(matched)) !== null) {
|
||
|
this._currentLine++;
|
||
|
this._currentLineBeginOffset = this._tokenStartOffset + nlMatch.index + 1;
|
||
|
}
|
||
|
|
||
|
this._tokenEndOffset = this._cursor + matched.length;
|
||
|
|
||
|
// Line-based locations, end.
|
||
|
this._tokenEndLine = this._currentLine;
|
||
|
this._tokenEndColumn = this._currentColumn = this._tokenEndOffset - this._currentLineBeginOffset;
|
||
|
},
|
||
|
_toToken: function _toToken(tokenType) {
|
||
|
var yytext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
||
|
|
||
|
return {
|
||
|
// Basic data.
|
||
|
type: tokenType,
|
||
|
value: yytext,
|
||
|
|
||
|
// Location data.
|
||
|
startOffset: this._tokenStartOffset,
|
||
|
endOffset: this._tokenEndOffset,
|
||
|
startLine: this._tokenStartLine,
|
||
|
endLine: this._tokenEndLine,
|
||
|
startColumn: this._tokenStartColumn,
|
||
|
endColumn: this._tokenEndColumn
|
||
|
};
|
||
|
},
|
||
|
isEOF: function isEOF() {
|
||
|
return this._cursor === this._string.length;
|
||
|
},
|
||
|
hasMoreTokens: function hasMoreTokens() {
|
||
|
return this._cursor <= this._string.length;
|
||
|
},
|
||
|
_match: function _match(string, regexp) {
|
||
|
var matched = string.match(regexp);
|
||
|
if (matched) {
|
||
|
// Handle `\n` in the matched token to track line numbers.
|
||
|
this._captureLocation(matched[0]);
|
||
|
this._cursor += matched[0].length;
|
||
|
return matched[0];
|
||
|
}
|
||
|
return null;
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Allows analyzing, and transforming token. Default implementation
|
||
|
* just passes the token through.
|
||
|
*/
|
||
|
onToken: function onToken(token) {
|
||
|
return token;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Expose tokenizer so it can be accessed in semantic actions.
|
||
|
*/
|
||
|
yy.lexer = tokenizer;
|
||
|
yy.tokenizer = tokenizer;
|
||
|
|
||
|
/**
|
||
|
* Global parsing options. Some options can be shadowed per
|
||
|
* each `parse` call, if the optations are passed.
|
||
|
*
|
||
|
* Initalized to the `captureLocations` which is passed
|
||
|
* from the generator. Other options can be added at runtime.
|
||
|
*/
|
||
|
yy.options = {
|
||
|
captureLocations: true
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Parsing module.
|
||
|
*/
|
||
|
var yyparse = {
|
||
|
/**
|
||
|
* Sets global parsing options.
|
||
|
*/
|
||
|
setOptions: function setOptions(options) {
|
||
|
yy.options = options;
|
||
|
return this;
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns parsing options.
|
||
|
*/
|
||
|
getOptions: function getOptions() {
|
||
|
return yy.options;
|
||
|
},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Parses a string.
|
||
|
*/
|
||
|
parse: function parse(string, parseOptions) {
|
||
|
if (!tokenizer) {
|
||
|
throw new Error('Tokenizer instance wasn\'t specified.');
|
||
|
}
|
||
|
|
||
|
tokenizer.initString(string);
|
||
|
|
||
|
/**
|
||
|
* If parse options are passed, override global parse options for
|
||
|
* this call, and later restore global options.
|
||
|
*/
|
||
|
var globalOptions = yy.options;
|
||
|
if (parseOptions) {
|
||
|
yy.options = Object.assign({}, yy.options, parseOptions);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Allow callers to do setup work based on the
|
||
|
* parsing string, and passed options.
|
||
|
*/
|
||
|
yyparse.onParseBegin(string, tokenizer, yy.options);
|
||
|
|
||
|
stack.length = 0;
|
||
|
stack.push(0);
|
||
|
|
||
|
var token = tokenizer.getNextToken();
|
||
|
var shiftedToken = null;
|
||
|
|
||
|
do {
|
||
|
if (!token) {
|
||
|
// Restore options.
|
||
|
yy.options = globalOptions;
|
||
|
unexpectedEndOfInput();
|
||
|
}
|
||
|
|
||
|
var state = stack[stack.length - 1];
|
||
|
var column = tokens[token.type];
|
||
|
|
||
|
if (!table[state].hasOwnProperty(column)) {
|
||
|
yy.options = globalOptions;
|
||
|
unexpectedToken(token);
|
||
|
}
|
||
|
|
||
|
var entry = table[state][column];
|
||
|
|
||
|
// Shift action.
|
||
|
if (entry[0] === 's') {
|
||
|
var _loc2 = null;
|
||
|
|
||
|
if (yy.options.captureLocations) {
|
||
|
_loc2 = {
|
||
|
startOffset: token.startOffset,
|
||
|
endOffset: token.endOffset,
|
||
|
startLine: token.startLine,
|
||
|
endLine: token.endLine,
|
||
|
startColumn: token.startColumn,
|
||
|
endColumn: token.endColumn
|
||
|
};
|
||
|
}
|
||
|
|
||
|
shiftedToken = this.onShift(token);
|
||
|
|
||
|
stack.push({ symbol: tokens[shiftedToken.type], semanticValue: shiftedToken.value, loc: _loc2 }, Number(entry.slice(1)));
|
||
|
|
||
|
token = tokenizer.getNextToken();
|
||
|
}
|
||
|
|
||
|
// Reduce action.
|
||
|
else if (entry[0] === 'r') {
|
||
|
var productionNumber = entry.slice(1);
|
||
|
var production = productions[productionNumber];
|
||
|
var hasSemanticAction = typeof production[2] === 'function';
|
||
|
var semanticValueArgs = hasSemanticAction ? [] : null;
|
||
|
|
||
|
var locationArgs = hasSemanticAction && yy.options.captureLocations ? [] : null;
|
||
|
|
||
|
if (production[1] !== 0) {
|
||
|
var rhsLength = production[1];
|
||
|
while (rhsLength-- > 0) {
|
||
|
stack.pop();
|
||
|
var stackEntry = stack.pop();
|
||
|
|
||
|
if (hasSemanticAction) {
|
||
|
semanticValueArgs.unshift(stackEntry.semanticValue);
|
||
|
|
||
|
if (locationArgs) {
|
||
|
locationArgs.unshift(stackEntry.loc);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var reduceStackEntry = { symbol: production[0] };
|
||
|
|
||
|
if (hasSemanticAction) {
|
||
|
yytext = shiftedToken ? shiftedToken.value : null;
|
||
|
yyleng = shiftedToken ? shiftedToken.value.length : null;
|
||
|
|
||
|
var semanticActionArgs = locationArgs !== null ? semanticValueArgs.concat(locationArgs) : semanticValueArgs;
|
||
|
|
||
|
production[2].apply(production, _toConsumableArray(semanticActionArgs));
|
||
|
|
||
|
reduceStackEntry.semanticValue = __;
|
||
|
|
||
|
if (locationArgs) {
|
||
|
reduceStackEntry.loc = __loc;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var nextState = stack[stack.length - 1];
|
||
|
var symbolToReduceWith = production[0];
|
||
|
|
||
|
stack.push(reduceStackEntry, table[nextState][symbolToReduceWith]);
|
||
|
}
|
||
|
|
||
|
// Accept.
|
||
|
else if (entry === 'acc') {
|
||
|
stack.pop();
|
||
|
var parsed = stack.pop();
|
||
|
|
||
|
if (stack.length !== 1 || stack[0] !== 0 || tokenizer.hasMoreTokens()) {
|
||
|
// Restore options.
|
||
|
yy.options = globalOptions;
|
||
|
unexpectedToken(token);
|
||
|
}
|
||
|
|
||
|
if (parsed.hasOwnProperty('semanticValue')) {
|
||
|
yy.options = globalOptions;
|
||
|
yyparse.onParseEnd(parsed.semanticValue);
|
||
|
return parsed.semanticValue;
|
||
|
}
|
||
|
|
||
|
yyparse.onParseEnd();
|
||
|
|
||
|
// Restore options.
|
||
|
yy.options = globalOptions;
|
||
|
return true;
|
||
|
}
|
||
|
} while (tokenizer.hasMoreTokens() || stack.length > 1);
|
||
|
},
|
||
|
setTokenizer: function setTokenizer(customTokenizer) {
|
||
|
tokenizer = customTokenizer;
|
||
|
return yyparse;
|
||
|
},
|
||
|
getTokenizer: function getTokenizer() {
|
||
|
return tokenizer;
|
||
|
},
|
||
|
onParseBegin: function onParseBegin(string, tokenizer, options) {},
|
||
|
onParseEnd: function onParseEnd(parsed) {},
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Allows analyzing, and transforming shifted token. Default implementation
|
||
|
* just passes the token through.
|
||
|
*/
|
||
|
onShift: function onShift(token) {
|
||
|
return token;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Tracks capturing groups.
|
||
|
*/
|
||
|
var capturingGroupsCount = 0;
|
||
|
|
||
|
/**
|
||
|
* Tracks named groups.
|
||
|
*/
|
||
|
var namedGroups = {};
|
||
|
|
||
|
/**
|
||
|
* Parsing string.
|
||
|
*/
|
||
|
var parsingString = '';
|
||
|
|
||
|
yyparse.onParseBegin = function (string, lexer) {
|
||
|
parsingString = string;
|
||
|
capturingGroupsCount = 0;
|
||
|
namedGroups = {};
|
||
|
|
||
|
var lastSlash = string.lastIndexOf('/');
|
||
|
var flags = string.slice(lastSlash);
|
||
|
|
||
|
if (flags.includes('x') && flags.includes('u')) {
|
||
|
lexer.pushState('xu');
|
||
|
} else {
|
||
|
if (flags.includes('x')) {
|
||
|
lexer.pushState('x');
|
||
|
}
|
||
|
if (flags.includes('u')) {
|
||
|
lexer.pushState('u');
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* On shifting `(` remember its number to used on reduce.
|
||
|
*/
|
||
|
yyparse.onShift = function (token) {
|
||
|
if (token.type === 'L_PAREN' || token.type === 'NAMED_CAPTURE_GROUP') {
|
||
|
token.value = new String(token.value);
|
||
|
token.value.groupNumber = ++capturingGroupsCount;
|
||
|
}
|
||
|
return token;
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Extracts ranges from the range string.
|
||
|
*/
|
||
|
function getRange(text) {
|
||
|
var range = text.match(/\d+/g).map(Number);
|
||
|
|
||
|
if (Number.isFinite(range[1]) && range[1] < range[0]) {
|
||
|
throw new SyntaxError('Numbers out of order in ' + text + ' quantifier');
|
||
|
}
|
||
|
|
||
|
return range;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Checks class range
|
||
|
*/
|
||
|
function checkClassRange(from, to) {
|
||
|
if (from.kind === 'control' || to.kind === 'control' || !isNaN(from.codePoint) && !isNaN(to.codePoint) && from.codePoint > to.codePoint) {
|
||
|
throw new SyntaxError('Range ' + from.value + '-' + to.value + ' out of order in character class');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ---------------------- Unicode property -------------------------------------------
|
||
|
|
||
|
var unicodeProperties = require('../unicode/parser-unicode-properties.js');
|
||
|
|
||
|
/**
|
||
|
* Unicode property.
|
||
|
*/
|
||
|
function UnicodeProperty(matched, loc) {
|
||
|
var negative = matched[1] === 'P';
|
||
|
var separatorIdx = matched.indexOf('=');
|
||
|
|
||
|
var name = matched.slice(3, separatorIdx !== -1 ? separatorIdx : -1);
|
||
|
var value = void 0;
|
||
|
|
||
|
// General_Category allows using only value as a shorthand.
|
||
|
var isShorthand = separatorIdx === -1 && unicodeProperties.isGeneralCategoryValue(name);
|
||
|
|
||
|
// Binary propery name.
|
||
|
var isBinaryProperty = separatorIdx === -1 && unicodeProperties.isBinaryPropertyName(name);
|
||
|
|
||
|
if (isShorthand) {
|
||
|
value = name;
|
||
|
name = 'General_Category';
|
||
|
} else if (isBinaryProperty) {
|
||
|
value = name;
|
||
|
} else {
|
||
|
if (!unicodeProperties.isValidName(name)) {
|
||
|
throw new SyntaxError('Invalid unicode property name: ' + name + '.');
|
||
|
}
|
||
|
|
||
|
value = matched.slice(separatorIdx + 1, -1);
|
||
|
|
||
|
if (!unicodeProperties.isValidValue(name, value)) {
|
||
|
throw new SyntaxError('Invalid ' + name + ' unicode property value: ' + value + '.');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return Node({
|
||
|
type: 'UnicodeProperty',
|
||
|
name: name,
|
||
|
value: value,
|
||
|
negative: negative,
|
||
|
shorthand: isShorthand,
|
||
|
binary: isBinaryProperty,
|
||
|
canonicalName: unicodeProperties.getCanonicalName(name) || name,
|
||
|
canonicalValue: unicodeProperties.getCanonicalValue(value) || value
|
||
|
}, loc);
|
||
|
}
|
||
|
|
||
|
// ----------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Creates a character node.
|
||
|
*/
|
||
|
function Char(value, kind, loc) {
|
||
|
var symbol = void 0;
|
||
|
var codePoint = void 0;
|
||
|
|
||
|
switch (kind) {
|
||
|
case 'decimal':
|
||
|
{
|
||
|
codePoint = Number(value.slice(1));
|
||
|
symbol = String.fromCodePoint(codePoint);
|
||
|
break;
|
||
|
}
|
||
|
case 'oct':
|
||
|
{
|
||
|
codePoint = parseInt(value.slice(1), 8);
|
||
|
symbol = String.fromCodePoint(codePoint);
|
||
|
break;
|
||
|
}
|
||
|
case 'hex':
|
||
|
case 'unicode':
|
||
|
{
|
||
|
if (value.lastIndexOf('\\u') > 0) {
|
||
|
var _value$split$slice = value.split('\\u').slice(1),
|
||
|
_value$split$slice2 = _slicedToArray(_value$split$slice, 2),
|
||
|
lead = _value$split$slice2[0],
|
||
|
trail = _value$split$slice2[1];
|
||
|
|
||
|
lead = parseInt(lead, 16);
|
||
|
trail = parseInt(trail, 16);
|
||
|
codePoint = (lead - 0xd800) * 0x400 + (trail - 0xdc00) + 0x10000;
|
||
|
|
||
|
symbol = String.fromCodePoint(codePoint);
|
||
|
} else {
|
||
|
var hex = value.slice(2).replace('{', '');
|
||
|
codePoint = parseInt(hex, 16);
|
||
|
if (codePoint > 0x10ffff) {
|
||
|
throw new SyntaxError('Bad character escape sequence: ' + value);
|
||
|
}
|
||
|
|
||
|
symbol = String.fromCodePoint(codePoint);
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'meta':
|
||
|
{
|
||
|
switch (value) {
|
||
|
case '\\t':
|
||
|
symbol = '\t';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
case '\\n':
|
||
|
symbol = '\n';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
case '\\r':
|
||
|
symbol = '\r';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
case '\\v':
|
||
|
symbol = '\v';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
case '\\f':
|
||
|
symbol = '\f';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
case '\\b':
|
||
|
symbol = '\b';
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
case '\\0':
|
||
|
symbol = '\0';
|
||
|
codePoint = 0;
|
||
|
case '.':
|
||
|
symbol = '.';
|
||
|
codePoint = NaN;
|
||
|
break;
|
||
|
default:
|
||
|
codePoint = NaN;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'simple':
|
||
|
{
|
||
|
symbol = value;
|
||
|
codePoint = symbol.codePointAt(0);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return Node({
|
||
|
type: 'Char',
|
||
|
value: value,
|
||
|
kind: kind,
|
||
|
symbol: symbol,
|
||
|
codePoint: codePoint
|
||
|
}, loc);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Valid flags per current ECMAScript spec and
|
||
|
* stage 3+ proposals.
|
||
|
*/
|
||
|
var validFlags = 'gimsuxy';
|
||
|
|
||
|
/**
|
||
|
* Checks the flags are valid, and that
|
||
|
* we don't duplicate flags.
|
||
|
*/
|
||
|
function checkFlags(flags) {
|
||
|
var seen = new Set();
|
||
|
|
||
|
var _iteratorNormalCompletion = true;
|
||
|
var _didIteratorError = false;
|
||
|
var _iteratorError = undefined;
|
||
|
|
||
|
try {
|
||
|
for (var _iterator = flags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||
|
var flag = _step.value;
|
||
|
|
||
|
if (seen.has(flag) || !validFlags.includes(flag)) {
|
||
|
throw new SyntaxError('Invalid flags: ' + flags);
|
||
|
}
|
||
|
seen.add(flag);
|
||
|
}
|
||
|
} catch (err) {
|
||
|
_didIteratorError = true;
|
||
|
_iteratorError = err;
|
||
|
} finally {
|
||
|
try {
|
||
|
if (!_iteratorNormalCompletion && _iterator.return) {
|
||
|
_iterator.return();
|
||
|
}
|
||
|
} finally {
|
||
|
if (_didIteratorError) {
|
||
|
throw _iteratorError;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return flags.split('').sort().join('');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Parses patterns like \1, \2, etc. either as a backreference
|
||
|
* to a group, or a deciaml char code.
|
||
|
*/
|
||
|
function GroupRefOrDecChar(text, textLoc) {
|
||
|
var reference = Number(text.slice(1));
|
||
|
|
||
|
if (reference > 0 && reference <= capturingGroupsCount) {
|
||
|
return Node({
|
||
|
type: 'Backreference',
|
||
|
kind: 'number',
|
||
|
number: reference,
|
||
|
reference: reference
|
||
|
}, textLoc);
|
||
|
}
|
||
|
|
||
|
return Char(text, 'decimal', textLoc);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Unicode names.
|
||
|
*/
|
||
|
var uReStart = /^\\u[0-9a-fA-F]{4}/; // only matches start of string
|
||
|
var ucpReStart = /^\\u\{[0-9a-fA-F]{1,}\}/; // only matches start of string
|
||
|
var ucpReAnywhere = /\\u\{[0-9a-fA-F]{1,}\}/; // matches anywhere in string
|
||
|
|
||
|
/**
|
||
|
* Validates Unicode group name.
|
||
|
*/
|
||
|
function validateUnicodeGroupName(name, state) {
|
||
|
var isUnicodeName = ucpReAnywhere.test(name);
|
||
|
var isUnicodeState = state === 'u' || state === 'xu' || state === 'u_class';
|
||
|
|
||
|
if (isUnicodeName && !isUnicodeState) {
|
||
|
throw new SyntaxError('invalid group Unicode name "' + name + '", use `u` flag.');
|
||
|
}
|
||
|
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
// Matches the following production: https://tc39.es/ecma262/#prod-RegExpUnicodeEscapeSequence
|
||
|
//
|
||
|
// RegExpUnicodeEscapeSequence ::
|
||
|
// `u` LeadSurrogate `\u` TrailSurrogate # as 'leadSurrogate', 'trailSurrogate'
|
||
|
// `u` LeadSurrogate # as 'leadSurrogateOnly'
|
||
|
// `u` TrailSurrogate # as 'trailSurrogateOnly'
|
||
|
// `u` NonSurrogate # as 'nonSurrogate'
|
||
|
// `u` `{` CodePoint `}` # as 'codePoint'
|
||
|
//
|
||
|
// LeadSurrogate ::
|
||
|
// Hex4Digits but only if the SV of Hex4Digits is in the inclusive range 0xD800 to 0xDBFF # [dD][89aAbB][0-9a-fA-F]{2}
|
||
|
//
|
||
|
// TrailSurrogate ::
|
||
|
// Hex4Digits but only if the SV of Hex4Digits is in the inclusive range 0xDC00 to 0xDFFF # [dD][c-fC-F][0-9a-fA-F]{2}
|
||
|
//
|
||
|
// NonSurrogate ::
|
||
|
// Hex4Digits but only if the SV of Hex4Digits is not in the inclusive range 0xD800 to 0xDFFF # [0-9a-ce-fA-CE-F][0-9a-fA-F]{3}|[dD][0-7][0-9a-fA-F]{2}
|
||
|
//
|
||
|
// CodePoint ::
|
||
|
// HexDigits but only if MV of HexDigits ≤ 0x10FFFF # 0*(?:[0-9a-fA-F]{1,5}|10[0-9a-fA-F]{4})
|
||
|
//
|
||
|
var uidRe = /\\u(?:([dD][89aAbB][0-9a-fA-F]{2})\\u([dD][c-fC-F][0-9a-fA-F]{2})|([dD][89aAbB][0-9a-fA-F]{2})|([dD][c-fC-F][0-9a-fA-F]{2})|([0-9a-ce-fA-CE-F][0-9a-fA-F]{3}|[dD][0-7][0-9a-fA-F]{2})|\{(0*(?:[0-9a-fA-F]{1,5}|10[0-9a-fA-F]{4}))\})/;
|
||
|
|
||
|
function decodeUnicodeGroupName(name) {
|
||
|
return name.replace(new RegExp(uidRe, 'g'), function (_, leadSurrogate, trailSurrogate, leadSurrogateOnly, trailSurrogateOnly, nonSurrogate, codePoint) {
|
||
|
if (leadSurrogate) {
|
||
|
return String.fromCodePoint(parseInt(leadSurrogate, 16), parseInt(trailSurrogate, 16));
|
||
|
}
|
||
|
if (leadSurrogateOnly) {
|
||
|
return String.fromCodePoint(parseInt(leadSurrogateOnly, 16));
|
||
|
}
|
||
|
if (trailSurrogateOnly) {
|
||
|
// TODO: Per the spec: https://tc39.es/ecma262/#prod-RegExpUnicodeEscapeSequence
|
||
|
// > Each `\u` TrailSurrogate for which the choice of associated `u` LeadSurrogate is ambiguous shall be associated with the nearest possible `u` LeadSurrogate that would otherwise have no corresponding `\u` TrailSurrogate.
|
||
|
return String.fromCodePoint(parseInt(trailSurrogateOnly, 16));
|
||
|
}
|
||
|
if (nonSurrogate) {
|
||
|
return String.fromCodePoint(parseInt(nonSurrogate, 16));
|
||
|
}
|
||
|
if (codePoint) {
|
||
|
return String.fromCodePoint(parseInt(codePoint, 16));
|
||
|
}
|
||
|
return _;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Extracts from `\k<foo>` pattern either a backreference
|
||
|
* to a named capturing group (if it presents), or parses it
|
||
|
* as a list of char: `\k`, `<`, `f`, etc.
|
||
|
*/
|
||
|
function NamedGroupRefOrChars(text, textLoc) {
|
||
|
var referenceRaw = text.slice(3, -1);
|
||
|
var reference = decodeUnicodeGroupName(referenceRaw);
|
||
|
|
||
|
if (namedGroups.hasOwnProperty(reference)) {
|
||
|
return Node({
|
||
|
type: 'Backreference',
|
||
|
kind: 'name',
|
||
|
number: namedGroups[reference],
|
||
|
reference: reference,
|
||
|
referenceRaw: referenceRaw
|
||
|
}, textLoc);
|
||
|
}
|
||
|
|
||
|
// Else `\k<foo>` should be parsed as a list of `Char`s.
|
||
|
// This is really a 0.01% edge case, but we should handle it.
|
||
|
|
||
|
var startOffset = null;
|
||
|
var startLine = null;
|
||
|
var endLine = null;
|
||
|
var startColumn = null;
|
||
|
|
||
|
if (textLoc) {
|
||
|
startOffset = textLoc.startOffset;
|
||
|
startLine = textLoc.startLine;
|
||
|
endLine = textLoc.endLine;
|
||
|
startColumn = textLoc.startColumn;
|
||
|
}
|
||
|
|
||
|
var charRe = /^[\w$<>]/;
|
||
|
var loc = void 0;
|
||
|
|
||
|
var chars = [
|
||
|
// Init to first \k, taking 2 symbols.
|
||
|
Char(text.slice(1, 2), 'simple', startOffset ? {
|
||
|
startLine: startLine,
|
||
|
endLine: endLine,
|
||
|
startColumn: startColumn,
|
||
|
startOffset: startOffset,
|
||
|
endOffset: startOffset += 2,
|
||
|
endColumn: startColumn += 2
|
||
|
} : null)];
|
||
|
|
||
|
// For \k
|
||
|
chars[0].escaped = true;
|
||
|
|
||
|
// Other symbols.
|
||
|
text = text.slice(2);
|
||
|
|
||
|
while (text.length > 0) {
|
||
|
var matched = null;
|
||
|
|
||
|
// Unicode, \u003B or \u{003B}
|
||
|
if ((matched = text.match(uReStart)) || (matched = text.match(ucpReStart))) {
|
||
|
if (startOffset) {
|
||
|
loc = {
|
||
|
startLine: startLine,
|
||
|
endLine: endLine,
|
||
|
startColumn: startColumn,
|
||
|
startOffset: startOffset,
|
||
|
endOffset: startOffset += matched[0].length,
|
||
|
endColumn: startColumn += matched[0].length
|
||
|
};
|
||
|
}
|
||
|
chars.push(Char(matched[0], 'unicode', loc));
|
||
|
text = text.slice(matched[0].length);
|
||
|
}
|
||
|
|
||
|
// Simple char.
|
||
|
else if (matched = text.match(charRe)) {
|
||
|
if (startOffset) {
|
||
|
loc = {
|
||
|
startLine: startLine,
|
||
|
endLine: endLine,
|
||
|
startColumn: startColumn,
|
||
|
startOffset: startOffset,
|
||
|
endOffset: ++startOffset,
|
||
|
endColumn: ++startColumn
|
||
|
};
|
||
|
}
|
||
|
chars.push(Char(matched[0], 'simple', loc));
|
||
|
text = text.slice(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return chars;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates an AST node with a location.
|
||
|
*/
|
||
|
function Node(node, loc) {
|
||
|
if (yy.options.captureLocations) {
|
||
|
node.loc = {
|
||
|
source: parsingString.slice(loc.startOffset, loc.endOffset),
|
||
|
start: {
|
||
|
line: loc.startLine,
|
||
|
column: loc.startColumn,
|
||
|
offset: loc.startOffset
|
||
|
},
|
||
|
end: {
|
||
|
line: loc.endLine,
|
||
|
column: loc.endColumn,
|
||
|
offset: loc.endOffset
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
return node;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Creates location node.
|
||
|
*/
|
||
|
function loc(start, end) {
|
||
|
if (!yy.options.captureLocations) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
startOffset: start.startOffset,
|
||
|
endOffset: end.endOffset,
|
||
|
startLine: start.startLine,
|
||
|
endLine: end.endLine,
|
||
|
startColumn: start.startColumn,
|
||
|
endColumn: end.endColumn
|
||
|
};
|
||
|
}
|
||
|
|
||
|
function unexpectedToken(token) {
|
||
|
if (token.type === EOF) {
|
||
|
unexpectedEndOfInput();
|
||
|
}
|
||
|
|
||
|
tokenizer.throwUnexpectedToken(token.value, token.startLine, token.startColumn);
|
||
|
}
|
||
|
|
||
|
function unexpectedEndOfInput() {
|
||
|
parseError('Unexpected end of input.');
|
||
|
}
|
||
|
|
||
|
function parseError(message) {
|
||
|
throw new SyntaxError(message);
|
||
|
}
|
||
|
|
||
|
module.exports = yyparse;
|