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 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | exports.CodePointCharStream = void 0;
|
14 | const assert = require("assert");
|
15 | const IntStream_1 = require("./IntStream");
|
16 | const Interval_1 = require("./misc/Interval");
|
17 | const Decorators_1 = require("./Decorators");
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | class CodePointCharStream {
|
27 |
|
28 |
|
29 | constructor(array, position, remaining, name) {
|
30 |
|
31 | assert(position === 0);
|
32 | this._array = array;
|
33 | this._size = remaining;
|
34 | this._name = name;
|
35 | this._position = 0;
|
36 | }
|
37 | get internalStorage() {
|
38 | return this._array;
|
39 | }
|
40 | static fromBuffer(codePointBuffer, name) {
|
41 | if (name === undefined || name.length === 0) {
|
42 | name = IntStream_1.IntStream.UNKNOWN_SOURCE_NAME;
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | return new CodePointCharStream(codePointBuffer.array(), codePointBuffer.position, codePointBuffer.remaining, name);
|
55 | }
|
56 | consume() {
|
57 | if (this._size - this._position === 0) {
|
58 | assert(this.LA(1) === IntStream_1.IntStream.EOF);
|
59 | throw new RangeError("cannot consume EOF");
|
60 | }
|
61 | this._position++;
|
62 | }
|
63 | get index() {
|
64 | return this._position;
|
65 | }
|
66 | get size() {
|
67 | return this._size;
|
68 | }
|
69 |
|
70 | mark() {
|
71 | return -1;
|
72 | }
|
73 | release(marker) {
|
74 |
|
75 | }
|
76 | seek(index) {
|
77 | this._position = index;
|
78 | }
|
79 | get sourceName() {
|
80 | return this._name;
|
81 | }
|
82 | toString() {
|
83 | return this.getText(Interval_1.Interval.of(0, this.size - 1));
|
84 | }
|
85 | LA(i) {
|
86 | let offset;
|
87 | switch (Math.sign(i)) {
|
88 | case -1:
|
89 | offset = this.index + i;
|
90 | if (offset < 0) {
|
91 | return IntStream_1.IntStream.EOF;
|
92 | }
|
93 | return this._array[offset];
|
94 | case 0:
|
95 |
|
96 | return 0;
|
97 | case 1:
|
98 | offset = this.index + i - 1;
|
99 | if (offset >= this.size) {
|
100 | return IntStream_1.IntStream.EOF;
|
101 | }
|
102 | return this._array[offset];
|
103 | }
|
104 | throw new RangeError("Not reached");
|
105 | }
|
106 |
|
107 | getText(interval) {
|
108 | const startIdx = Math.min(interval.a, this.size);
|
109 | const len = Math.min(interval.b - interval.a + 1, this.size - startIdx);
|
110 | if (this._array instanceof Int32Array) {
|
111 | return String.fromCodePoint(...Array.from(this._array.subarray(startIdx, startIdx + len)));
|
112 | }
|
113 | else {
|
114 | return String.fromCharCode(...Array.from(this._array.subarray(startIdx, startIdx + len)));
|
115 | }
|
116 | }
|
117 | }
|
118 | __decorate([
|
119 | Decorators_1.Override
|
120 | ], CodePointCharStream.prototype, "consume", null);
|
121 | __decorate([
|
122 | Decorators_1.Override
|
123 | ], CodePointCharStream.prototype, "index", null);
|
124 | __decorate([
|
125 | Decorators_1.Override
|
126 | ], CodePointCharStream.prototype, "size", null);
|
127 | __decorate([
|
128 | Decorators_1.Override
|
129 | ], CodePointCharStream.prototype, "mark", null);
|
130 | __decorate([
|
131 | Decorators_1.Override
|
132 | ], CodePointCharStream.prototype, "release", null);
|
133 | __decorate([
|
134 | Decorators_1.Override
|
135 | ], CodePointCharStream.prototype, "seek", null);
|
136 | __decorate([
|
137 | Decorators_1.Override
|
138 | ], CodePointCharStream.prototype, "sourceName", null);
|
139 | __decorate([
|
140 | Decorators_1.Override
|
141 | ], CodePointCharStream.prototype, "toString", null);
|
142 | __decorate([
|
143 | Decorators_1.Override
|
144 | ], CodePointCharStream.prototype, "LA", null);
|
145 | __decorate([
|
146 | Decorators_1.Override
|
147 | ], CodePointCharStream.prototype, "getText", null);
|
148 | exports.CodePointCharStream = CodePointCharStream;
|
149 |
|
\ | No newline at end of file |