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

Function followsDeclaredName

src/extraction/languages/c-cpp.ts:986–1007  ·  view source on GitHub ↗

True when the identifier ending at `code[last]` is a name a declaration declares.

(code: string, last: number)

Source from the content-addressed store, hash-verified

984
985/** True when the identifier ending at `code[last]` is a name a declaration declares. */
986function followsDeclaredName(code: string, last: number): boolean {
987 let start = last;
988 while (start > 0 && /\w/.test(code[start - 1] as string)) start--;
989 const name = code.slice(start, last + 1);
990 if (!/^[A-Za-z_]\w*$/.test(name) || !/[a-z]/.test(name) || CPP_KEYWORDS.has(name)) return false;
991 let i = start - 1;
992 while (i >= 0 && /\s/.test(code[i] as string)) i--;
993 const c = code[i];
994 if (c === '*' || c === '&') return true;
995 if (c === '>') return code[i - 1] !== '-';
996 if (!c || !/\w/.test(c)) return false;
997 let j = i;
998 while (j > 0 && /\w/.test(code[j - 1] as string)) j--;
999 const before = code.slice(j, i + 1);
1000 if (before === 'const' || before === 'volatile') {
1001 let k = j - 1;
1002 while (k >= 0 && /\s/.test(code[k] as string)) k--;
1003 return code[k] === '*' || code[k] === '&';
1004 }
1005 if (CPP_TYPE_KEYWORDS.has(before)) return true;
1006 return /^[A-Za-z_]\w*$/.test(before) && !CPP_KEYWORDS.has(before);
1007}
1008
1009/** True when the `)` at `code[close]` closes a function declarator's parameter list. */
1010function closesParameterList(code: string, close: number): boolean {

Callers 1

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected