goscript 0.0.29 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.go +8 -1
- package/compiler/index.ts +1 -1
- package/compiler/stmt-assign.go +14 -0
- package/dist/compiler/index.js +1 -1
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +6 -6
- package/dist/gs/builtin/channel.js +3 -3
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/slice.js +3 -9
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/context/context.js +2 -2
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/internal/oserror/errors.d.ts +1 -1
- package/dist/gs/internal/oserror/errors.js +6 -6
- package/dist/gs/internal/oserror/index.d.ts +1 -1
- package/dist/gs/internal/oserror/index.js +1 -1
- package/dist/gs/internal/oserror/index.js.map +1 -1
- package/dist/gs/io/fs/format.d.ts +1 -1
- package/dist/gs/io/fs/format.js +12 -12
- package/dist/gs/io/fs/format.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +2 -2
- package/dist/gs/io/fs/fs.js +258 -36
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/glob.d.ts +2 -2
- package/dist/gs/io/fs/glob.js +40 -14
- package/dist/gs/io/fs/glob.js.map +1 -1
- package/dist/gs/io/fs/index.d.ts +8 -8
- package/dist/gs/io/fs/index.js +8 -8
- package/dist/gs/io/fs/readdir.d.ts +2 -2
- package/dist/gs/io/fs/readdir.js +78 -9
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/readfile.d.ts +2 -2
- package/dist/gs/io/fs/readfile.js +31 -13
- package/dist/gs/io/fs/readfile.js.map +1 -1
- package/dist/gs/io/fs/stat.d.ts +2 -2
- package/dist/gs/io/fs/stat.js +25 -2
- package/dist/gs/io/fs/stat.js.map +1 -1
- package/dist/gs/io/fs/sub.d.ts +2 -2
- package/dist/gs/io/fs/sub.js +264 -28
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/fs/walk.d.ts +2 -2
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/iter/iter.js +1 -1
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/path/index.d.ts +2 -2
- package/dist/gs/path/index.js +2 -2
- package/dist/gs/path/match.d.ts +1 -1
- package/dist/gs/path/match.js +39 -33
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/path/path.js +53 -24
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/runtime/runtime.d.ts +3 -3
- package/dist/gs/runtime/runtime.js +3 -3
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +1 -1
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/clone.js.map +1 -1
- package/dist/gs/strings/compare.js.map +1 -1
- package/dist/gs/strings/replace.js +4 -2
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.js +0 -12
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +5 -5
- package/dist/gs/sync/sync.js +5 -5
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/time/time.d.ts +2 -2
- package/dist/gs/time/time.js +62 -16
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unsafe/unsafe.d.ts +8 -8
- package/dist/gs/unsafe/unsafe.js +8 -8
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +1 -1
- package/gs/builtin/channel.ts +6 -6
- package/gs/builtin/slice.ts +3 -9
- package/gs/context/context.ts +2 -2
- package/gs/internal/oserror/errors.ts +7 -8
- package/gs/internal/oserror/index.ts +7 -1
- package/gs/io/fs/format.ts +39 -40
- package/gs/io/fs/fs.ts +446 -222
- package/gs/io/fs/glob.ts +164 -131
- package/gs/io/fs/index.ts +8 -8
- package/gs/io/fs/readdir.ts +188 -106
- package/gs/io/fs/readfile.ts +79 -58
- package/gs/io/fs/stat.ts +49 -25
- package/gs/io/fs/sub.ts +422 -181
- package/gs/io/fs/walk.ts +67 -63
- package/gs/iter/iter.ts +1 -1
- package/gs/path/index.ts +2 -2
- package/gs/path/match.ts +263 -250
- package/gs/path/path.ts +259 -232
- package/gs/runtime/runtime.ts +4 -4
- package/gs/strings/builder.test.ts +0 -1
- package/gs/strings/builder.ts +1 -1
- package/gs/strings/clone.ts +0 -2
- package/gs/strings/compare.ts +0 -2
- package/gs/strings/iter.test.ts +0 -1
- package/gs/strings/replace.test.ts +3 -4
- package/gs/strings/replace.ts +4 -7
- package/gs/strings/strings.test.ts +6 -6
- package/gs/strings/strings.ts +0 -14
- package/gs/sync/sync.ts +5 -5
- package/gs/time/time.ts +86 -29
- package/gs/unsafe/unsafe.ts +8 -8
- package/package.json +1 -1
package/gs/path/match.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as $ from
|
|
1
|
+
import * as $ from '@goscript/builtin/builtin.js'
|
|
2
2
|
|
|
3
|
-
import * as errors from
|
|
3
|
+
import * as errors from '@goscript/errors/index.js'
|
|
4
4
|
|
|
5
|
-
import * as utf8 from
|
|
5
|
+
import * as utf8 from '@goscript/unicode/utf8/index.js'
|
|
6
6
|
|
|
7
|
-
export let ErrBadPattern: $.GoError = errors.New(
|
|
7
|
+
export let ErrBadPattern: $.GoError = errors.New('syntax error in pattern')
|
|
8
8
|
|
|
9
9
|
// Match reports whether name matches the shell pattern.
|
|
10
10
|
// The pattern syntax is:
|
|
@@ -28,280 +28,293 @@ export let ErrBadPattern: $.GoError = errors.New("syntax error in pattern")
|
|
|
28
28
|
// The only possible returned error is [ErrBadPattern], when pattern
|
|
29
29
|
// is malformed.
|
|
30
30
|
export function Match(pattern: string, name: string): [boolean, $.GoError] {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{
|
|
31
|
+
{
|
|
32
|
+
// Trailing * matches rest of string unless it has a /.
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
// Look for match at current position.
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
// if we're the last chunk, make sure we've exhausted the name
|
|
37
|
+
// otherwise we'll give a false result even if we could still match
|
|
38
|
+
// using the star
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// using the star
|
|
40
|
+
// Look for match skipping i+1 bytes.
|
|
41
|
+
// Cannot skip /.
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
// Cannot skip /.
|
|
43
|
+
// if we're the last chunk, make sure we exhausted the name
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
// Before returning false with no error,
|
|
46
|
+
// check that the remainder of the pattern is syntactically valid.
|
|
47
|
+
Pattern: for (; $.len(pattern) > 0; ) {
|
|
48
|
+
let star: boolean = false
|
|
49
|
+
let chunk: string = ''
|
|
50
|
+
let rest: string = ''
|
|
51
|
+
let scanResult = scanChunk(pattern)
|
|
52
|
+
star = scanResult[0]
|
|
53
|
+
chunk = scanResult[1]
|
|
54
|
+
rest = scanResult[2]
|
|
55
|
+
pattern = rest
|
|
47
56
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// Trailing * matches rest of string unless it has a /.
|
|
58
|
+
if (star && chunk == '') {
|
|
59
|
+
// Trailing * matches rest of string unless it has a /.
|
|
60
|
+
return [name.indexOf('/') < 0, null]
|
|
61
|
+
}
|
|
62
|
+
// Look for match at current position.
|
|
63
|
+
let [t, ok, err] = matchChunk(chunk, name)
|
|
64
|
+
// if we're the last chunk, make sure we've exhausted the name
|
|
65
|
+
// otherwise we'll give a false result even if we could still match
|
|
66
|
+
// using the star
|
|
67
|
+
if (ok && ($.len(t) == 0 || $.len(pattern) > 0)) {
|
|
68
|
+
name = t
|
|
69
|
+
continue
|
|
70
|
+
}
|
|
71
|
+
if (err != null) {
|
|
72
|
+
return [false, err]
|
|
73
|
+
}
|
|
59
74
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Trailing * matches rest of string unless it has a /.
|
|
63
|
-
return [name.indexOf("/") < 0, null]
|
|
64
|
-
}
|
|
65
|
-
// Look for match at current position.
|
|
66
|
-
let [t, ok, err] = matchChunk(chunk, name)
|
|
67
|
-
// if we're the last chunk, make sure we've exhausted the name
|
|
68
|
-
// otherwise we'll give a false result even if we could still match
|
|
69
|
-
// using the star
|
|
70
|
-
if (ok && ($.len(t) == 0 || $.len(pattern) > 0)) {
|
|
71
|
-
name = t
|
|
72
|
-
continue
|
|
73
|
-
}
|
|
74
|
-
if (err != null) {
|
|
75
|
-
return [false, err]
|
|
76
|
-
}
|
|
75
|
+
// Look for match skipping i+1 bytes.
|
|
76
|
+
// Cannot skip /.
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
// if we're the last chunk, make sure we exhausted the name
|
|
79
|
+
if (star) {
|
|
80
|
+
// Look for match skipping i+1 bytes.
|
|
81
|
+
// Cannot skip /.
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// if we're the last chunk, make sure we exhausted the name
|
|
84
|
+
for (let i = 0; i < $.len(name) && $.indexString(name, i) != 47; i++) {
|
|
85
|
+
let [t, ok, err] = matchChunk(
|
|
86
|
+
chunk,
|
|
87
|
+
$.sliceString(name, i, undefined),
|
|
88
|
+
)
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return [false, null]
|
|
123
|
-
}
|
|
124
|
-
return [$.len(name) == 0, null]
|
|
125
|
-
}
|
|
90
|
+
// if we're the last chunk, make sure we exhausted the name
|
|
91
|
+
if (ok) {
|
|
92
|
+
// if we're the last chunk, make sure we exhausted the name
|
|
93
|
+
if ($.len(pattern) == 0 && $.len(t) > 0) {
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
name = t
|
|
97
|
+
continue Pattern
|
|
98
|
+
}
|
|
99
|
+
if (err != null) {
|
|
100
|
+
return [false, err]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Before returning false with no error,
|
|
105
|
+
// check that the remainder of the pattern is syntactically valid.
|
|
106
|
+
for (; $.len(pattern) > 0; ) {
|
|
107
|
+
// let star2: boolean = false
|
|
108
|
+
let chunk2: string = ''
|
|
109
|
+
let rest2: string = ''
|
|
110
|
+
let scanResult2 = scanChunk(pattern)
|
|
111
|
+
// star2 = scanResult2[0]
|
|
112
|
+
chunk2 = scanResult2[1]
|
|
113
|
+
rest2 = scanResult2[2]
|
|
114
|
+
pattern = rest2
|
|
115
|
+
{
|
|
116
|
+
let [, , err] = matchChunk(chunk2, '')
|
|
117
|
+
if (err != null) {
|
|
118
|
+
return [false, err]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return [false, null]
|
|
123
|
+
}
|
|
124
|
+
return [$.len(name) == 0, null]
|
|
125
|
+
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// scanChunk gets the next segment of pattern, which is a non-star string
|
|
129
129
|
// possibly preceded by a star.
|
|
130
130
|
export function scanChunk(pattern: string): [boolean, string, string] {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let inrange = false
|
|
140
|
-
let i: number = 0
|
|
141
|
-
|
|
142
|
-
// error check handled in matchChunk: bad pattern.
|
|
143
|
-
Scan: for (i = 0; i < $.len(pattern); i++) {
|
|
131
|
+
let star: boolean = false
|
|
132
|
+
{
|
|
133
|
+
for (; $.len(pattern) > 0 && $.indexString(pattern, 0) == 42; ) {
|
|
134
|
+
pattern = $.sliceString(pattern, 1, undefined)
|
|
135
|
+
star = true
|
|
136
|
+
}
|
|
137
|
+
let inrange = false
|
|
138
|
+
let i: number = 0
|
|
144
139
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
140
|
+
// error check handled in matchChunk: bad pattern.
|
|
141
|
+
Scan: for (i = 0; i < $.len(pattern); i++) {
|
|
142
|
+
// error check handled in matchChunk: bad pattern.
|
|
143
|
+
switch ($.indexString(pattern, i)) {
|
|
144
|
+
case 92:
|
|
145
|
+
if (i + 1 < $.len(pattern)) {
|
|
146
|
+
i++
|
|
147
|
+
}
|
|
148
|
+
break
|
|
149
|
+
case 91:
|
|
150
|
+
inrange = true
|
|
151
|
+
break
|
|
152
|
+
case 93:
|
|
153
|
+
inrange = false
|
|
154
|
+
break
|
|
155
|
+
case 42:
|
|
156
|
+
if (!inrange) {
|
|
157
|
+
break Scan
|
|
158
|
+
}
|
|
159
|
+
break
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return [
|
|
163
|
+
star,
|
|
164
|
+
$.sliceString(pattern, 0, i),
|
|
165
|
+
$.sliceString(pattern, i, undefined),
|
|
166
|
+
]
|
|
167
|
+
}
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
// matchChunk checks whether chunk matches the beginning of s.
|
|
170
171
|
// If so, it returns the remainder of s (after the match).
|
|
171
172
|
// Chunk is all single-character operators: literals, char classes, and ?.
|
|
172
|
-
export function matchChunk(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
173
|
+
export function matchChunk(
|
|
174
|
+
chunk: string,
|
|
175
|
+
s: string,
|
|
176
|
+
): [string, boolean, $.GoError] {
|
|
177
|
+
let err: $.GoError = null
|
|
178
|
+
{
|
|
179
|
+
// failed records whether the match has failed.
|
|
180
|
+
// After the match fails, the loop continues on processing chunk,
|
|
181
|
+
// checking that the pattern is well-formed but no longer reading s.
|
|
182
|
+
let failed = false
|
|
181
183
|
|
|
182
|
-
|
|
184
|
+
// character class
|
|
183
185
|
|
|
184
|
-
|
|
186
|
+
// possibly negated
|
|
185
187
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
// parse all ranges
|
|
189
|
+
for (; $.len(chunk) > 0; ) {
|
|
190
|
+
if (!failed && $.len(s) == 0) {
|
|
191
|
+
failed = true
|
|
192
|
+
}
|
|
191
193
|
|
|
192
|
-
|
|
194
|
+
// character class
|
|
193
195
|
|
|
194
|
-
|
|
196
|
+
// possibly negated
|
|
195
197
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
198
|
+
// parse all ranges
|
|
199
|
+
switch ($.indexString(chunk, 0)) {
|
|
200
|
+
case 91: {
|
|
201
|
+
let r: number = 0
|
|
202
|
+
if (!failed) {
|
|
203
|
+
let n: number = 0
|
|
204
|
+
let decoded = utf8.DecodeRuneInString(s)
|
|
205
|
+
r = decoded[0]
|
|
206
|
+
n = decoded[1]
|
|
207
|
+
s = $.sliceString(s, n, undefined)
|
|
208
|
+
}
|
|
209
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
210
|
+
let negated = false
|
|
211
|
+
if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 94) {
|
|
212
|
+
negated = true
|
|
213
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
214
|
+
}
|
|
215
|
+
let match = false
|
|
216
|
+
let nrange = 0
|
|
217
|
+
for (;;) {
|
|
218
|
+
if (
|
|
219
|
+
$.len(chunk) > 0 &&
|
|
220
|
+
$.indexString(chunk, 0) == 93 &&
|
|
221
|
+
nrange > 0
|
|
222
|
+
) {
|
|
223
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
224
|
+
break
|
|
225
|
+
}
|
|
226
|
+
let lo: number = 0
|
|
227
|
+
let hi: number = 0
|
|
228
|
+
{
|
|
229
|
+
let escResult = getEsc(chunk)
|
|
230
|
+
lo = escResult[0]
|
|
231
|
+
chunk = escResult[1]
|
|
232
|
+
err = escResult[2]
|
|
233
|
+
if (err != null) {
|
|
234
|
+
return ['', false, err]
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
hi = lo
|
|
238
|
+
if ($.indexString(chunk, 0) == 45) {
|
|
239
|
+
{
|
|
240
|
+
let escResult2 = getEsc($.sliceString(chunk, 1, undefined))
|
|
241
|
+
hi = escResult2[0]
|
|
242
|
+
chunk = escResult2[1]
|
|
243
|
+
err = escResult2[2]
|
|
244
|
+
if (err != null) {
|
|
245
|
+
return ['', false, err]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (lo <= r && r <= hi) {
|
|
250
|
+
match = true
|
|
251
|
+
}
|
|
252
|
+
nrange++
|
|
253
|
+
}
|
|
254
|
+
if (match == negated) {
|
|
255
|
+
failed = true
|
|
256
|
+
}
|
|
257
|
+
break
|
|
258
|
+
}
|
|
259
|
+
case 63: {
|
|
260
|
+
if (!failed) {
|
|
261
|
+
if ($.indexString(s, 0) == 47) {
|
|
262
|
+
failed = true
|
|
263
|
+
}
|
|
264
|
+
let [, n] = utf8.DecodeRuneInString(s)
|
|
265
|
+
s = $.sliceString(s, n, undefined)
|
|
266
|
+
}
|
|
267
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
268
|
+
break
|
|
269
|
+
}
|
|
270
|
+
case 92: {
|
|
271
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
272
|
+
if ($.len(chunk) == 0) {
|
|
273
|
+
return ['', false, ErrBadPattern]
|
|
274
|
+
}
|
|
275
|
+
// unhandled branch statement token: fallthrough
|
|
276
|
+
break
|
|
277
|
+
}
|
|
278
|
+
default: {
|
|
279
|
+
if (!failed) {
|
|
280
|
+
if ($.indexString(chunk, 0) != $.indexString(s, 0)) {
|
|
281
|
+
failed = true
|
|
282
|
+
}
|
|
283
|
+
s = $.sliceString(s, 1, undefined)
|
|
284
|
+
}
|
|
285
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
286
|
+
break
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (failed) {
|
|
291
|
+
return ['', false, null]
|
|
292
|
+
}
|
|
293
|
+
return [s, true, null]
|
|
294
|
+
}
|
|
285
295
|
}
|
|
286
296
|
|
|
287
297
|
export function getEsc(chunk: string): [number, string, $.GoError] {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
298
|
+
if (
|
|
299
|
+
$.len(chunk) == 0 ||
|
|
300
|
+
$.indexString(chunk, 0) == 45 ||
|
|
301
|
+
$.indexString(chunk, 0) == 93
|
|
302
|
+
) {
|
|
303
|
+
return [0, '', ErrBadPattern]
|
|
304
|
+
}
|
|
305
|
+
if ($.indexString(chunk, 0) == 92) {
|
|
306
|
+
chunk = $.sliceString(chunk, 1, undefined)
|
|
307
|
+
if ($.len(chunk) == 0) {
|
|
308
|
+
return [0, '', ErrBadPattern]
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
let [r, n] = utf8.DecodeRuneInString(chunk)
|
|
312
|
+
if (r == utf8.RuneError && n == 1) {
|
|
313
|
+
return [0, '', ErrBadPattern]
|
|
314
|
+
}
|
|
315
|
+
chunk = $.sliceString(chunk, n, undefined)
|
|
316
|
+
if ($.len(chunk) == 0 || $.indexString(chunk, 0) != 45 || $.len(chunk) == 1) {
|
|
317
|
+
return [r, chunk, null]
|
|
318
|
+
}
|
|
319
|
+
return [r, chunk, null]
|
|
306
320
|
}
|
|
307
|
-
|