@prisma-next/psl-parser 0.14.0-dev.5 → 0.14.0-dev.7

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 CHANGED
@@ -4,9 +4,9 @@ Reusable PSL parser for Prisma Next.
4
4
 
5
5
  ## Overview
6
6
 
7
- `@prisma-next/psl-parser` parses Prisma Schema Language (PSL) source into a deterministic AST with source spans and stable machine-readable diagnostics. It is intentionally parser-only: normalization to contract IR and emit integration happen in downstream milestones/packages.
7
+ `@prisma-next/psl-parser` parses Prisma Schema Language (PSL) source into a deterministic CST with source spans and stable machine-readable diagnostics, then offers shared symbol-table resolution for the target-agnostic semantics every PSL interpreter needs. Normalization to contract IR and emit integration stay in downstream target packages.
8
8
 
9
- In the provider-based authoring model, PSL providers call this parser and then return `Result<Contract, ContractSourceDiagnostics>` to the framework emit pipeline.
9
+ In the provider-based authoring model, PSL providers call `parse` to obtain the CST and then `buildSymbolTable` to obtain a scope-aware view, before returning `Result<Contract, ContractSourceDiagnostics>` to the framework emit pipeline.
10
10
 
11
11
  ## Responsibilities
12
12
 
@@ -15,8 +15,9 @@ In the provider-based authoring model, PSL providers call this parser and then r
15
15
  - Preserve raw PSL relation action tokens (for example `Cascade`) without semantic normalization.
16
16
  - Return stable diagnostics (`code`, `message`, `span`, `sourceId`) for invalid and unsupported constructs.
17
17
  - Enforce strict error behavior for unsupported syntax (no warning or best-effort mode).
18
- - Parse attributes generically (namespaced or not), including optional argument lists; semantics live downstream.
18
+ - Parse attributes generically (namespaced or not), including optional argument lists; target semantics live downstream.
19
19
  - Emit attribute nodes with explicit target (`field` / `model` / `namedType`), attribute name, and parsed argument list with spans.
20
+ - Build a scope-aware symbol table from the CST, including duplicate-declaration diagnostics, target-supplied scalar/type-alias classification, and descriptor-driven generic-block reconstruction.
20
21
 
21
22
  ## Attributes (generic parsing boundary)
22
23
 
@@ -37,11 +38,22 @@ Interpretation/validation (for example `@prisma-next/sql-contract-psl`) is respo
37
38
 
38
39
  ## Public API
39
40
 
40
- - `parsePslDocument(input)` in `src/parser.ts`
41
+ - `parse(schema)` in `src/parse.ts` (also at `@prisma-next/psl-parser/syntax`) — the CST parser: returns the `DocumentAst`, its backing `SourceFile`, and syntactic diagnostics. The recursive-descent / lossless-CST path supersedes the legacy `parsePslDocument`.
42
+ - `buildSymbolTable({ document, sourceFile, scalarTypes, pslBlockDescriptors })` in `src/symbol-table.ts` — a pure, fault-tolerant pass over a parsed CST `DocumentAst` that returns a scope-aware `SymbolTable` (top-level namespaces / scalars / type-aliases / blocks / models / composite-types as keyed records discriminated by `kind`, namespace members and block fields nested under their owner, every symbol carrying its CST AST `node` plus its declaration `span`) plus its own duplicate-name diagnostics (`PSL_DUPLICATE_DECLARATION`, first-wins, colliding across kinds within one scope). `scalarTypes` is supplied by the target to classify `types { ... }` bindings, while `pslBlockDescriptors` is supplied from authoring contributions so generic/extension blocks can be reconstructed once into `BlockSymbol.block`. The pass also **resolves** the field/named-type read set once: each `FieldSymbol` carries the split type (`typeName`/`typeNamespaceId`/`typeContractSpaceId`), `optional`/`list`, `typeConstructor?`, rendered `attributes`, and `malformedType?` (set, with a `PSL_INVALID_QUALIFIED_TYPE` diagnostic, when the type is over-qualified); `ScalarSymbol`/`TypeAliasSymbol` carry the resolved binding (`baseType`/`typeConstructor`/`isConstructor`). Interpreters consume this resolved shape directly — there is no per-package field/attribute view layer.
43
+ - `readResolvedAttribute(s)` / `readResolvedConstructorCall` + the span maps
44
+ (`nodePslSpan`, `rangeToPslSpan`, `keywordPslSpan`) in `src/resolve.ts` — the
45
+ shared CST read helpers `buildSymbolTable` uses and that consumers (e.g.
46
+ enum-block reconstruction) reuse, with `PslSpan` spans.
47
+ - `reconstructExtensionBlock` / `findBlockDescriptor` /
48
+ `validateExtensionBlockFromSymbol` in `src/extension-block.ts` — reconstruct a
49
+ descriptor-driven `PslExtensionBlock` from a CST `GenericBlockDeclarationAst`
50
+ (a `BlockSymbol`) and run the framework's standalone `validateExtensionBlock`
51
+ over it, building the ref-resolution context from the symbol table.
52
+ - `parseQuotedStringLiteral` / `getPositionalArgument` in `src/attribute-helpers.ts`.
41
53
  - AST/diagnostic/span types live in `@prisma-next/framework-components/psl-ast`
42
54
  and are re-exported from this package's root entry for convenience.
43
55
  - Subpath exports:
44
- - `@prisma-next/psl-parser/parser`
56
+ - `@prisma-next/psl-parser/syntax`
45
57
  - `@prisma-next/psl-parser/tokenizer`
46
58
 
47
59
  ## Dependencies
@@ -56,11 +68,17 @@ Interpretation/validation (for example `@prisma-next/sql-contract-psl`) is respo
56
68
 
57
69
  ```mermaid
58
70
  flowchart LR
59
- PSL[PSL source text] --> Parser[psl-parser]
60
- Parser --> AST[PSL AST with spans]
61
- Parser --> Diagnostics[Structured diagnostics]
62
- AST --> Normalizer[PSL -> contract IR normalizer]
63
- Diagnostics --> CLI[CLI/editor renderers]
71
+ PSL[PSL source text] --> Parse[parse]
72
+ Parse --> CST[DocumentAst + SourceFile]
73
+ Parse --> ParseDiagnostics[Parser diagnostics]
74
+ CST --> Symbols[buildSymbolTable]
75
+ Scalars[target scalarTypes] --> Symbols
76
+ Descriptors[pslBlockDescriptors] --> Symbols
77
+ Symbols --> SymbolTable[SymbolTable]
78
+ Symbols --> SymbolDiagnostics[Symbol-table diagnostics]
79
+ SymbolTable --> Interpreter[Target PSL interpreter]
80
+ ParseDiagnostics --> Provider[Provider diagnostic seeding]
81
+ SymbolDiagnostics --> Provider
64
82
  ```
65
83
 
66
84
  ## Package Boundaries