@prisma-next/psl-parser 0.13.0-dev.4 → 0.13.0-dev.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{parser-Cw_zV0M5.mjs → parser-CaplKvRs.mjs} +110 -141
- package/dist/parser-CaplKvRs.mjs.map +1 -0
- package/dist/parser.mjs +1 -1
- package/dist/syntax.d.mts +63 -6
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +699 -15
- package/dist/syntax.mjs.map +1 -1
- package/dist/tokenizer-DdaOstnz.mjs +233 -0
- package/dist/tokenizer-DdaOstnz.mjs.map +1 -0
- package/dist/tokenizer.mjs +1 -190
- package/package.json +5 -5
- package/src/exports/index.ts +13 -2
- package/src/exports/syntax.ts +7 -1
- package/src/parse.ts +767 -0
- package/src/parser.ts +125 -196
- package/src/source-file.ts +89 -0
- package/src/syntax/ast/declarations.ts +7 -5
- package/src/syntax/ast/expressions.ts +144 -17
- package/src/syntax/syntax-kind.ts +7 -2
- package/src/tokenizer.ts +48 -0
- package/dist/parser-Cw_zV0M5.mjs.map +0 -1
- package/dist/tokenizer.mjs.map +0 -1
|
@@ -56,6 +56,78 @@ export class ArrayLiteralAst implements AstNode {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const HEX = /^[0-9a-fA-F]+$/;
|
|
60
|
+
|
|
61
|
+
function decodeFixedHex(raw: string, start: number, width: number): string | undefined {
|
|
62
|
+
if (start + width > raw.length) return undefined;
|
|
63
|
+
const hex = raw.slice(start, start + width);
|
|
64
|
+
if (!HEX.test(hex)) return undefined;
|
|
65
|
+
return String.fromCharCode(Number.parseInt(hex, 16));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function decodeStringLiteral(raw: string): string {
|
|
69
|
+
let out = '';
|
|
70
|
+
let i = 0;
|
|
71
|
+
while (i < raw.length) {
|
|
72
|
+
const ch = raw.charAt(i);
|
|
73
|
+
if (ch !== '\\' || i + 1 >= raw.length) {
|
|
74
|
+
out += ch;
|
|
75
|
+
i++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const next = raw.charAt(i + 1);
|
|
79
|
+
switch (next) {
|
|
80
|
+
case 'n':
|
|
81
|
+
out += '\n';
|
|
82
|
+
i += 2;
|
|
83
|
+
continue;
|
|
84
|
+
case 'r':
|
|
85
|
+
out += '\r';
|
|
86
|
+
i += 2;
|
|
87
|
+
continue;
|
|
88
|
+
case 't':
|
|
89
|
+
out += '\t';
|
|
90
|
+
i += 2;
|
|
91
|
+
continue;
|
|
92
|
+
case '"':
|
|
93
|
+
out += '"';
|
|
94
|
+
i += 2;
|
|
95
|
+
continue;
|
|
96
|
+
case '\\':
|
|
97
|
+
out += '\\';
|
|
98
|
+
i += 2;
|
|
99
|
+
continue;
|
|
100
|
+
case 'x': {
|
|
101
|
+
const decoded = decodeFixedHex(raw, i + 2, 2);
|
|
102
|
+
if (decoded === undefined) {
|
|
103
|
+
out += '\\x';
|
|
104
|
+
i += 2;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
out += decoded;
|
|
108
|
+
i += 4;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
case 'u': {
|
|
112
|
+
const decoded = decodeFixedHex(raw, i + 2, 4);
|
|
113
|
+
if (decoded === undefined) {
|
|
114
|
+
out += '\\u';
|
|
115
|
+
i += 2;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
out += decoded;
|
|
119
|
+
i += 6;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
out += `\\${next}`;
|
|
124
|
+
i += 2;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
59
131
|
export class StringLiteralExprAst implements AstNode {
|
|
60
132
|
readonly syntax: SyntaxNode;
|
|
61
133
|
|
|
@@ -70,23 +142,7 @@ export class StringLiteralExprAst implements AstNode {
|
|
|
70
142
|
value(): string | undefined {
|
|
71
143
|
const tok = this.token();
|
|
72
144
|
if (!tok) return undefined;
|
|
73
|
-
|
|
74
|
-
return raw.replace(/\\(.)/g, (_match, char: string) => {
|
|
75
|
-
switch (char) {
|
|
76
|
-
case 'n':
|
|
77
|
-
return '\n';
|
|
78
|
-
case 'r':
|
|
79
|
-
return '\r';
|
|
80
|
-
case 't':
|
|
81
|
-
return '\t';
|
|
82
|
-
case '"':
|
|
83
|
-
return '"';
|
|
84
|
-
case '\\':
|
|
85
|
-
return '\\';
|
|
86
|
-
default:
|
|
87
|
-
return `\\${char}`;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
145
|
+
return decodeStringLiteral(tok.text.slice(1, -1));
|
|
90
146
|
}
|
|
91
147
|
|
|
92
148
|
static cast(node: SyntaxNode): StringLiteralExprAst | undefined {
|
|
@@ -140,12 +196,82 @@ export class BooleanLiteralExprAst implements AstNode {
|
|
|
140
196
|
}
|
|
141
197
|
}
|
|
142
198
|
|
|
199
|
+
export class ObjectLiteralExprAst implements AstNode {
|
|
200
|
+
readonly syntax: SyntaxNode;
|
|
201
|
+
|
|
202
|
+
constructor(syntax: SyntaxNode) {
|
|
203
|
+
this.syntax = syntax;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
lbrace(): Token | undefined {
|
|
207
|
+
return findChildToken(this.syntax, 'LBrace');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
rbrace(): Token | undefined {
|
|
211
|
+
return findChildToken(this.syntax, 'RBrace');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
*fields(): Iterable<ObjectFieldAst> {
|
|
215
|
+
yield* filterChildren(this.syntax, ObjectFieldAst.cast);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static cast(node: SyntaxNode): ObjectLiteralExprAst | undefined {
|
|
219
|
+
return node.kind === 'ObjectLiteralExpr' ? new ObjectLiteralExprAst(node) : undefined;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class ObjectFieldAst implements AstNode {
|
|
224
|
+
readonly syntax: SyntaxNode;
|
|
225
|
+
|
|
226
|
+
constructor(syntax: SyntaxNode) {
|
|
227
|
+
this.syntax = syntax;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
key(): IdentifierAst | undefined {
|
|
231
|
+
for (const child of this.syntax.children()) {
|
|
232
|
+
if (!(child instanceof SyntaxNode)) {
|
|
233
|
+
if (child.kind === 'Colon') break;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
return IdentifierAst.cast(child);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
colon(): Token | undefined {
|
|
242
|
+
return findChildToken(this.syntax, 'Colon');
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
value(): ExpressionAst | undefined {
|
|
246
|
+
if (this.colon()) {
|
|
247
|
+
let pastColon = false;
|
|
248
|
+
for (const child of this.syntax.children()) {
|
|
249
|
+
if (!(child instanceof SyntaxNode)) {
|
|
250
|
+
if (child.kind === 'Colon') pastColon = true;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (pastColon) {
|
|
254
|
+
const expr = castExpression(child);
|
|
255
|
+
if (expr) return expr;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
return findFirstChild(this.syntax, castExpression);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static cast(node: SyntaxNode): ObjectFieldAst | undefined {
|
|
264
|
+
return node.kind === 'ObjectField' ? new ObjectFieldAst(node) : undefined;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
143
268
|
export type ExpressionAst =
|
|
144
269
|
| FunctionCallAst
|
|
145
270
|
| ArrayLiteralAst
|
|
146
271
|
| StringLiteralExprAst
|
|
147
272
|
| NumberLiteralExprAst
|
|
148
273
|
| BooleanLiteralExprAst
|
|
274
|
+
| ObjectLiteralExprAst
|
|
149
275
|
| IdentifierAst;
|
|
150
276
|
|
|
151
277
|
export function castExpression(node: SyntaxNode): ExpressionAst | undefined {
|
|
@@ -155,6 +281,7 @@ export function castExpression(node: SyntaxNode): ExpressionAst | undefined {
|
|
|
155
281
|
StringLiteralExprAst.cast(node) ??
|
|
156
282
|
NumberLiteralExprAst.cast(node) ??
|
|
157
283
|
BooleanLiteralExprAst.cast(node) ??
|
|
284
|
+
ObjectLiteralExprAst.cast(node) ??
|
|
158
285
|
IdentifierAst.cast(node)
|
|
159
286
|
);
|
|
160
287
|
}
|
|
@@ -5,7 +5,10 @@ export type SyntaxKind =
|
|
|
5
5
|
| 'CompositeTypeDeclaration'
|
|
6
6
|
| 'Namespace'
|
|
7
7
|
| 'TypesBlock'
|
|
8
|
-
|
|
8
|
+
// The generic/extension block node — the `kw [name] { key = value }` form
|
|
9
|
+
// produced by `parseGenericBlock`. Deliberately distinct from the reserved
|
|
10
|
+
// `model`/`enum`/`namespace`/`type`/`types` declarations above.
|
|
11
|
+
| 'GenericBlockDeclaration'
|
|
9
12
|
| 'FieldDeclaration'
|
|
10
13
|
| 'EnumValueDeclaration'
|
|
11
14
|
| 'NamedTypeDeclaration'
|
|
@@ -20,4 +23,6 @@ export type SyntaxKind =
|
|
|
20
23
|
| 'ArrayLiteral'
|
|
21
24
|
| 'StringLiteralExpr'
|
|
22
25
|
| 'NumberLiteralExpr'
|
|
23
|
-
| 'BooleanLiteralExpr'
|
|
26
|
+
| 'BooleanLiteralExpr'
|
|
27
|
+
| 'ObjectLiteralExpr'
|
|
28
|
+
| 'ObjectField';
|
package/src/tokenizer.ts
CHANGED
|
@@ -86,6 +86,7 @@ function scan(source: string, pos: number): Token {
|
|
|
86
86
|
scanWhitespace(source, pos) ??
|
|
87
87
|
scanComment(source, pos) ??
|
|
88
88
|
scanAt(source, pos) ??
|
|
89
|
+
scanKeywordNumber(source, pos) ??
|
|
89
90
|
scanIdent(source, pos) ??
|
|
90
91
|
scanNumber(source, pos) ??
|
|
91
92
|
scanString(source, pos) ??
|
|
@@ -151,6 +152,22 @@ function scanIdent(source: string, pos: number): Token | undefined {
|
|
|
151
152
|
return { kind: 'Ident', text: source.slice(pos, end) };
|
|
152
153
|
}
|
|
153
154
|
|
|
155
|
+
const KEYWORD_NUMBERS = ['-Infinity', 'Infinity', 'NaN'] as const;
|
|
156
|
+
|
|
157
|
+
// `NaN`, `Infinity`, and `-Infinity` are numeric literals, not identifiers.
|
|
158
|
+
// They must match before `scanIdent` (which would otherwise claim the
|
|
159
|
+
// identifier-led words) and are word-bounded: a following identifier-part char
|
|
160
|
+
// (so `Infinityx` / `NaNxyz`) keeps the run an `Ident` rather than a number.
|
|
161
|
+
function scanKeywordNumber(source: string, pos: number): Token | undefined {
|
|
162
|
+
for (const word of KEYWORD_NUMBERS) {
|
|
163
|
+
if (!source.startsWith(word, pos)) continue;
|
|
164
|
+
const after = readChar(source, pos + word.length);
|
|
165
|
+
if (after !== '' && isIdentPart(after)) return undefined;
|
|
166
|
+
return { kind: 'NumberLiteral', text: word };
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
154
171
|
function scanNumber(source: string, pos: number): Token | undefined {
|
|
155
172
|
let end = pos;
|
|
156
173
|
if (source.charAt(end) === '-') {
|
|
@@ -195,6 +212,37 @@ function scanString(source: string, pos: number): Token | undefined {
|
|
|
195
212
|
return { kind: 'StringLiteral', text: source.slice(pos, end) };
|
|
196
213
|
}
|
|
197
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Whether a `StringLiteral` token's text is properly closed. `scanString` emits
|
|
217
|
+
* the same `StringLiteral` kind for both well-formed and unterminated strings —
|
|
218
|
+
* it stops at a newline or EOF when no closing quote is found — so callers that
|
|
219
|
+
* need to distinguish the two ask here.
|
|
220
|
+
*
|
|
221
|
+
* Because `scanString` stops at the *first* unescaped `"`, the only quote whose
|
|
222
|
+
* escaping can be in question is the **last character**: the text is terminated
|
|
223
|
+
* iff it opens with `"`, ends with `"`, and that closing `"` is not escaped.
|
|
224
|
+
* Under the `\\`-escapes-the-next-character rule, a `"` is unescaped iff an
|
|
225
|
+
* **even** number of backslashes immediately precede it — each `\\` pair cancels,
|
|
226
|
+
* and an odd run leaves the final `\` escaping the quote. So it suffices to
|
|
227
|
+
* count the trailing backslash run; no full re-scan is needed:
|
|
228
|
+
*
|
|
229
|
+
* - `"ok"` → 0 backslashes (even) → closing quote stands → terminated
|
|
230
|
+
* - `"a\"` → 1 backslash (odd) → the `"` is escaped → unterminated
|
|
231
|
+
* - `"a\\"` → 2 backslashes (even) → escaped `\`, real `"` → terminated
|
|
232
|
+
*
|
|
233
|
+
* A lone `"` (length 1) or a text with no closing `"` is unterminated.
|
|
234
|
+
*/
|
|
235
|
+
export function isTerminatedStringLiteral(text: string): boolean {
|
|
236
|
+
if (text.length < 2 || text.charAt(0) !== '"' || text.charAt(text.length - 1) !== '"') {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
let backslashes = 0;
|
|
240
|
+
for (let i = text.length - 2; i >= 1 && text.charAt(i) === '\\'; i--) {
|
|
241
|
+
backslashes++;
|
|
242
|
+
}
|
|
243
|
+
return backslashes % 2 === 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
198
246
|
function scanPunctuation(source: string, pos: number): Token | undefined {
|
|
199
247
|
const kind = PUNCTUATION[source.charAt(pos)];
|
|
200
248
|
if (kind === undefined) return undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser-Cw_zV0M5.mjs","names":[],"sources":["../src/parser.ts"],"sourcesContent":["import type {\n AuthoringPslBlockDescriptor,\n AuthoringPslBlockDescriptorNamespace,\n} from '@prisma-next/framework-components/authoring';\nimport { isAuthoringPslBlockDescriptor } from '@prisma-next/framework-components/authoring';\nimport { emptyCodecLookup } from '@prisma-next/framework-components/codec';\nimport type {\n ParsePslDocumentInput,\n ParsePslDocumentResult,\n PslAttribute,\n PslAttributeArgument,\n PslAttributeTarget,\n PslCompositeType,\n PslDiagnostic,\n PslDiagnosticCode,\n PslDocumentAst,\n PslEnum,\n PslEnumValue,\n PslExtensionBlock,\n PslExtensionBlockParamValue,\n PslField,\n PslFieldAttribute,\n PslModel,\n PslModelAttribute,\n PslNamedTypeDeclaration,\n PslNamespace,\n PslPosition,\n PslSpan,\n PslTypeConstructorCall,\n PslTypesBlock,\n} from '@prisma-next/framework-components/psl-ast';\nimport {\n makePslNamespace,\n makePslNamespaceEntries,\n namespacePslExtensionBlocks,\n UNSPECIFIED_PSL_NAMESPACE_ID,\n validateExtensionBlock,\n} from '@prisma-next/framework-components/psl-ast';\nimport { ifDefined } from '@prisma-next/utils/defined';\n\nconst SCALAR_TYPES = new Set([\n 'String',\n 'Boolean',\n 'Int',\n 'BigInt',\n 'Float',\n 'Decimal',\n 'DateTime',\n 'Json',\n 'Bytes',\n]);\n\ninterface BlockBounds {\n readonly startLine: number;\n readonly endLine: number;\n readonly closed: boolean;\n}\n\ninterface ParserContext {\n readonly schema: string;\n readonly sourceId: string;\n readonly lines: readonly string[];\n readonly lineOffsets: readonly number[];\n readonly diagnostics: PslDiagnostic[];\n}\n\nexport function parsePslDocument(input: ParsePslDocumentInput): ParsePslDocumentResult {\n const normalizedSchema = input.schema.replaceAll('\\r\\n', '\\n');\n const lines = normalizedSchema.split('\\n');\n const lineOffsets = computeLineOffsets(normalizedSchema);\n const diagnostics: PslDiagnostic[] = [];\n const context: ParserContext = {\n schema: normalizedSchema,\n sourceId: input.sourceId,\n lines,\n lineOffsets,\n diagnostics,\n };\n\n interface NamespaceAccumulator {\n name: string;\n models: PslModel[];\n enums: PslEnum[];\n compositeTypes: PslCompositeType[];\n extensionBlocks: PslExtensionBlock[];\n span: PslSpan | undefined;\n }\n\n const namespaceOrder: string[] = [];\n const namespacesByName = new Map<string, NamespaceAccumulator>();\n const getOrCreateNamespace = (\n name: string,\n spanIfNew: PslSpan | undefined,\n ): NamespaceAccumulator => {\n let acc = namespacesByName.get(name);\n if (!acc) {\n acc = {\n name,\n models: [],\n enums: [],\n compositeTypes: [],\n extensionBlocks: [],\n span: spanIfNew,\n };\n namespacesByName.set(name, acc);\n namespaceOrder.push(name);\n }\n return acc;\n };\n\n let typesBlock: PslTypesBlock | undefined;\n const pslBlockNamespace: AuthoringPslBlockDescriptorNamespace = input.pslBlockDescriptors ?? {};\n\n // Walk a contiguous range of lines, routing top-level declarations into the\n // active namespace bucket. Called once for the whole document and once per\n // `namespace { … }` block body; nested `namespace { … }` or `types { … }`\n // blocks inside a namespace body are rejected with a diagnostic.\n const parseBody = (\n startLine: number,\n endLineExclusive: number,\n currentNamespaceName: string,\n isInsideNamespace: boolean,\n ): void => {\n let lineIndex = startLine;\n while (lineIndex < endLineExclusive) {\n const rawLine = context.lines[lineIndex] ?? '';\n const line = stripInlineComment(rawLine).trim();\n if (line.length === 0) {\n lineIndex += 1;\n continue;\n }\n\n const modelMatch = line.match(/^model\\s+([A-Za-z_]\\w*)\\s*\\{$/);\n if (modelMatch) {\n const bounds = findBlockBounds(context, lineIndex);\n const name = modelMatch[1] ?? '';\n if (name.length > 0) {\n const acc = getOrCreateNamespace(\n currentNamespaceName,\n createTrimmedLineSpan(context, lineIndex),\n );\n acc.models.push(parseModelBlock(context, name, bounds));\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n const enumMatch = line.match(/^enum\\s+([A-Za-z_]\\w*)\\s*\\{$/);\n if (enumMatch) {\n const bounds = findBlockBounds(context, lineIndex);\n const name = enumMatch[1] ?? '';\n if (name.length > 0) {\n const acc = getOrCreateNamespace(\n currentNamespaceName,\n createTrimmedLineSpan(context, lineIndex),\n );\n acc.enums.push(parseEnumBlock(context, name, bounds));\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n const compositeTypeMatch = line.match(/^type\\s+([A-Za-z_]\\w*)\\s*\\{$/);\n if (compositeTypeMatch) {\n const bounds = findBlockBounds(context, lineIndex);\n const name = compositeTypeMatch[1] ?? '';\n if (name.length > 0) {\n const acc = getOrCreateNamespace(\n currentNamespaceName,\n createTrimmedLineSpan(context, lineIndex),\n );\n acc.compositeTypes.push(parseCompositeTypeBlock(context, name, bounds));\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n const namespaceMatch = line.match(/^namespace\\s+([A-Za-z_]\\w*)\\s*\\{$/);\n if (namespaceMatch) {\n const bounds = findBlockBounds(context, lineIndex);\n const name = namespaceMatch[1] ?? '';\n if (isInsideNamespace) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_NAMESPACE_BLOCK',\n message: `Recursive \"namespace ${name}\" block is not allowed; namespace blocks may not nest`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n } else if (name === UNSPECIFIED_PSL_NAMESPACE_ID) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_NAMESPACE_BLOCK',\n message: `Namespace name \"${UNSPECIFIED_PSL_NAMESPACE_ID}\" is reserved for the parser-synthesised bucket for top-level declarations`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n } else if (name.length > 0) {\n getOrCreateNamespace(name, createTrimmedLineSpan(context, lineIndex));\n parseBody(bounds.startLine + 1, bounds.endLine, name, true);\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n if (/^types\\s*\\{$/.test(line)) {\n const bounds = findBlockBounds(context, lineIndex);\n if (isInsideNamespace) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_NAMESPACE_BLOCK',\n message:\n '`types` blocks must be declared at the document top level, not inside a namespace block',\n span: createTrimmedLineSpan(context, lineIndex),\n });\n } else if (typesBlock !== undefined) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: 'Only one top-level `types` block is allowed per document',\n span: createTrimmedLineSpan(context, lineIndex),\n });\n } else {\n typesBlock = parseTypesBlock(context, bounds);\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n const extensionBlockMatch = line.match(/^([A-Za-z_]\\w*)\\s+([A-Za-z_]\\w*)\\s*\\{$/);\n if (extensionBlockMatch) {\n const keyword = extensionBlockMatch[1] ?? '';\n const blockName = extensionBlockMatch[2] ?? '';\n const descriptor = lookupExtensionBlockDescriptor(pslBlockNamespace, keyword);\n if (descriptor) {\n const bounds = findBlockBounds(context, lineIndex);\n if (blockName.length > 0) {\n const acc = getOrCreateNamespace(\n currentNamespaceName,\n createTrimmedLineSpan(context, lineIndex),\n );\n const node = parseExtensionBlock(context, descriptor, blockName, lineIndex, bounds);\n acc.extensionBlocks.push(node);\n }\n lineIndex = bounds.endLine + 1;\n continue;\n }\n }\n\n if (line.includes('{')) {\n const blockName = line.split(/\\s+/)[0] ?? 'block';\n pushDiagnostic(context, {\n code: 'PSL_UNSUPPORTED_TOP_LEVEL_BLOCK',\n message: `Unsupported top-level block \"${blockName}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n const bounds = findBlockBounds(context, lineIndex);\n lineIndex = bounds.endLine + 1;\n continue;\n }\n\n pushDiagnostic(context, {\n code: 'PSL_UNSUPPORTED_TOP_LEVEL_BLOCK',\n message: `Unsupported top-level declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n lineIndex += 1;\n }\n };\n\n parseBody(0, lines.length, UNSPECIFIED_PSL_NAMESPACE_ID, false);\n\n // Named-type validation: types are document-scoped (one block, outside any\n // namespace), so collision checks compare named-type names against every\n // model/enum/composite-type in every namespace.\n const allModels: PslModel[] = [];\n const allEnums: PslEnum[] = [];\n const allCompositeTypes: PslCompositeType[] = [];\n for (const name of namespaceOrder) {\n const acc = namespacesByName.get(name);\n if (!acc) continue;\n allModels.push(...acc.models);\n allEnums.push(...acc.enums);\n allCompositeTypes.push(...acc.compositeTypes);\n }\n\n const namedTypeNames = new Set(\n (typesBlock?.declarations ?? []).map((declaration) => declaration.name),\n );\n const modelNames = new Set(allModels.map((model) => model.name));\n const enumNames = new Set(allEnums.map((enumBlock) => enumBlock.name));\n const compositeTypeNames = new Set(allCompositeTypes.map((ct) => ct.name));\n for (const declaration of typesBlock?.declarations ?? []) {\n if (SCALAR_TYPES.has(declaration.name)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: `Named type \"${declaration.name}\" conflicts with scalar type \"${declaration.name}\"`,\n span: declaration.span,\n });\n continue;\n }\n if (modelNames.has(declaration.name)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: `Named type \"${declaration.name}\" conflicts with model name \"${declaration.name}\"`,\n span: declaration.span,\n });\n continue;\n }\n if (enumNames.has(declaration.name)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: `Named type \"${declaration.name}\" conflicts with enum name \"${declaration.name}\"`,\n span: declaration.span,\n });\n }\n }\n\n const documentSpan: PslSpan = {\n start: createPosition(context, 0, 0),\n end: createPosition(\n context,\n Math.max(lines.length - 1, 0),\n (lines[Math.max(lines.length - 1, 0)] ?? '').length,\n ),\n };\n\n const namespaces: PslNamespace[] = [];\n for (const name of namespaceOrder) {\n const acc = namespacesByName.get(name);\n if (!acc) continue;\n // Drop the synthesised __unspecified__ entry when it ended up empty (e.g.\n // every declaration in the document lived inside an explicit\n // `namespace { … }` block). Keeping a phantom bucket would force every\n // downstream consumer to special-case \"namespace with no members\".\n if (\n name === UNSPECIFIED_PSL_NAMESPACE_ID &&\n acc.models.length === 0 &&\n acc.enums.length === 0 &&\n acc.compositeTypes.length === 0 &&\n acc.extensionBlocks.length === 0\n ) {\n continue;\n }\n const normalizedModels = acc.models.map((model) => ({\n ...model,\n fields: model.fields.map((field) => {\n if (!namedTypeNames.has(field.typeName)) {\n return field;\n }\n const hasRelationAttribute = field.attributes.some(\n (attribute) => attribute.name === 'relation',\n );\n if (\n hasRelationAttribute ||\n modelNames.has(field.typeName) ||\n enumNames.has(field.typeName) ||\n compositeTypeNames.has(field.typeName) ||\n SCALAR_TYPES.has(field.typeName)\n ) {\n return field;\n }\n return {\n ...field,\n typeRef: field.typeName,\n };\n }),\n }));\n namespaces.push(\n makePslNamespace({\n kind: 'namespace',\n name,\n entries: makePslNamespaceEntries(\n normalizedModels,\n acc.enums,\n acc.compositeTypes,\n acc.extensionBlocks,\n ),\n span: acc.span ?? documentSpan,\n }),\n );\n }\n\n // Validate extension blocks with the generic validator after the full\n // AST is assembled. The validator needs all namespaces for ref resolution.\n // It runs whenever pslBlockDescriptors are registered — codecLookup falls\n // back to emptyCodecLookup when not provided, which rejects value-kind\n // parameters with unknown codecs. Callers with value parameters should\n // always supply a codecLookup.\n if (Object.keys(pslBlockNamespace).length > 0) {\n const codecLookup = input.codecLookup ?? emptyCodecLookup;\n // Build a discriminator → descriptor reverse map from the descriptor\n // namespace. The parser keyed by keyword; the validator resolves by\n // node.kind (= discriminator) so we need the reverse direction.\n const descriptorByDiscriminator = new Map<string, AuthoringPslBlockDescriptor>();\n for (const value of Object.values(pslBlockNamespace)) {\n if (isAuthoringPslBlockDescriptor(value)) {\n descriptorByDiscriminator.set(value.discriminator, value);\n }\n }\n for (const ns of namespaces) {\n // Collect extension blocks from entries using the canonical helper, then\n // filter to only those whose discriminator is registered in the namespace.\n for (const block of namespacePslExtensionBlocks(ns)) {\n const descriptor = descriptorByDiscriminator.get(block.kind);\n if (descriptor === undefined) {\n continue;\n }\n const blockDiagnostics = validateExtensionBlock(\n block,\n descriptor,\n input.sourceId,\n codecLookup,\n {\n ownerNamespace: ns,\n allNamespaces: namespaces,\n },\n );\n diagnostics.push(...blockDiagnostics);\n }\n }\n }\n\n const ast: PslDocumentAst = {\n kind: 'document',\n sourceId: input.sourceId,\n namespaces,\n ...ifDefined('types', typesBlock),\n span: documentSpan,\n };\n\n return {\n ast,\n diagnostics,\n ok: diagnostics.length === 0,\n };\n}\n\nfunction parseModelBlock(context: ParserContext, name: string, bounds: BlockBounds): PslModel {\n const fields: PslField[] = [];\n const attributes: PslModelAttribute[] = [];\n\n for (let lineIndex = bounds.startLine + 1; lineIndex < bounds.endLine; lineIndex += 1) {\n const raw = context.lines[lineIndex] ?? '';\n const line = stripInlineComment(raw).trim();\n if (line.length === 0) {\n continue;\n }\n\n if (line.startsWith('@@')) {\n const attribute = parseModelAttribute(context, line, lineIndex);\n if (attribute) {\n attributes.push(attribute);\n }\n continue;\n }\n\n const field = parseField(context, line, lineIndex);\n if (field) {\n fields.push(field);\n }\n }\n\n return {\n kind: 'model',\n name,\n fields,\n attributes,\n span: createLineRangeSpan(context, bounds.startLine, bounds.endLine),\n };\n}\n\nfunction parseCompositeTypeBlock(\n context: ParserContext,\n name: string,\n bounds: BlockBounds,\n): PslCompositeType {\n const fields: PslField[] = [];\n const attributes: PslAttribute[] = [];\n\n for (let lineIndex = bounds.startLine + 1; lineIndex < bounds.endLine; lineIndex += 1) {\n const raw = context.lines[lineIndex] ?? '';\n const line = stripInlineComment(raw).trim();\n if (line.length === 0) {\n continue;\n }\n\n if (line.startsWith('@@')) {\n const attribute = parseModelAttribute(context, line, lineIndex);\n if (attribute) {\n attributes.push(attribute);\n }\n continue;\n }\n\n const field = parseField(context, line, lineIndex);\n if (field) {\n fields.push(field);\n }\n }\n\n return {\n kind: 'compositeType',\n name,\n fields,\n attributes,\n span: createLineRangeSpan(context, bounds.startLine, bounds.endLine),\n };\n}\n\nfunction parseEnumBlock(context: ParserContext, name: string, bounds: BlockBounds): PslEnum {\n const values: PslEnumValue[] = [];\n const attributes: PslAttribute[] = [];\n\n for (let lineIndex = bounds.startLine + 1; lineIndex < bounds.endLine; lineIndex += 1) {\n const raw = context.lines[lineIndex] ?? '';\n const line = stripInlineComment(raw).trim();\n if (line.length === 0) {\n continue;\n }\n\n if (line.startsWith('@@')) {\n const attribute = parseEnumAttribute(context, line, lineIndex);\n if (attribute) {\n attributes.push(attribute);\n }\n continue;\n }\n\n // An enum member line is the bare member identifier, optionally followed\n // by a `@map(\"storage-label\")` attribute. The map attribute lets the\n // printer round-trip enum values whose original storage label is not a\n // valid PSL identifier (e.g. PostgreSQL enum labels with hyphens).\n const valueMatch = line.match(/^([A-Za-z_]\\w*)(?:\\s+@map\\(\\s*\"((?:[^\"\\\\]|\\\\.)*)\"\\s*\\))?$/);\n if (!valueMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ENUM_MEMBER',\n message: `Invalid enum value declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n continue;\n }\n\n const mapName = valueMatch[2] !== undefined ? unescapePslString(valueMatch[2]) : undefined;\n\n values.push({\n kind: 'enumValue',\n name: valueMatch[1] ?? '',\n ...(mapName !== undefined ? { mapName } : {}),\n span: createTrimmedLineSpan(context, lineIndex),\n });\n }\n\n return {\n kind: 'enum',\n name,\n values,\n attributes,\n span: createLineRangeSpan(context, bounds.startLine, bounds.endLine),\n };\n}\n\n/**\n * Decode PSL escape sequences (`\\\\`, `\\\"`, `\\'`, `\\n`, `\\r`) inside a\n * quoted-literal body. The argument is the body of the literal with the\n * surrounding quotes already stripped by the caller. Mirrors the inverse\n * helper in `@prisma-next/psl-printer`'s `escapePslString` so a string\n * round-trips parser → printer → parser unchanged.\n */\nfunction unescapePslString(value: string): string {\n let result = '';\n for (let i = 0; i < value.length; i++) {\n const ch = value.charCodeAt(i);\n if (ch !== 0x5c /* '\\\\' */ || i + 1 >= value.length) {\n result += value[i];\n continue;\n }\n const next = value[i + 1];\n if (next === '\\\\' || next === '\"' || next === \"'\") {\n result += next;\n } else if (next === 'n') {\n result += '\\n';\n } else if (next === 'r') {\n result += '\\r';\n } else {\n result += '\\\\';\n result += next;\n }\n i++;\n }\n return result;\n}\n\nfunction parseTypesBlock(context: ParserContext, bounds: BlockBounds): PslTypesBlock {\n const declarations: PslNamedTypeDeclaration[] = [];\n\n for (let lineIndex = bounds.startLine + 1; lineIndex < bounds.endLine; lineIndex += 1) {\n const raw = context.lines[lineIndex] ?? '';\n const lineWithoutComment = stripInlineComment(raw);\n const line = lineWithoutComment.trim();\n if (line.length === 0) {\n continue;\n }\n\n const declarationMatch = line.match(/^([A-Za-z_]\\w*)\\s*=\\s*(.+)$/);\n if (!declarationMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: `Invalid types declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n continue;\n }\n\n const declarationName = declarationMatch[1] ?? '';\n const trimmedStartColumn = firstNonWhitespaceColumn(raw);\n const declarationValue = (declarationMatch[2] ?? '').trim();\n const valueOffset = line.indexOf(declarationValue);\n const declarationValueColumn = trimmedStartColumn + Math.max(valueOffset, 0);\n\n const typeAndAttributeSplit = splitTypeAndAttributes(declarationValue);\n const typeSource = typeAndAttributeSplit.typeSource.trim();\n const attributeSource = typeAndAttributeSplit.attributeSource.trimStart();\n const leadingAttributeWhitespace =\n typeAndAttributeSplit.attributeSource.length - attributeSource.length;\n\n const typeConstructor = parseTypeConstructorCall(context, {\n declarationValue: typeSource,\n lineIndex,\n startColumn: declarationValueColumn,\n invalidCode: 'PSL_INVALID_TYPES_MEMBER',\n invalidMessage: (value) => `Invalid types declaration \"${value}\"`,\n });\n if (typeConstructor === 'malformed') {\n continue;\n }\n\n const attributeParse = extractAttributeTokensWithSpans(\n context,\n lineIndex,\n attributeSource,\n declarationValueColumn + typeAndAttributeSplit.attributeOffset + leadingAttributeWhitespace,\n );\n if (!attributeParse.ok) {\n continue;\n }\n const attributes = attributeParse.tokens\n .map((token) =>\n parseAttributeToken(context, {\n token: token.text,\n target: 'namedType',\n lineIndex,\n span: token.span,\n }),\n )\n .filter((attribute): attribute is PslAttribute => Boolean(attribute));\n\n if (typeConstructor) {\n declarations.push({\n kind: 'namedType',\n name: declarationName,\n typeConstructor,\n attributes,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n continue;\n }\n\n const baseTypeMatch = typeSource.match(/^([A-Za-z_]\\w*)$/);\n if (!baseTypeMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_TYPES_MEMBER',\n message: `Invalid types declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n continue;\n }\n\n const baseType = baseTypeMatch[1] ?? '';\n\n declarations.push({\n kind: 'namedType',\n name: declarationName,\n baseType,\n attributes,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n }\n\n return {\n kind: 'types',\n declarations,\n span: createLineRangeSpan(context, bounds.startLine, bounds.endLine),\n };\n}\n\nfunction parseTypeConstructorCall(\n context: ParserContext,\n input: {\n readonly declarationValue: string;\n readonly lineIndex: number;\n readonly startColumn: number;\n readonly invalidCode: PslDiagnosticCode;\n readonly invalidMessage: (value: string) => string;\n },\n): PslTypeConstructorCall | 'malformed' | undefined {\n const value = input.declarationValue.trim();\n const constructorMatch = value.match(\n /^([A-Za-z_][A-Za-z0-9_-]*(?:\\.[A-Za-z_][A-Za-z0-9_-]*)*)\\s*\\(/,\n );\n if (!constructorMatch) {\n return undefined;\n }\n\n // constructorMatch already required `(`; openParen is guaranteed ≥ 0.\n const openParen = value.indexOf('(');\n const closeParen = value.lastIndexOf(')');\n\n if (closeParen !== value.length - 1) {\n pushDiagnostic(context, {\n code: input.invalidCode,\n message: input.invalidMessage(value),\n span: createInlineSpan(\n context,\n input.lineIndex,\n input.startColumn,\n input.startColumn + value.length,\n ),\n });\n return 'malformed';\n }\n\n const constructorPath = constructorMatch[1] ?? '';\n\n const argsRaw = value.slice(openParen + 1, closeParen);\n const args = parseArgumentList(context, {\n argsRaw,\n argsOffset: input.startColumn + openParen + 1,\n lineIndex: input.lineIndex,\n token: value,\n span: createInlineSpan(\n context,\n input.lineIndex,\n input.startColumn,\n input.startColumn + value.length,\n ),\n invalidCode: input.invalidCode,\n invalidEmptyArgumentMessage: `Invalid empty argument in type constructor \"${value}\"`,\n invalidNamedArgumentMessage: (part) =>\n `Invalid named argument syntax \"${part}\" in type constructor \"${value}\"`,\n });\n if (!args) {\n return 'malformed';\n }\n\n return {\n kind: 'typeConstructor',\n path: constructorPath.split('.'),\n args,\n span: createInlineSpan(\n context,\n input.lineIndex,\n input.startColumn,\n input.startColumn + value.length,\n ),\n };\n}\n\nfunction parseModelAttribute(\n context: ParserContext,\n line: string,\n lineIndex: number,\n): PslModelAttribute | undefined {\n const rawLine = context.lines[lineIndex] ?? '';\n const tokenParse = extractAttributeTokensWithSpans(\n context,\n lineIndex,\n line,\n firstNonWhitespaceColumn(rawLine),\n );\n if (!tokenParse.ok || tokenParse.tokens.length !== 1) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid model attribute syntax \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n const token = tokenParse.tokens[0];\n if (!token) {\n return undefined;\n }\n return parseAttributeToken(context, {\n token: token.text,\n target: 'model',\n lineIndex,\n span: token.span,\n });\n}\n\nfunction parseEnumAttribute(\n context: ParserContext,\n line: string,\n lineIndex: number,\n): PslAttribute | undefined {\n const rawLine = context.lines[lineIndex] ?? '';\n const tokenParse = extractAttributeTokensWithSpans(\n context,\n lineIndex,\n line,\n firstNonWhitespaceColumn(rawLine),\n );\n if (!tokenParse.ok || tokenParse.tokens.length !== 1) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ENUM_MEMBER',\n message: `Invalid enum value declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n const token = tokenParse.tokens[0];\n if (!token) {\n return undefined;\n }\n const parsed = parseAttributeToken(context, {\n token: token.text,\n target: 'enum',\n lineIndex,\n span: token.span,\n });\n if (!parsed) {\n return undefined;\n }\n if (parsed.name !== 'map') {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ENUM_MEMBER',\n message: `Invalid enum value declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n return parsed;\n}\n\nfunction parseField(context: ParserContext, line: string, lineIndex: number): PslField | undefined {\n const fieldMatch = line.match(/^([A-Za-z_]\\w*)(\\s+)(.+)$/);\n if (!fieldMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_MODEL_MEMBER',\n message: `Invalid model member declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n\n const fieldName = fieldMatch[1] ?? '';\n const separator = fieldMatch[2] ?? '';\n const remainder = fieldMatch[3] ?? '';\n const typeAndAttributeSplit = splitTypeAndAttributes(remainder);\n const rawTypeSource = typeAndAttributeSplit.typeSource.trim();\n const attributePart = typeAndAttributeSplit.attributeSource;\n const optional = rawTypeSource.endsWith('?');\n const typeSourceWithoutOptional = optional ? rawTypeSource.slice(0, -1).trimEnd() : rawTypeSource;\n const list = typeSourceWithoutOptional.endsWith('[]');\n const baseTypeSource = list\n ? typeSourceWithoutOptional.slice(0, -2).trimEnd()\n : typeSourceWithoutOptional;\n const rawLine = context.lines[lineIndex] ?? '';\n const trimmedStartColumn = firstNonWhitespaceColumn(rawLine);\n const typeStartColumn = trimmedStartColumn + fieldName.length + separator.length;\n\n const typeConstructor = parseTypeConstructorCall(context, {\n declarationValue: baseTypeSource,\n lineIndex,\n startColumn: typeStartColumn,\n invalidCode: 'PSL_INVALID_MODEL_MEMBER',\n invalidMessage: (value) => `Invalid field type constructor \"${value}\"`,\n });\n if (typeConstructor === 'malformed') {\n return undefined;\n }\n\n let typeName: string;\n let typeNamespaceId: string | undefined;\n let typeContractSpaceId: string | undefined;\n\n if (typeConstructor) {\n typeName = typeConstructor.path.join('.');\n } else {\n // Detect the colon-prefix cross-contract-space form: `<space>:<rest>` where\n // `<rest>` is the existing dot-qualified or bare form (`<ns>.<Name>` or `<Name>`).\n // Multiple colons (e.g. `a:b:c`) are invalid.\n const colonCount = (baseTypeSource.match(/:/g) ?? []).length;\n if (colonCount > 1) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_MODEL_MEMBER',\n message: `Invalid model member declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n\n let typeRefSource: string;\n if (colonCount === 1) {\n // Colon-prefix form: `<space>:<rest>`\n const colonIndex = baseTypeSource.indexOf(':');\n const spaceCandidate = baseTypeSource.slice(0, colonIndex);\n typeRefSource = baseTypeSource.slice(colonIndex + 1);\n // Validate space identifier\n if (!/^[A-Za-z_]\\w*$/.test(spaceCandidate)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_MODEL_MEMBER',\n message: `Invalid model member declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n typeContractSpaceId = spaceCandidate;\n } else {\n typeRefSource = baseTypeSource;\n }\n\n const dotCount = (typeRefSource.match(/\\./g) ?? []).length;\n if (dotCount > 1) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_QUALIFIED_TYPE',\n message: `Nested dot-qualified type \"${baseTypeSource}\" is not supported; use exactly one qualifier segment (e.g. \"ns.TypeName\")`,\n span: createInlineSpan(\n context,\n lineIndex,\n typeStartColumn,\n typeStartColumn + baseTypeSource.length,\n ),\n });\n return undefined;\n }\n const singleMatch = typeRefSource.match(/^([A-Za-z_]\\w*)(?:\\.([A-Za-z_]\\w*))?$/);\n if (!singleMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_MODEL_MEMBER',\n message: `Invalid model member declaration \"${line}\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n return undefined;\n }\n if (singleMatch[2] !== undefined) {\n typeNamespaceId = singleMatch[1];\n typeName = singleMatch[2];\n } else {\n typeName = singleMatch[1] ?? '';\n }\n }\n\n const attributes: PslFieldAttribute[] = [];\n const attributeSource = attributePart.trimStart();\n const leadingAttributeWhitespace = attributePart.length - attributeSource.length;\n const tokenParse = extractAttributeTokensWithSpans(\n context,\n lineIndex,\n attributeSource,\n trimmedStartColumn +\n fieldName.length +\n separator.length +\n typeAndAttributeSplit.attributeOffset +\n leadingAttributeWhitespace,\n );\n if (!tokenParse.ok) {\n return {\n kind: 'field',\n name: fieldName,\n typeName,\n ...ifDefined('typeNamespaceId', typeNamespaceId),\n ...ifDefined('typeContractSpaceId', typeContractSpaceId),\n ...ifDefined('typeConstructor', typeConstructor),\n optional,\n list,\n attributes,\n span: createTrimmedLineSpan(context, lineIndex),\n };\n }\n\n for (const token of tokenParse.tokens) {\n const parsed = parseAttributeToken(context, {\n token: token.text,\n target: 'field',\n lineIndex,\n span: token.span,\n });\n if (parsed) {\n attributes.push(parsed);\n }\n }\n\n return {\n kind: 'field',\n name: fieldName,\n typeName,\n ...ifDefined('typeNamespaceId', typeNamespaceId),\n ...ifDefined('typeContractSpaceId', typeContractSpaceId),\n ...ifDefined('typeConstructor', typeConstructor),\n optional,\n list,\n attributes,\n span: createTrimmedLineSpan(context, lineIndex),\n };\n}\n\nfunction isQuoteEscaped(value: string, quoteIndex: number): boolean {\n let backslashCount = 0;\n\n for (let index = quoteIndex - 1; index >= 0 && value[index] === '\\\\'; index -= 1) {\n backslashCount += 1;\n }\n\n return backslashCount % 2 === 1;\n}\n\nfunction splitTypeAndAttributes(value: string): {\n readonly typeSource: string;\n readonly attributeSource: string;\n readonly attributeOffset: number;\n} {\n let depthParen = 0;\n let depthBracket = 0;\n let depthBrace = 0;\n let quote: '\"' | \"'\" | null = null;\n\n for (let index = 0; index < value.length; index += 1) {\n const character = value[index] ?? '';\n if (quote) {\n if (character === quote && !isQuoteEscaped(value, index)) {\n quote = null;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n if (character === '(') {\n depthParen += 1;\n continue;\n }\n if (character === ')') {\n depthParen = Math.max(0, depthParen - 1);\n continue;\n }\n if (character === '[') {\n depthBracket += 1;\n continue;\n }\n if (character === ']') {\n depthBracket = Math.max(0, depthBracket - 1);\n continue;\n }\n if (character === '{') {\n depthBrace += 1;\n continue;\n }\n if (character === '}') {\n depthBrace = Math.max(0, depthBrace - 1);\n continue;\n }\n\n if (character === '@' && depthParen === 0 && depthBracket === 0 && depthBrace === 0) {\n return {\n typeSource: value.slice(0, index).trimEnd(),\n attributeSource: value.slice(index),\n attributeOffset: index,\n };\n }\n }\n\n return {\n typeSource: value.trimEnd(),\n attributeSource: '',\n attributeOffset: value.length,\n };\n}\n\nfunction parseAttributeToken(\n context: ParserContext,\n input: {\n readonly token: string;\n readonly target: PslAttributeTarget;\n readonly lineIndex: number;\n readonly span: PslSpan;\n },\n): PslAttribute | undefined {\n const expectsBlockPrefix = input.target === 'model' || input.target === 'enum';\n const targetLabel = input.target === 'enum' ? 'Enum' : 'Model';\n if (expectsBlockPrefix && !input.token.startsWith('@@')) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `${targetLabel} attribute \"${input.token}\" must use @@ prefix`,\n span: input.span,\n });\n return undefined;\n }\n if (!expectsBlockPrefix && !input.token.startsWith('@')) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Attribute \"${input.token}\" must use @ prefix`,\n span: input.span,\n });\n return undefined;\n }\n if (!expectsBlockPrefix && input.token.startsWith('@@')) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Attribute \"${input.token}\" is not valid in ${input.target} context`,\n span: input.span,\n });\n return undefined;\n }\n\n const rawBody = expectsBlockPrefix ? input.token.slice(2) : input.token.slice(1);\n const openParen = rawBody.indexOf('(');\n const closeParen = rawBody.lastIndexOf(')');\n const hasArgs = openParen >= 0 || closeParen >= 0;\n if ((openParen >= 0 && closeParen === -1) || (openParen === -1 && closeParen >= 0)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid attribute syntax \"${input.token}\"`,\n span: input.span,\n });\n return undefined;\n }\n\n const name = (openParen >= 0 ? rawBody.slice(0, openParen) : rawBody).trim();\n if (!/^[A-Za-z_][A-Za-z0-9_-]*(\\.[A-Za-z_][A-Za-z0-9_-]*)*$/.test(name)) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid attribute name \"${name || input.token}\"`,\n span: input.span,\n });\n return undefined;\n }\n\n let args: readonly PslAttributeArgument[] = [];\n if (hasArgs && openParen >= 0 && closeParen >= openParen) {\n if (closeParen !== rawBody.length - 1) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid trailing syntax in attribute \"${input.token}\"`,\n span: input.span,\n });\n return undefined;\n }\n const argsRaw = rawBody.slice(openParen + 1, closeParen);\n const parsedArgs = parseArgumentList(context, {\n argsRaw,\n argsOffset: input.span.start.column - 1 + (expectsBlockPrefix ? 2 : 1) + openParen + 1,\n lineIndex: input.lineIndex,\n token: input.token,\n span: input.span,\n invalidCode: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n invalidEmptyArgumentMessage: `Invalid empty argument in attribute \"${input.token}\"`,\n invalidNamedArgumentMessage: (part) => `Invalid named argument syntax \"${part}\"`,\n });\n if (!parsedArgs) {\n return undefined;\n }\n args = parsedArgs;\n }\n\n return {\n kind: 'attribute',\n target: input.target,\n name,\n args,\n span: input.span,\n };\n}\n\nfunction parseArgumentList(\n context: ParserContext,\n input: {\n readonly argsRaw: string;\n readonly argsOffset: number;\n readonly lineIndex: number;\n readonly token: string;\n readonly span: PslSpan;\n readonly invalidCode: PslDiagnosticCode;\n readonly invalidEmptyArgumentMessage: string;\n readonly invalidNamedArgumentMessage: (part: string) => string;\n },\n): readonly PslAttributeArgument[] | undefined {\n const trimmed = input.argsRaw.trim();\n if (trimmed.length === 0) {\n return [];\n }\n\n const parts = splitTopLevelSegments(input.argsRaw, ',');\n const args: PslAttributeArgument[] = [];\n\n for (const part of parts) {\n const original = part.value;\n const trimmedPart = original.trim();\n if (trimmedPart.length === 0) {\n pushDiagnostic(context, {\n code: input.invalidCode,\n message: input.invalidEmptyArgumentMessage,\n span: input.span,\n });\n return undefined;\n }\n\n const leadingWhitespace = original.length - original.trimStart().length;\n const partStart = input.argsOffset + part.start + leadingWhitespace;\n const partEnd = partStart + trimmedPart.length;\n const partSpan = createInlineSpan(context, input.lineIndex, partStart, partEnd);\n\n const namedSplit = splitTopLevelSegments(trimmedPart, ':');\n if (namedSplit.length > 1) {\n const first = namedSplit[0];\n if (!first) {\n pushDiagnostic(context, {\n code: input.invalidCode,\n message: input.invalidNamedArgumentMessage(trimmedPart),\n span: partSpan,\n });\n return undefined;\n }\n const name = first.value.trim();\n const rawValue = trimmedPart.slice(first.end + 1).trim();\n if (!name || rawValue.length === 0) {\n pushDiagnostic(context, {\n code: input.invalidCode,\n message: input.invalidNamedArgumentMessage(trimmedPart),\n span: partSpan,\n });\n return undefined;\n }\n args.push({\n kind: 'named',\n name,\n value: normalizeAttributeArgumentValue(rawValue),\n span: partSpan,\n });\n continue;\n }\n\n args.push({\n kind: 'positional',\n value: normalizeAttributeArgumentValue(trimmedPart),\n span: partSpan,\n });\n }\n\n return args;\n}\n\nfunction normalizeAttributeArgumentValue(value: string): string {\n return value.trim();\n}\n\nfunction findBlockBounds(context: ParserContext, startLine: number): BlockBounds {\n let depth = 0;\n\n for (let lineIndex = startLine; lineIndex < context.lines.length; lineIndex += 1) {\n const line = stripInlineComment(context.lines[lineIndex] ?? '');\n let quote: '\"' | \"'\" | null = null;\n for (let index = 0; index < line.length; index += 1) {\n const character = line[index] ?? '';\n if (quote) {\n if (character === quote && !isQuoteEscaped(line, index)) {\n quote = null;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '{') {\n depth += 1;\n }\n if (character === '}') {\n depth -= 1;\n if (depth === 0) {\n return { startLine, endLine: lineIndex, closed: true };\n }\n }\n }\n }\n\n pushDiagnostic(context, {\n code: 'PSL_UNTERMINATED_BLOCK',\n message: 'Unterminated block declaration',\n span: createTrimmedLineSpan(context, startLine),\n });\n return {\n startLine,\n endLine: context.lines.length - 1,\n closed: false,\n };\n}\n\ninterface TopLevelSegment {\n readonly value: string;\n readonly start: number;\n readonly end: number;\n}\n\nfunction splitTopLevelSegments(value: string, separator: ',' | ':'): TopLevelSegment[] {\n const parts: TopLevelSegment[] = [];\n let depthParen = 0;\n let depthBracket = 0;\n let depthBrace = 0;\n let quote: '\"' | \"'\" | null = null;\n let start = 0;\n\n for (let index = 0; index < value.length; index += 1) {\n const character = value[index] ?? '';\n if (quote) {\n if (character === quote && !isQuoteEscaped(value, index)) {\n quote = null;\n }\n continue;\n }\n\n if (character === '\"' || character === \"'\") {\n quote = character;\n continue;\n }\n\n if (character === '(') {\n depthParen += 1;\n continue;\n }\n if (character === ')') {\n depthParen = Math.max(0, depthParen - 1);\n continue;\n }\n if (character === '[') {\n depthBracket += 1;\n continue;\n }\n if (character === ']') {\n depthBracket = Math.max(0, depthBracket - 1);\n continue;\n }\n if (character === '{') {\n depthBrace += 1;\n continue;\n }\n if (character === '}') {\n depthBrace = Math.max(0, depthBrace - 1);\n continue;\n }\n\n if (character === separator && depthParen === 0 && depthBracket === 0 && depthBrace === 0) {\n parts.push({\n value: value.slice(start, index),\n start,\n end: index,\n });\n start = index + 1;\n }\n }\n\n parts.push({\n value: value.slice(start),\n start,\n end: value.length,\n });\n return parts;\n}\n\nfunction extractAttributeTokensWithSpans(\n context: ParserContext,\n lineIndex: number,\n value: string,\n startColumn: number,\n): { readonly ok: boolean; readonly tokens: readonly { text: string; span: PslSpan }[] } {\n const tokens: { text: string; span: PslSpan }[] = [];\n let index = 0;\n while (index < value.length) {\n while (index < value.length && /\\s/.test(value[index] ?? '')) {\n index += 1;\n }\n if (index >= value.length) {\n break;\n }\n\n if (value[index] !== '@') {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid attribute syntax \"${value.trim()}\"`,\n span: createInlineSpan(context, lineIndex, startColumn + index, startColumn + value.length),\n });\n return { ok: false, tokens };\n }\n\n const start = index;\n index += 1;\n if (value[index] === '@') {\n index += 1;\n }\n\n const nameStart = index;\n while (index < value.length && /[A-Za-z0-9_.-]/.test(value[index] ?? '')) {\n index += 1;\n }\n\n if (index === nameStart) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid attribute syntax \"${value.slice(start).trim()}\"`,\n span: createInlineSpan(context, lineIndex, startColumn + start, startColumn + value.length),\n });\n return { ok: false, tokens };\n }\n\n if (value[index] === '(') {\n let depth = 0;\n let quote: '\"' | \"'\" | null = null;\n while (index < value.length) {\n const char = value[index] ?? '';\n if (quote) {\n if (char === quote && !isQuoteEscaped(value, index)) {\n quote = null;\n }\n index += 1;\n continue;\n }\n\n if (char === '\"' || char === \"'\") {\n quote = char;\n index += 1;\n continue;\n }\n\n if (char === '(') {\n depth += 1;\n } else if (char === ')') {\n depth -= 1;\n if (depth === 0) {\n index += 1;\n break;\n }\n }\n index += 1;\n }\n if (depth !== 0) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Unterminated attribute argument list in \"${value.slice(start).trim()}\"`,\n span: createInlineSpan(\n context,\n lineIndex,\n startColumn + start,\n startColumn + value.length,\n ),\n });\n return { ok: false, tokens };\n }\n }\n\n const tokenText = value.slice(start, index).trim();\n tokens.push({\n text: tokenText,\n span: createInlineSpan(context, lineIndex, startColumn + start, startColumn + index),\n });\n\n while (index < value.length && /\\s/.test(value[index] ?? '')) {\n index += 1;\n }\n\n if (index < value.length && value[index] !== '@') {\n break;\n }\n }\n\n if (index < value.length && value[index] !== '@') {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_ATTRIBUTE_SYNTAX',\n message: `Invalid attribute syntax \"${value.trim()}\"`,\n span: createInlineSpan(context, lineIndex, startColumn + index, startColumn + value.length),\n });\n return { ok: false, tokens };\n }\n\n return { ok: true, tokens };\n}\n\nfunction stripInlineComment(line: string): string {\n let quote: '\"' | \"'\" | null = null;\n for (let index = 0; index < line.length - 1; index += 1) {\n const current = line[index] ?? '';\n const next = line[index + 1] ?? '';\n\n if (quote) {\n if (current === quote && !isQuoteEscaped(line, index)) {\n quote = null;\n }\n continue;\n }\n\n if (current === '\"' || current === \"'\") {\n quote = current;\n continue;\n }\n\n if (current === '/' && next === '/') {\n return line.slice(0, index);\n }\n }\n\n return line;\n}\n\nfunction computeLineOffsets(schema: string): number[] {\n const offsets = [0];\n for (let index = 0; index < schema.length; index += 1) {\n if (schema[index] === '\\n') {\n offsets.push(index + 1);\n }\n }\n return offsets;\n}\n\nfunction firstNonWhitespaceColumn(line: string): number {\n const first = line.search(/\\S/);\n return first === -1 ? 0 : first;\n}\n\nfunction createInlineSpan(\n context: ParserContext,\n lineIndex: number,\n startColumn: number,\n endColumn: number,\n): PslSpan {\n return {\n start: createPosition(context, lineIndex, startColumn),\n end: createPosition(context, lineIndex, endColumn),\n };\n}\n\nfunction createTrimmedLineSpan(context: ParserContext, lineIndex: number): PslSpan {\n const line = context.lines[lineIndex] ?? '';\n const startColumn = firstNonWhitespaceColumn(line);\n return {\n start: createPosition(context, lineIndex, startColumn),\n end: createPosition(context, lineIndex, line.length),\n };\n}\n\nfunction createLineRangeSpan(context: ParserContext, startLine: number, endLine: number): PslSpan {\n const startLineText = context.lines[startLine] ?? '';\n const endLineText = context.lines[endLine] ?? '';\n const startColumn = firstNonWhitespaceColumn(startLineText);\n return {\n start: createPosition(context, startLine, startColumn),\n end: createPosition(context, endLine, endLineText.length),\n };\n}\n\nfunction createPosition(\n context: ParserContext,\n lineIndex: number,\n columnIndex: number,\n): PslPosition {\n const clampedLineIndex = Math.max(0, Math.min(lineIndex, context.lineOffsets.length - 1));\n const lineText = context.lines[clampedLineIndex] ?? '';\n const clampedColumnIndex = Math.max(0, Math.min(columnIndex, lineText.length));\n return {\n offset: (context.lineOffsets[clampedLineIndex] ?? 0) + clampedColumnIndex,\n line: clampedLineIndex + 1,\n column: clampedColumnIndex + 1,\n };\n}\n\nfunction pushDiagnostic(\n context: ParserContext,\n diagnostic: Omit<PslDiagnostic, 'sourceId'> & { readonly code: PslDiagnosticCode },\n): void {\n context.diagnostics.push({\n ...diagnostic,\n sourceId: context.sourceId,\n });\n}\n\nfunction lookupExtensionBlockDescriptor(\n namespace: AuthoringPslBlockDescriptorNamespace,\n keyword: string,\n): AuthoringPslBlockDescriptor | undefined {\n if (!Object.hasOwn(namespace, keyword)) {\n return undefined;\n }\n const value = namespace[keyword];\n return isAuthoringPslBlockDescriptor(value) ? value : undefined;\n}\n\n/**\n * Reads an extension block body generically, driven by the descriptor's\n * `parameters` map. Each `key = <rhs>` line in the body is matched against\n * a declared parameter and the RHS is captured per the parameter's kind:\n *\n * - `ref` → the bareword identifier token (`PslExtensionBlockParamRef`)\n * - `value` → the raw RHS text verbatim (`PslExtensionBlockParamScalarValue`)\n * - `option` → the chosen bareword token (`PslExtensionBlockParamOption`)\n * - `list` → bracketed `[a, b, …]` list, each element captured per `of`\n * (`PslExtensionBlockParamList`)\n *\n * No validation runs here (unknown key, missing required, codec acceptance,\n * option-in-set, ref resolution). A body line that is not `key = value`\n * shaped emits a `PSL_INVALID_EXTENSION_BLOCK_MEMBER` parse diagnostic.\n */\nfunction parseExtensionBlock(\n context: ParserContext,\n descriptor: AuthoringPslBlockDescriptor,\n blockName: string,\n keywordLineIndex: number,\n bounds: BlockBounds,\n): PslExtensionBlock {\n const parameters: Record<string, PslExtensionBlockParamValue> = {};\n\n for (let lineIndex = bounds.startLine + 1; lineIndex < bounds.endLine; lineIndex += 1) {\n const raw = context.lines[lineIndex] ?? '';\n const line = stripInlineComment(raw).trim();\n if (line.length === 0) {\n continue;\n }\n\n const assignMatch = line.match(/^([A-Za-z_]\\w*)\\s*=\\s*(.+)$/);\n if (!assignMatch) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_EXTENSION_BLOCK_MEMBER',\n message: `Invalid extension block body line \"${line}\"; expected \"key = value\"`,\n span: createTrimmedLineSpan(context, lineIndex),\n });\n continue;\n }\n\n const key = assignMatch[1] ?? '';\n const rhsRaw = (assignMatch[2] ?? '').trim();\n const paramDescriptor = descriptor.parameters[key];\n\n if (paramDescriptor === undefined) {\n // Unknown parameter — captured as a raw value; the generic validator reports this.\n parameters[key] = {\n kind: 'value',\n raw: rhsRaw,\n span: createTrimmedLineSpan(context, lineIndex),\n };\n continue;\n }\n\n const captured = captureParamRhs(context, lineIndex, rhsRaw, paramDescriptor);\n if (captured !== undefined) {\n parameters[key] = captured;\n }\n }\n\n return {\n kind: descriptor.discriminator,\n name: blockName,\n parameters,\n span: createLineRangeSpan(context, keywordLineIndex, bounds.endLine),\n };\n}\n\n/**\n * Captures a single parameter RHS string according to the declared parameter\n * kind. Returns `undefined` and pushes a diagnostic only if the syntax is\n * genuinely malformed (e.g. a `list` with no opening bracket). Value\n * acceptance (codec, option-in-set, ref resolution) is handled by the validator.\n */\nfunction captureParamRhs(\n context: ParserContext,\n lineIndex: number,\n rhs: string,\n param: AuthoringPslBlockDescriptor['parameters'][string],\n): PslExtensionBlockParamValue | undefined {\n const span = createTrimmedLineSpan(context, lineIndex);\n\n switch (param.kind) {\n case 'ref': {\n return { kind: 'ref', identifier: rhs, span };\n }\n case 'value': {\n return { kind: 'value', raw: rhs, span };\n }\n case 'option': {\n return { kind: 'option', token: rhs, span };\n }\n case 'list': {\n if (!rhs.startsWith('[') || !rhs.endsWith(']')) {\n pushDiagnostic(context, {\n code: 'PSL_INVALID_EXTENSION_BLOCK_MEMBER',\n message: `Expected a bracketed list \"[…]\" for list parameter, got \"${rhs}\"`,\n span,\n });\n return undefined;\n }\n const inner = rhs.slice(1, -1).trim();\n const items: PslExtensionBlockParamValue[] = [];\n if (inner.length > 0) {\n const segments = splitTopLevelSegments(inner, ',');\n for (const segment of segments) {\n const itemRhs = segment.value.trim();\n if (itemRhs.length === 0) {\n continue;\n }\n const item = captureParamRhs(context, lineIndex, itemRhs, param.of);\n if (item !== undefined) {\n items.push(item);\n }\n }\n }\n return { kind: 'list', items, span };\n }\n }\n}\n"],"mappings":";;;;;AAwCA,MAAM,eAAe,IAAI,IAAI;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA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CAEtB;CAEA,OAAO;EACL,MAAM,WAAW;EACjB,MAAM;EACN;EACA,MAAM,oBAAoB,SAAS,kBAAkB,OAAO,OAAO;CACrE;AACF;;;;;;;AAQA,SAAS,gBACP,SACA,WACA,KACA,OACyC;CACzC,MAAM,OAAO,sBAAsB,SAAS,SAAS;CAErD,QAAQ,MAAM,MAAd;EACE,KAAK,OACH,OAAO;GAAE,MAAM;GAAO,YAAY;GAAK;EAAK;EAE9C,KAAK,SACH,OAAO;GAAE,MAAM;GAAS,KAAK;GAAK;EAAK;EAEzC,KAAK,UACH,OAAO;GAAE,MAAM;GAAU,OAAO;GAAK;EAAK;EAE5C,KAAK,QAAQ;GACX,IAAI,CAAC,IAAI,WAAW,GAAG,KAAK,CAAC,IAAI,SAAS,GAAG,GAAG;IAC9C,eAAe,SAAS;KACtB,MAAM;KACN,SAAS,4DAA4D,IAAI;KACzE;IACF,CAAC;IACD;GACF;GACA,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK;GACpC,MAAM,QAAuC,CAAC;GAC9C,IAAI,MAAM,SAAS,GAAG;IACpB,MAAM,WAAW,sBAAsB,OAAO,GAAG;IACjD,KAAK,MAAM,WAAW,UAAU;KAC9B,MAAM,UAAU,QAAQ,MAAM,KAAK;KACnC,IAAI,QAAQ,WAAW,GACrB;KAEF,MAAM,OAAO,gBAAgB,SAAS,WAAW,SAAS,MAAM,EAAE;KAClE,IAAI,SAAS,KAAA,GACX,MAAM,KAAK,IAAI;IAEnB;GACF;GACA,OAAO;IAAE,MAAM;IAAQ;IAAO;GAAK;EACrC;CACF;AACF"}
|
package/dist/tokenizer.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenizer.mjs","names":["#source","#buffer","#pos","#scanNext"],"sources":["../src/tokenizer.ts"],"sourcesContent":["export type TokenKind =\n | 'Ident'\n | 'StringLiteral'\n | 'NumberLiteral'\n | 'At'\n | 'DoubleAt'\n | 'LBrace'\n | 'RBrace'\n | 'LParen'\n | 'RParen'\n | 'LBracket'\n | 'RBracket'\n | 'Equals'\n | 'Question'\n | 'Dot'\n | 'Comma'\n | 'Colon'\n | 'Whitespace'\n | 'Newline'\n | 'Comment'\n | 'Invalid'\n | 'Eof';\n\nexport interface Token {\n readonly kind: TokenKind;\n readonly text: string;\n}\n\nexport class Tokenizer {\n readonly #source: string;\n #pos: number;\n readonly #buffer: Token[];\n\n constructor(source: string) {\n this.#source = source;\n this.#pos = 0;\n this.#buffer = [];\n }\n\n next(): Token {\n const next = this.#buffer.shift();\n if (next) {\n return next;\n }\n return this.#scanNext();\n }\n\n peek(offset = 0): Token {\n if (offset > this.#buffer.length) {\n const last = this.#buffer.at(-1);\n if (last?.kind === 'Eof') {\n return last;\n }\n }\n\n const token = this.#buffer[offset];\n if (token) {\n return token;\n }\n\n while (this.#buffer.length <= offset) {\n const token = this.#scanNext();\n if (token.kind === 'Eof') {\n return token;\n }\n this.#buffer.push(token);\n }\n\n return this.#buffer[offset] as Token;\n }\n\n #scanNext(): Token {\n const token = scan(this.#source, this.#pos);\n this.#pos += token.text.length;\n return token;\n }\n}\n\nfunction scan(source: string, pos: number): Token {\n if (pos >= source.length) {\n return { kind: 'Eof', text: '' };\n }\n\n return (\n scanNewline(source, pos) ??\n scanWhitespace(source, pos) ??\n scanComment(source, pos) ??\n scanAt(source, pos) ??\n scanIdent(source, pos) ??\n scanNumber(source, pos) ??\n scanString(source, pos) ??\n scanPunctuation(source, pos) ?? {\n kind: 'Invalid' as const,\n text: readChar(source, pos),\n }\n );\n}\n\nfunction scanNewline(source: string, pos: number): Token | undefined {\n const ch = source.charAt(pos);\n if (ch !== '\\r' && ch !== '\\n') return undefined;\n if (ch === '\\r' && source.charAt(pos + 1) === '\\n') {\n return { kind: 'Newline', text: '\\r\\n' };\n }\n return { kind: 'Newline', text: ch };\n}\n\nfunction scanWhitespace(source: string, pos: number): Token | undefined {\n const ch = source.charAt(pos);\n if (ch !== ' ' && ch !== '\\t') return undefined;\n let end = pos + 1;\n while (end < source.length) {\n const c = source.charAt(end);\n if (c !== ' ' && c !== '\\t') break;\n end++;\n }\n return { kind: 'Whitespace', text: source.slice(pos, end) };\n}\n\nfunction scanComment(source: string, pos: number): Token | undefined {\n if (source.charAt(pos) !== '/' || source.charAt(pos + 1) !== '/') return undefined;\n let end = pos + 2;\n while (end < source.length) {\n const c = source.charAt(end);\n if (c === '\\n' || c === '\\r') break;\n end++;\n }\n return { kind: 'Comment', text: source.slice(pos, end) };\n}\n\nfunction scanAt(source: string, pos: number): Token | undefined {\n if (source.charAt(pos) !== '@') return undefined;\n if (source.charAt(pos + 1) === '@') {\n return { kind: 'DoubleAt', text: '@@' };\n }\n return { kind: 'At', text: '@' };\n}\n\nfunction scanIdent(source: string, pos: number): Token | undefined {\n const ch = readChar(source, pos);\n if (!isIdentStart(ch)) return undefined;\n let end = pos + ch.length;\n while (end < source.length) {\n const c = readChar(source, end);\n if (isIdentPart(c)) {\n end += c.length;\n } else {\n break;\n }\n }\n return { kind: 'Ident', text: source.slice(pos, end) };\n}\n\nfunction scanNumber(source: string, pos: number): Token | undefined {\n let end = pos;\n if (source.charAt(end) === '-') {\n if (end + 1 >= source.length || !isDigit(source.charAt(end + 1))) return undefined;\n end++;\n } else if (!isDigit(source.charAt(end))) {\n return undefined;\n }\n end++;\n while (end < source.length && isDigit(source.charAt(end))) {\n end++;\n }\n if (source.charAt(end) === '.' && end + 1 < source.length && isDigit(source.charAt(end + 1))) {\n end++; // consume the dot\n while (end < source.length && isDigit(source.charAt(end))) {\n end++;\n }\n }\n return { kind: 'NumberLiteral', text: source.slice(pos, end) };\n}\n\nfunction scanString(source: string, pos: number): Token | undefined {\n if (source.charAt(pos) !== '\"') return undefined;\n let end = pos + 1;\n while (end < source.length) {\n const c = source.charAt(end);\n if (c === '\\\\' && end + 1 < source.length) {\n end += 2; // skip escape sequence\n continue;\n }\n if (c === '\"') {\n end++; // include closing quote\n return { kind: 'StringLiteral', text: source.slice(pos, end) };\n }\n if (c === '\\n' || c === '\\r') {\n // Unterminated: stop before newline\n return { kind: 'StringLiteral', text: source.slice(pos, end) };\n }\n end++;\n }\n // Unterminated at EOF\n return { kind: 'StringLiteral', text: source.slice(pos, end) };\n}\n\nfunction scanPunctuation(source: string, pos: number): Token | undefined {\n const kind = PUNCTUATION[source.charAt(pos)];\n if (kind === undefined) return undefined;\n return { kind, text: source.charAt(pos) };\n}\n\nfunction readChar(source: string, pos: number): string {\n const cp = source.codePointAt(pos);\n return cp !== undefined ? String.fromCodePoint(cp) : '';\n}\n\nfunction isIdentStart(ch: string): boolean {\n return /\\p{L}/u.test(ch) || ch === '_';\n}\n\nfunction isIdentPart(ch: string): boolean {\n return isIdentStart(ch) || isDigit(ch) || ch === '-';\n}\n\nfunction isDigit(ch: string): boolean {\n return ch >= '0' && ch <= '9';\n}\n\nconst PUNCTUATION: Record<string, TokenKind> = {\n '{': 'LBrace',\n '}': 'RBrace',\n '(': 'LParen',\n ')': 'RParen',\n '[': 'LBracket',\n ']': 'RBracket',\n '=': 'Equals',\n '?': 'Question',\n '.': 'Dot',\n ',': 'Comma',\n ':': 'Colon',\n};\n"],"mappings":";AA4BA,IAAa,YAAb,MAAuB;CACrB;CACA;CACA;CAEA,YAAY,QAAgB;EAC1B,KAAKA,UAAU;EACf,KAAKE,OAAO;EACZ,KAAKD,UAAU,CAAC;CAClB;CAEA,OAAc;EACZ,MAAM,OAAO,KAAKA,QAAQ,MAAM;EAChC,IAAI,MACF,OAAO;EAET,OAAO,KAAKE,UAAU;CACxB;CAEA,KAAK,SAAS,GAAU;EACtB,IAAI,SAAS,KAAKF,QAAQ,QAAQ;GAChC,MAAM,OAAO,KAAKA,QAAQ,GAAG,EAAE;GAC/B,IAAI,MAAM,SAAS,OACjB,OAAO;EAEX;EAEA,MAAM,QAAQ,KAAKA,QAAQ;EAC3B,IAAI,OACF,OAAO;EAGT,OAAO,KAAKA,QAAQ,UAAU,QAAQ;GACpC,MAAM,QAAQ,K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