* The names a pattern between `from` and `to` binds, each with the * tuple-struct, variant or struct pattern it sits in, innermost first.
(code: string, from: number, to: number, close: Map<number, number>, site: RustPatternSite | undefined, emit: Emit)
| 303 | * tuple-struct, variant or struct pattern it sits in, innermost first. |
| 304 | */ |
| 305 | function walkPattern(code: string, from: number, to: number, close: Map<number, number>, site: RustPatternSite | undefined, emit: Emit): void { |
| 306 | let p = from; |
| 307 | while (p < to) { |
| 308 | const c = code[p]!; |
| 309 | if (c === '(' || c === '[') { |
| 310 | // A tuple or a slice: its fields' types are not read here. |
| 311 | const end = Math.min(close.get(p) ?? to, to); |
| 312 | for (const [a, b] of splitTop(code, p + 1, end, close, false)) walkPattern(code, a, b, close, undefined, emit); |
| 313 | p = end + 1; |
| 314 | continue; |
| 315 | } |
| 316 | if (!/[A-Za-z_]/.test(c) || isIdentChar(code[p - 1])) { |
| 317 | p++; |
| 318 | continue; |
| 319 | } |
| 320 | const path = readPath(code, p); |
| 321 | if (path.segments.length === 0) { |
| 322 | p++; |
| 323 | continue; |
| 324 | } |
| 325 | const after = skipSpace(code, path.end); |
| 326 | const written = path.segments.join('::'); |
| 327 | if (code[after] === '(') { |
| 328 | const end = Math.min(close.get(after) ?? to, to); |
| 329 | let index = 0; |
| 330 | for (const [a, b] of splitTop(code, after + 1, end, close, false)) { |
| 331 | walkPattern(code, a, b, close, { path: written, index }, emit); |
| 332 | index++; |
| 333 | } |
| 334 | p = end + 1; |
| 335 | continue; |
| 336 | } |
| 337 | if (code[after] === '{') { |
| 338 | const end = Math.min(close.get(after) ?? to, to); |
| 339 | for (const [a, b] of splitTop(code, after + 1, end, close, false)) { |
| 340 | const colon = topColon(code, a, b, close); |
| 341 | if (colon >= 0) { |
| 342 | const field = code.slice(a, colon).trim(); |
| 343 | if (/^\w+$/.test(field)) walkPattern(code, colon + 1, b, close, { path: written, field }, emit); |
| 344 | continue; |
| 345 | } |
| 346 | // `name`, `ref name`, `mut name`, `ref mut name` bind the field of that name. |
| 347 | const text = code.slice(a, b); |
| 348 | const short = /^\s*(?:ref\s+)?(?:mut\s+)?([A-Za-z_]\w*)\s*$/.exec(text); |
| 349 | if (short && isBindingName(short[1]!)) emit(short[1]!, a + text.lastIndexOf(short[1]!), { path: written, field: short[1]! }); |
| 350 | } |
| 351 | p = end + 1; |
| 352 | continue; |
| 353 | } |
| 354 | if (path.segments.length === 1 && isBindingName(path.segments[0]!)) emit(path.segments[0]!, p, site); |
| 355 | // `name @ pattern`: the subpattern binds in its own right. |
| 356 | p = code[after] === '@' ? after + 1 : path.end; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /** The innermost `{…}` holding an offset, as [open, close]; null outside every block. */ |
| 361 | function blockAt(events: number[], open: number[], close: Map<number, number>, codeLength: number, offset: number): [number, number] | null { |
no test coverage detected