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

Function scanAnonymousRecord

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

* At a `record` keyword from `start` to `end`, recognize the declaration of a field, variable or typed constant of * an anonymous record type, followed by its `;`, a typed constant's `=`, or the `)` or `end` after a last field. The * `record` (or the `packed` before it) is written over by `string`

(s: string, start: number, end: number, ranges: number[], words: Array<[number, number, string]>)

Source from the content-addressed store, hash-verified

1005 * index to resume from.
1006 */
1007function scanAnonymousRecord(s: string, start: number, end: number, ranges: number[], words: Array<[number, number, string]>): number {
1008 if (anonymousRecordDeclStart(s, start) < 0) return end;
1009 const first = lowerWordAt(s, skipTrivia(s, end));
1010 if (first === '' || NOT_IN_RECORD_FIELDS.has(first)) return end; // `<T: record>`, `R: record;`
1011 const close = recordEnd(s, end);
1012 if (close < 0) return end;
1013 const next = skipTrivia(s, close);
1014 const c = s.charCodeAt(next);
1015 const last = lowerWordAt(s, next) === 'end'; // a last field, whose `;` Pascal lets go but the grammar needs
1016 if (c !== CH_SEMI && c !== CH_EQ && c !== CH_RPAREN && !last) return end;
1017 const packed = wordStartBefore(s, tokenEndBefore(s, start));
1018 const at = packed >= 0 && lowerWordAt(s, packed) === 'packed' ? packed : start;
1019 words.push([at, at + 6, 'string']);
1020 if (last) {
1021 ranges.push(at + 6, close - 3);
1022 words.push([close - 3, close, ';']);
1023 } else {
1024 ranges.push(at + 6, close);
1025 }
1026 return close;
1027}
1028
1029/**
1030 * `s` with every `[from, to)` range in `ranges` blanked to spaces, newlines kept, and every `[from, to, word]` in

Callers 1

preParsePascalFunction · 0.85

Calls 8

anonymousRecordDeclStartFunction · 0.85
lowerWordAtFunction · 0.85
recordEndFunction · 0.85
wordStartBeforeFunction · 0.85
tokenEndBeforeFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
skipTriviaFunction · 0.70

Tested by

no test coverage detected