@prisma-next/psl-parser 0.13.0 → 0.14.0-dev.10
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/README.md +28 -10
- package/dist/declarations-D9h_ihD3.mjs +820 -0
- package/dist/declarations-D9h_ihD3.mjs.map +1 -0
- package/dist/format.d.mts +19 -0
- package/dist/format.d.mts.map +1 -0
- package/dist/format.mjs +470 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.d.mts +136 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +472 -2
- package/dist/index.mjs.map +1 -1
- package/dist/parse-BjZ1LPe6.d.mts +349 -0
- package/dist/parse-BjZ1LPe6.d.mts.map +1 -0
- package/dist/parse-DhEV6av6.mjs +605 -0
- package/dist/parse-DhEV6av6.mjs.map +1 -0
- package/dist/syntax.d.mts +3 -272
- package/dist/syntax.d.mts.map +1 -1
- package/dist/syntax.mjs +3 -708
- package/dist/tokenizer-1hAHZzmp.mjs +228 -0
- package/dist/tokenizer-1hAHZzmp.mjs.map +1 -0
- package/dist/tokenizer.mjs +1 -190
- package/package.json +6 -6
- package/src/block-reconstruction.ts +139 -0
- package/src/exports/format.ts +3 -0
- package/src/exports/index.ts +40 -5
- package/src/exports/syntax.ts +9 -4
- package/src/extension-block.ts +107 -0
- package/src/format/emit.ts +603 -0
- package/src/format/error.ts +13 -0
- package/src/format/format.ts +13 -0
- package/src/format/options.ts +28 -0
- package/src/parse.ts +751 -0
- package/src/resolve.ts +120 -0
- package/src/source-file.ts +89 -0
- package/src/symbol-table.ts +446 -0
- package/src/syntax/ast/attributes.ts +5 -24
- package/src/syntax/ast/declarations.ts +14 -67
- package/src/syntax/ast/expressions.ts +187 -19
- package/src/syntax/ast/identifier.ts +4 -0
- package/src/syntax/ast/qualified-name.ts +87 -0
- package/src/syntax/ast/type-annotation.ts +11 -41
- package/src/syntax/ast-helpers.ts +12 -0
- package/src/syntax/syntax-kind.ts +8 -4
- package/src/tokenizer.ts +47 -7
- package/dist/parser-Cw_zV0M5.mjs +0 -1176
- package/dist/parser-Cw_zV0M5.mjs.map +0 -1
- package/dist/parser-Dfi3Wfdq.d.mts +0 -7
- package/dist/parser-Dfi3Wfdq.d.mts.map +0 -1
- package/dist/parser.d.mts +0 -2
- package/dist/parser.mjs +0 -2
- package/dist/syntax.mjs.map +0 -1
- package/dist/tokenizer.mjs.map +0 -1
- package/src/exports/parser.ts +0 -1
- package/src/parser.ts +0 -1713
package/src/exports/syntax.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export type { ParseDiagnostic, ParseResult } from '../parse';
|
|
2
|
+
export { parse } from '../parse';
|
|
3
|
+
export type { Position, Range } from '../source-file';
|
|
4
|
+
export { SourceFile } from '../source-file';
|
|
1
5
|
export {
|
|
2
6
|
AttributeArgListAst,
|
|
3
7
|
FieldAttributeAst,
|
|
@@ -5,12 +9,10 @@ export {
|
|
|
5
9
|
} from '../syntax/ast/attributes';
|
|
6
10
|
export type { NamespaceMemberAst } from '../syntax/ast/declarations';
|
|
7
11
|
export {
|
|
8
|
-
BlockDeclarationAst,
|
|
9
12
|
CompositeTypeDeclarationAst,
|
|
10
13
|
DocumentAst,
|
|
11
|
-
EnumDeclarationAst,
|
|
12
|
-
EnumValueDeclarationAst,
|
|
13
14
|
FieldDeclarationAst,
|
|
15
|
+
GenericBlockDeclarationAst,
|
|
14
16
|
KeyValuePairAst,
|
|
15
17
|
ModelDeclarationAst,
|
|
16
18
|
NamedTypeDeclarationAst,
|
|
@@ -25,13 +27,16 @@ export {
|
|
|
25
27
|
castExpression,
|
|
26
28
|
FunctionCallAst,
|
|
27
29
|
NumberLiteralExprAst,
|
|
30
|
+
ObjectFieldAst,
|
|
31
|
+
ObjectLiteralExprAst,
|
|
28
32
|
StringLiteralExprAst,
|
|
29
33
|
} from '../syntax/ast/expressions';
|
|
30
34
|
// AST wrappers
|
|
31
35
|
export { IdentifierAst } from '../syntax/ast/identifier';
|
|
36
|
+
export { QualifiedNameAst } from '../syntax/ast/qualified-name';
|
|
32
37
|
export { TypeAnnotationAst } from '../syntax/ast/type-annotation';
|
|
33
38
|
export type { AstNode } from '../syntax/ast-helpers';
|
|
34
|
-
export { filterChildren, findChildToken, findFirstChild } from '../syntax/ast-helpers';
|
|
39
|
+
export { filterChildren, findChildToken, findFirstChild, printSyntax } from '../syntax/ast-helpers';
|
|
35
40
|
export type { GreenElement, GreenNode, GreenToken } from '../syntax/green';
|
|
36
41
|
export { greenNode, greenToken } from '../syntax/green';
|
|
37
42
|
export { GreenNodeBuilder } from '../syntax/green-builder';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AuthoringPslBlockDescriptor,
|
|
3
|
+
type AuthoringPslBlockDescriptorNamespace,
|
|
4
|
+
isAuthoringPslBlockDescriptor,
|
|
5
|
+
} from '@prisma-next/framework-components/authoring';
|
|
6
|
+
import type { CodecLookup } from '@prisma-next/framework-components/codec';
|
|
7
|
+
import {
|
|
8
|
+
makePslNamespace,
|
|
9
|
+
makePslNamespaceEntries,
|
|
10
|
+
type PslDiagnostic,
|
|
11
|
+
type PslModel,
|
|
12
|
+
type PslSpan,
|
|
13
|
+
UNSPECIFIED_PSL_NAMESPACE_ID,
|
|
14
|
+
validateExtensionBlock,
|
|
15
|
+
} from '@prisma-next/framework-components/psl-ast';
|
|
16
|
+
import type { SourceFile } from './source-file';
|
|
17
|
+
import type { BlockSymbol, ModelSymbol, SymbolTable } from './symbol-table';
|
|
18
|
+
|
|
19
|
+
export function findBlockDescriptor(
|
|
20
|
+
descriptors: AuthoringPslBlockDescriptorNamespace | undefined,
|
|
21
|
+
keyword: string,
|
|
22
|
+
): AuthoringPslBlockDescriptor | undefined {
|
|
23
|
+
if (descriptors === undefined) return undefined;
|
|
24
|
+
for (const value of Object.values(descriptors)) {
|
|
25
|
+
if (value === undefined) continue;
|
|
26
|
+
if (isAuthoringPslBlockDescriptor(value)) {
|
|
27
|
+
if (value.keyword === keyword) return value;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const nested = findBlockDescriptor(value, keyword);
|
|
31
|
+
if (nested !== undefined) return nested;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function validateExtensionBlockFromSymbol(input: {
|
|
37
|
+
readonly block: BlockSymbol;
|
|
38
|
+
readonly descriptor: AuthoringPslBlockDescriptor;
|
|
39
|
+
readonly symbolTable: SymbolTable;
|
|
40
|
+
readonly sourceFile: SourceFile;
|
|
41
|
+
readonly sourceId: string;
|
|
42
|
+
readonly codecLookup: CodecLookup;
|
|
43
|
+
}): readonly PslDiagnostic[] {
|
|
44
|
+
const refCtx = buildRefResolutionContext(input.symbolTable, input.block);
|
|
45
|
+
return validateExtensionBlock(
|
|
46
|
+
input.block.block,
|
|
47
|
+
input.descriptor,
|
|
48
|
+
input.sourceId,
|
|
49
|
+
input.codecLookup,
|
|
50
|
+
refCtx,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const ZERO_SPAN: PslSpan = {
|
|
55
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
56
|
+
end: { offset: 0, line: 1, column: 1 },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function buildRefResolutionContext(
|
|
60
|
+
symbolTable: SymbolTable,
|
|
61
|
+
block: BlockSymbol,
|
|
62
|
+
): {
|
|
63
|
+
ownerNamespace: ReturnType<typeof makePslNamespace>;
|
|
64
|
+
allNamespaces: readonly ReturnType<typeof makePslNamespace>[];
|
|
65
|
+
} {
|
|
66
|
+
const unspecifiedNamespace = makeNamespace(
|
|
67
|
+
UNSPECIFIED_PSL_NAMESPACE_ID,
|
|
68
|
+
Object.values(symbolTable.topLevel.models),
|
|
69
|
+
);
|
|
70
|
+
const namedNamespaces = Object.values(symbolTable.topLevel.namespaces).map((namespace) =>
|
|
71
|
+
makeNamespace(namespace.name, Object.values(namespace.models)),
|
|
72
|
+
);
|
|
73
|
+
const allNamespaces = [unspecifiedNamespace, ...namedNamespaces];
|
|
74
|
+
const ownerNamespaceName = findOwnerNamespaceName(symbolTable, block);
|
|
75
|
+
const ownerNamespace =
|
|
76
|
+
allNamespaces.find((namespace) => namespace.name === ownerNamespaceName) ??
|
|
77
|
+
unspecifiedNamespace;
|
|
78
|
+
return { ownerNamespace, allNamespaces };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function makeNamespace(
|
|
82
|
+
name: string,
|
|
83
|
+
models: readonly ModelSymbol[],
|
|
84
|
+
): ReturnType<typeof makePslNamespace> {
|
|
85
|
+
const modelStubs: PslModel[] = models.map((model) => ({
|
|
86
|
+
kind: 'model',
|
|
87
|
+
name: model.name,
|
|
88
|
+
fields: [],
|
|
89
|
+
attributes: [],
|
|
90
|
+
span: ZERO_SPAN,
|
|
91
|
+
}));
|
|
92
|
+
return makePslNamespace({
|
|
93
|
+
kind: 'namespace',
|
|
94
|
+
name,
|
|
95
|
+
entries: makePslNamespaceEntries(modelStubs, [], []),
|
|
96
|
+
span: ZERO_SPAN,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function findOwnerNamespaceName(symbolTable: SymbolTable, block: BlockSymbol): string {
|
|
101
|
+
for (const namespace of Object.values(symbolTable.topLevel.namespaces)) {
|
|
102
|
+
if (Object.values(namespace.blocks).some((candidate) => candidate === block)) {
|
|
103
|
+
return namespace.name;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return UNSPECIFIED_PSL_NAMESPACE_ID;
|
|
107
|
+
}
|