1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TokenSequence = void 0;
|
4 | var TextRange_1 = require("./TextRange");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var TokenSequence = (function () {
|
10 | function TokenSequence(parameters) {
|
11 | this.parserContext = parameters.parserContext;
|
12 | this._startIndex = parameters.startIndex;
|
13 | this._endIndex = parameters.endIndex;
|
14 | this._validateBounds();
|
15 | }
|
16 | |
17 |
|
18 |
|
19 | TokenSequence.createEmpty = function (parserContext) {
|
20 | return new TokenSequence({ parserContext: parserContext, startIndex: 0, endIndex: 0 });
|
21 | };
|
22 | Object.defineProperty(TokenSequence.prototype, "startIndex", {
|
23 | |
24 |
|
25 |
|
26 | get: function () {
|
27 | return this._startIndex;
|
28 | },
|
29 | enumerable: false,
|
30 | configurable: true
|
31 | });
|
32 | Object.defineProperty(TokenSequence.prototype, "endIndex", {
|
33 | |
34 |
|
35 |
|
36 | get: function () {
|
37 | return this._endIndex;
|
38 | },
|
39 | enumerable: false,
|
40 | configurable: true
|
41 | });
|
42 | Object.defineProperty(TokenSequence.prototype, "tokens", {
|
43 | get: function () {
|
44 | return this.parserContext.tokens.slice(this._startIndex, this._endIndex);
|
45 | },
|
46 | enumerable: false,
|
47 | configurable: true
|
48 | });
|
49 | |
50 |
|
51 |
|
52 |
|
53 | TokenSequence.prototype.getNewSequence = function (startIndex, endIndex) {
|
54 | return new TokenSequence({
|
55 | parserContext: this.parserContext,
|
56 | startIndex: startIndex,
|
57 | endIndex: endIndex
|
58 | });
|
59 | };
|
60 | |
61 |
|
62 |
|
63 |
|
64 | TokenSequence.prototype.getContainingTextRange = function () {
|
65 | if (this.isEmpty()) {
|
66 | return TextRange_1.TextRange.empty;
|
67 | }
|
68 | return this.parserContext.sourceRange.getNewRange(this.parserContext.tokens[this._startIndex].range.pos, this.parserContext.tokens[this._endIndex - 1].range.end);
|
69 | };
|
70 | TokenSequence.prototype.isEmpty = function () {
|
71 | return this._startIndex === this._endIndex;
|
72 | };
|
73 | |
74 |
|
75 |
|
76 | TokenSequence.prototype.toString = function () {
|
77 | return this.tokens.map(function (x) { return x.toString(); }).join('');
|
78 | };
|
79 | TokenSequence.prototype._validateBounds = function () {
|
80 | if (this.startIndex < 0) {
|
81 | throw new Error('TokenSequence.startIndex cannot be negative');
|
82 | }
|
83 | if (this.endIndex < 0) {
|
84 | throw new Error('TokenSequence.endIndex cannot be negative');
|
85 | }
|
86 | if (this.endIndex < this.startIndex) {
|
87 | throw new Error('TokenSequence.endIndex cannot be smaller than TokenSequence.startIndex');
|
88 | }
|
89 | if (this.startIndex > this.parserContext.tokens.length) {
|
90 | throw new Error('TokenSequence.startIndex cannot exceed the associated token array');
|
91 | }
|
92 | if (this.endIndex > this.parserContext.tokens.length) {
|
93 | throw new Error('TokenSequence.endIndex cannot exceed the associated token array');
|
94 | }
|
95 | };
|
96 | return TokenSequence;
|
97 | }());
|
98 | exports.TokenSequence = TokenSequence;
|
99 |
|
\ | No newline at end of file |