1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
7 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
8 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
9 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
10 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
11 | };
|
12 | var __param = (this && this.__param) || function (paramIndex, decorator) {
|
13 | return function (target, key) { decorator(target, key, paramIndex); }
|
14 | };
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.CommonToken = void 0;
|
17 | const Interval_1 = require("./misc/Interval");
|
18 | const Decorators_1 = require("./Decorators");
|
19 | const Token_1 = require("./Token");
|
20 | let CommonToken = class CommonToken {
|
21 | constructor(type, text, source = CommonToken.EMPTY_SOURCE, channel = Token_1.Token.DEFAULT_CHANNEL, start = 0, stop = 0) {
|
22 | |
23 |
|
24 |
|
25 | this._line = 0;
|
26 | |
27 |
|
28 |
|
29 |
|
30 | this._charPositionInLine = -1;
|
31 | |
32 |
|
33 |
|
34 |
|
35 | this._channel = Token_1.Token.DEFAULT_CHANNEL;
|
36 | |
37 |
|
38 |
|
39 | this.index = -1;
|
40 | this._text = text;
|
41 | this._type = type;
|
42 | this.source = source;
|
43 | this._channel = channel;
|
44 | this.start = start;
|
45 | this.stop = stop;
|
46 | if (source.source != null) {
|
47 | this._line = source.source.line;
|
48 | this._charPositionInLine = source.source.charPositionInLine;
|
49 | }
|
50 | }
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | static fromToken(oldToken) {
|
64 | let result = new CommonToken(oldToken.type, undefined, CommonToken.EMPTY_SOURCE, oldToken.channel, oldToken.startIndex, oldToken.stopIndex);
|
65 | result._line = oldToken.line;
|
66 | result.index = oldToken.tokenIndex;
|
67 | result._charPositionInLine = oldToken.charPositionInLine;
|
68 | if (oldToken instanceof CommonToken) {
|
69 | result._text = oldToken._text;
|
70 | result.source = oldToken.source;
|
71 | }
|
72 | else {
|
73 | result._text = oldToken.text;
|
74 | result.source = { source: oldToken.tokenSource, stream: oldToken.inputStream };
|
75 | }
|
76 | return result;
|
77 | }
|
78 | get type() {
|
79 | return this._type;
|
80 | }
|
81 |
|
82 | set type(type) {
|
83 | this._type = type;
|
84 | }
|
85 | get line() {
|
86 | return this._line;
|
87 | }
|
88 |
|
89 | set line(line) {
|
90 | this._line = line;
|
91 | }
|
92 | get text() {
|
93 | if (this._text != null) {
|
94 | return this._text;
|
95 | }
|
96 | let input = this.inputStream;
|
97 | if (input == null) {
|
98 | return undefined;
|
99 | }
|
100 | let n = input.size;
|
101 | if (this.start < n && this.stop < n) {
|
102 | return input.getText(Interval_1.Interval.of(this.start, this.stop));
|
103 | }
|
104 | else {
|
105 | return "<EOF>";
|
106 | }
|
107 | }
|
108 | |
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | set text(text) {
|
119 | this._text = text;
|
120 | }
|
121 | get charPositionInLine() {
|
122 | return this._charPositionInLine;
|
123 | }
|
124 |
|
125 | set charPositionInLine(charPositionInLine) {
|
126 | this._charPositionInLine = charPositionInLine;
|
127 | }
|
128 | get channel() {
|
129 | return this._channel;
|
130 | }
|
131 |
|
132 | set channel(channel) {
|
133 | this._channel = channel;
|
134 | }
|
135 | get startIndex() {
|
136 | return this.start;
|
137 | }
|
138 | set startIndex(start) {
|
139 | this.start = start;
|
140 | }
|
141 | get stopIndex() {
|
142 | return this.stop;
|
143 | }
|
144 | set stopIndex(stop) {
|
145 | this.stop = stop;
|
146 | }
|
147 | get tokenIndex() {
|
148 | return this.index;
|
149 | }
|
150 |
|
151 | set tokenIndex(index) {
|
152 | this.index = index;
|
153 | }
|
154 | get tokenSource() {
|
155 | return this.source.source;
|
156 | }
|
157 | get inputStream() {
|
158 | return this.source.stream;
|
159 | }
|
160 | toString(recognizer) {
|
161 | let channelStr = "";
|
162 | if (this._channel > 0) {
|
163 | channelStr = ",channel=" + this._channel;
|
164 | }
|
165 | let txt = this.text;
|
166 | if (txt != null) {
|
167 | txt = txt.replace(/\n/g, "\\n");
|
168 | txt = txt.replace(/\r/g, "\\r");
|
169 | txt = txt.replace(/\t/g, "\\t");
|
170 | }
|
171 | else {
|
172 | txt = "<no text>";
|
173 | }
|
174 | let typeString = String(this._type);
|
175 | if (recognizer) {
|
176 | typeString = recognizer.vocabulary.getDisplayName(this._type);
|
177 | }
|
178 | return "[@" + this.tokenIndex + "," + this.start + ":" + this.stop + "='" + txt + "',<" + typeString + ">" + channelStr + "," + this._line + ":" + this.charPositionInLine + "]";
|
179 | }
|
180 | };
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | CommonToken.EMPTY_SOURCE = { source: undefined, stream: undefined };
|
186 | __decorate([
|
187 | Decorators_1.NotNull
|
188 | ], CommonToken.prototype, "source", void 0);
|
189 | __decorate([
|
190 | Decorators_1.Override
|
191 | ], CommonToken.prototype, "type", null);
|
192 | __decorate([
|
193 | Decorators_1.Override
|
194 | ], CommonToken.prototype, "line", null);
|
195 | __decorate([
|
196 | Decorators_1.Override
|
197 | ], CommonToken.prototype, "text", null);
|
198 | __decorate([
|
199 | Decorators_1.Override
|
200 | ], CommonToken.prototype, "charPositionInLine", null);
|
201 | __decorate([
|
202 | Decorators_1.Override
|
203 | ], CommonToken.prototype, "channel", null);
|
204 | __decorate([
|
205 | Decorators_1.Override
|
206 | ], CommonToken.prototype, "startIndex", null);
|
207 | __decorate([
|
208 | Decorators_1.Override
|
209 | ], CommonToken.prototype, "stopIndex", null);
|
210 | __decorate([
|
211 | Decorators_1.Override
|
212 | ], CommonToken.prototype, "tokenIndex", null);
|
213 | __decorate([
|
214 | Decorators_1.Override
|
215 | ], CommonToken.prototype, "tokenSource", null);
|
216 | __decorate([
|
217 | Decorators_1.Override
|
218 | ], CommonToken.prototype, "inputStream", null);
|
219 | __decorate([
|
220 | Decorators_1.Override
|
221 | ], CommonToken.prototype, "toString", null);
|
222 | __decorate([
|
223 | __param(0, Decorators_1.NotNull)
|
224 | ], CommonToken, "fromToken", null);
|
225 | CommonToken = __decorate([
|
226 | __param(2, Decorators_1.NotNull)
|
227 | ], CommonToken);
|
228 | exports.CommonToken = CommonToken;
|
229 |
|
\ | No newline at end of file |