MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / bindPattern

Function bindPattern

src/resolution/rust-scopes.ts:515–533  ·  view source on GitHub ↗
(from: number, to: number, kind: RustBinding['kind'], scopeFrom: number, scopeTo: number, scrutinee?: string)

Source from the content-addressed store, hash-verified

513 else bindings.set(name, [binding]);
514 };
515 const bindPattern = (from: number, to: number, kind: RustBinding['kind'], scopeFrom: number, scopeTo: number, scrutinee?: string): void => {
516 const emit: Emit = (name, at, site) => add(name, { at, kind, from: scopeFrom, to: scopeTo, site, scrutinee });
517 // A tuple pattern, `(k, v)` or `(i, mut x)`: a name alone at its top is
518 // the tuple's field at its place (a site with no path).
519 const open = skipSpace(code, from);
520 const end = code[open] === '(' ? close.get(open) : undefined;
521 if (end !== undefined && end < to && skipSpace(code, end + 1) >= to) {
522 let index = 0;
523 for (const [a, b] of splitTop(code, open + 1, end, close, false)) {
524 const text = code.slice(a, b);
525 const simple = /^\s*(?:ref\s+)?(?:mut\s+)?([A-Za-z_]\w*)\s*$/.exec(text);
526 if (simple && isBindingName(simple[1]!)) emit(simple[1]!, a + text.lastIndexOf(simple[1]!), { path: '', index });
527 else walkPattern(code, a, b, close, undefined, emit);
528 index++;
529 }
530 return;
531 }
532 walkPattern(code, from, to, close, undefined, emit);
533 };
534 // A parameter `pattern: Type`, or a closure's `pattern`.
535 const param = (from: number, to: number, kind: 'param' | 'closure', scopeFrom: number, scopeTo: number): void => {
536 const colon = topColon(code, from, to, close);

Callers 2

paramFunction · 0.70
readRustBindingsFunction · 0.70

Calls 7

isBindingNameFunction · 0.85
walkPatternFunction · 0.85
skipSpaceFunction · 0.70
splitTopFunction · 0.70
emitFunction · 0.70
getMethod · 0.65
execMethod · 0.65

Tested by

no test coverage detected