1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var ParameterTypeMatcher = (function () {
|
4 | function ParameterTypeMatcher(parameterType, regexpString, text, matchPosition) {
|
5 | if (matchPosition === void 0) { matchPosition = 0; }
|
6 | this.parameterType = parameterType;
|
7 | this.regexpString = regexpString;
|
8 | this.text = text;
|
9 | this.matchPosition = matchPosition;
|
10 | var captureGroupRegexp = new RegExp("(" + regexpString + ")");
|
11 | this.match = captureGroupRegexp.exec(text.slice(this.matchPosition));
|
12 | }
|
13 | ParameterTypeMatcher.prototype.advanceTo = function (newMatchPosition) {
|
14 | for (var advancedPos = newMatchPosition; advancedPos < this.text.length; advancedPos++) {
|
15 | var matcher = new ParameterTypeMatcher(this.parameterType, this.regexpString, this.text, advancedPos);
|
16 | if (matcher.find) {
|
17 | return matcher;
|
18 | }
|
19 | }
|
20 | return new ParameterTypeMatcher(this.parameterType, this.regexpString, this.text, this.text.length);
|
21 | };
|
22 | Object.defineProperty(ParameterTypeMatcher.prototype, "find", {
|
23 | get: function () {
|
24 | return this.match && this.group !== '' && this.full_word;
|
25 | },
|
26 | enumerable: true,
|
27 | configurable: true
|
28 | });
|
29 | Object.defineProperty(ParameterTypeMatcher.prototype, "start", {
|
30 | get: function () {
|
31 | return this.matchPosition + this.match.index;
|
32 | },
|
33 | enumerable: true,
|
34 | configurable: true
|
35 | });
|
36 | Object.defineProperty(ParameterTypeMatcher.prototype, "full_word", {
|
37 | get: function () {
|
38 | return this.match_start_word && this.match_end_word;
|
39 | },
|
40 | enumerable: true,
|
41 | configurable: true
|
42 | });
|
43 | Object.defineProperty(ParameterTypeMatcher.prototype, "match_start_word", {
|
44 | get: function () {
|
45 | return this.start == 0 || this.text[this.start - 1].match(/\s|\p{P}/u);
|
46 | },
|
47 | enumerable: true,
|
48 | configurable: true
|
49 | });
|
50 | Object.defineProperty(ParameterTypeMatcher.prototype, "match_end_word", {
|
51 | get: function () {
|
52 | var next_character_index = this.start + this.group.length;
|
53 | return next_character_index === this.text.length || this.text[next_character_index].match(/\s|\p{P}/u);
|
54 | },
|
55 | enumerable: true,
|
56 | configurable: true
|
57 | });
|
58 | Object.defineProperty(ParameterTypeMatcher.prototype, "group", {
|
59 | get: function () {
|
60 | return this.match[0];
|
61 | },
|
62 | enumerable: true,
|
63 | configurable: true
|
64 | });
|
65 | ParameterTypeMatcher.compare = function (a, b) {
|
66 | var posComparison = a.start - b.start;
|
67 | if (posComparison !== 0) {
|
68 | return posComparison;
|
69 | }
|
70 | var lengthComparison = b.group.length - a.group.length;
|
71 | if (lengthComparison !== 0) {
|
72 | return lengthComparison;
|
73 | }
|
74 | return 0;
|
75 | };
|
76 | return ParameterTypeMatcher;
|
77 | }());
|
78 | exports.default = ParameterTypeMatcher;
|
79 | module.exports = ParameterTypeMatcher;
|
80 |
|
\ | No newline at end of file |