* 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)
| 960 | * routine type's parameters. |
| 961 | */ |
| 962 | function recordEnd(s: string, i: number): number { |
| 963 | const limit = Math.min(s.length, i + MAX_RECORD_LENGTH); |
| 964 | let depth = 1; |
| 965 | let brackets = 0; |
| 966 | let prev = ''; // the token before: a word lowercased, or its character |
| 967 | while (i < limit) { |
| 968 | const k = commentOrStringEnd(s, i); |
| 969 | if (k >= 0) { |
| 970 | if (s.charCodeAt(i) === CH_QUOTE) prev = "'"; |
| 971 | i = k; |
| 972 | continue; |
| 973 | } |
| 974 | const c = s.charCodeAt(i); |
| 975 | if (isIdentStart(c)) { |
| 976 | const e = wordEnd(s, i + 1); |
| 977 | const word = s.slice(i, e).toLowerCase(); |
| 978 | if (brackets === 0) { |
| 979 | if (word === 'end') { |
| 980 | if (--depth === 0) return e; |
| 981 | } else if (word === 'record') { |
| 982 | depth++; |
| 983 | } else if (NOT_IN_RECORD_FIELDS.has(word) && prev !== ':' && prev !== 'of' && prev !== 'to') { |
| 984 | return -1; |
| 985 | } |
| 986 | } |
| 987 | prev = word; |
| 988 | i = e; |
| 989 | continue; |
| 990 | } |
| 991 | if (c === CH_LPAREN || c === CH_LBRACKET) brackets++; |
| 992 | else if (c === CH_RPAREN || c === CH_RBRACKET) brackets--; |
| 993 | else if (c === CH_EQ && brackets === 0) return -1; |
| 994 | if (!isSpace(c)) prev = s[i]!; |
| 995 | i++; |
| 996 | } |
| 997 | return -1; |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * At a `record` keyword from `start` to `end`, recognize the declaration of a field, variable or typed constant of |
no test coverage detected