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

Function tokenEndBefore

src/extraction/languages/pascal-preparse.ts:194–209  ·  view source on GitHub ↗

The index after the last character before `i` that is neither whitespace nor in a `{…}` or `(*…*)` comment.

(s: string, i: number)

Source from the content-addressed store, hash-verified

192
193/** The index after the last character before `i` that is neither whitespace nor in a `{…}` or `(*…*)` comment. */
194function tokenEndBefore(s: string, i: number): number {
195 for (;;) {
196 while (i > 0 && isSpace(s.charCodeAt(i - 1))) i--;
197 if (i > 0 && s.charCodeAt(i - 1) === CH_RBRACE) {
198 const open = s.lastIndexOf('{', i - 2);
199 if (open < 0) return i;
200 i = open;
201 } else if (i > 1 && s.charCodeAt(i - 1) === CH_RPAREN && s.charCodeAt(i - 2) === CH_STAR) {
202 const open = s.lastIndexOf('(*', i - 3);
203 if (open < 0) return i;
204 i = open;
205 } else {
206 return i;
207 }
208 }
209}
210
211/** The start of the identifier that ends at `i`, or -1 when none does. */
212function wordStartBefore(s: string, i: number): number {

Callers 2

anonymousRecordDeclStartFunction · 0.85
scanAnonymousRecordFunction · 0.85

Calls 1

isSpaceFunction · 0.70

Tested by

no test coverage detected