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

Function recordEnd

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

* The index after the `end` closing a record whose fields start at `i`, or -1 when they hold what a record's fields * can't. A word like `procedure` or `object` is part of a field's type after `:`, `of` or `to` (`OnIdle: procedure * of object`, `Get: reference to function: Integer`, `Args: array o

(s: string, i: number)

Source from the content-addressed store, hash-verified

890 * routine type's parameters.
891 */
892function recordEnd(s: string, i: number): number {
893 const limit = Math.min(s.length, i + MAX_RECORD_LENGTH);
894 let depth = 1;
895 let brackets = 0;
896 let prev = ''; // the token before: a word lowercased, or its character
897 while (i < limit) {
898 const k = commentOrStringEnd(s, i);
899 if (k >= 0) {
900 if (s.charCodeAt(i) === CH_QUOTE) prev = "'";
901 i = k;
902 continue;
903 }
904 const c = s.charCodeAt(i);
905 if (isIdentStart(c)) {
906 const e = wordEnd(s, i + 1);
907 const word = s.slice(i, e).toLowerCase();
908 if (brackets === 0) {
909 if (word === 'end') {
910 if (--depth === 0) return e;
911 } else if (word === 'record') {
912 depth++;
913 } else if (NOT_IN_RECORD_FIELDS.has(word) && prev !== ':' && prev !== 'of' && prev !== 'to') {
914 return -1;
915 }
916 }
917 prev = word;
918 i = e;
919 continue;
920 }
921 if (c === CH_LPAREN || c === CH_LBRACKET) brackets++;
922 else if (c === CH_RPAREN || c === CH_RBRACKET) brackets--;
923 else if (c === CH_EQ && brackets === 0) return -1;
924 if (!isSpace(c)) prev = s[i]!;
925 i++;
926 }
927 return -1;
928}
929
930/**
931 * At a `record` keyword from `start` to `end`, recognize the declaration of a field, variable or typed constant of

Callers 1

scanAnonymousRecordFunction · 0.85

Calls 5

commentOrStringEndFunction · 0.85
isIdentStartFunction · 0.85
hasMethod · 0.80
wordEndFunction · 0.70
isSpaceFunction · 0.70

Tested by

no test coverage detected