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

Function followsDeclaredName

src/extraction/languages/c-cpp.ts:987–1008  ·  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

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

Callers 1

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected