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

Function tokenEndBefore

src/extraction/languages/pascal-preparse.ts:189–204  ·  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

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