Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

TML-2893: add qualified-name, single-quote, and enum-block support to the CST parser - #849

Merged
SevInf merged 2 commits into
mainfrom
psl-cst-parser
Jun 17, 2026
Merged

SevInf merged 2 commits into
mainfrom
psl-cst-parser

Conversation

@SevInf

@SevInf SevInf commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2893 — the PSL-parser replacement effort. The fault-tolerant CST parser itself already landed in #795; this PR fills in the parser functionality that was still missing, extending the existing CST parser with qualified names, single-quoted strings, and enum-block parsing.

At a glance

The CST parser already parsed bare names; this PR teaches it the qualified forms every downstream consumer needs — parsed as one QualifiedName node:

model Profile {
  id    Int
  // cross-space + namespace-qualified type reference — now a single QualifiedName
  user  supabase:auth.User @relation(fields: [userId], references: [id])
  // namespace-qualified constructor type
  embedding pgvector.Vector(1536)
}

Before this PR these qualified positions were handled by ad-hoc bounded-lookahead patches; now parseQualifiedName produces a uniform QualifiedNameAst ([space ':']? Ident ('.' Ident)*) wherever a qualified name can appear — type references, constructor callees, function-call callees, and @@-attribute names.

Decision

This PR extends the existing fault-tolerant CST parser with the functionality it was missing, leaving the legacy parsePslDocument untouched:

  1. A unified QualifiedName CST node + parseQualifiedName. One parser and one AST node (QualifiedNameAst) for every qualified position, replacing the previous per-site lookahead handling. Emits PSL_INVALID_QUALIFIED_NAME for malformed over-qualified names.
  2. Single-quoted string literals. The tokenizer now scans '…' as well as "…", and isTerminatedStringLiteral handles both quote styles.
  3. Enum routed through generic blocks. The dedicated parseEnum path and its EnumDeclarationAst / EnumValueDeclarationAst nodes are gone; an enum block now parses as a GenericBlockDeclarationAst (which also gained @@-attribute support inside generic-block members).
  4. Quoted object-literal keys. Object fields accept string-literal keys ({ "key": value }), not just identifiers.

The CST parser core (parse, SourceFile, the red/green tree) is not introduced here — it predates this branch. This PR is purely parser-functionality: the legacy parsePslDocument and its consumers (the SQL/Mongo interpreters) are untouched.

How it fits together

  1. QualifiedName becomes a first-class node — syntax/ast/qualified-name.ts adds QualifiedNameAst with space / namespace / identifier / path / isOverQualified accessors; syntax-kind.ts adds the QualifiedName kind; exports/syntax.ts exposes it.
  2. The parser emits it everywhere a qualified name can appear — parse.ts adds parseQualifiedName / parseQualifiedSegments and rewires type-annotation, function-call, and @@-attribute parsing through it, retiring the bounded-lookahead patch.
  3. AST accessors return the new node — FieldAttributeAst.name(), ModelAttributeAst.name(), and TypeAnnotationAst.name() now return QualifiedNameAst; FunctionCallAst gains name() / path(); ObjectFieldAst gains string-literal key support.
  4. Enum folds into generic blocks — parseEnum and the enum AST classes are removed; GenericBlockDeclarationAst gains attributes() so enum (and other extension blocks) parse generically.
  5. One additive diagnostic code — PSL_INVALID_QUALIFIED_NAME is added to framework-components's PslDiagnosticCode (alongside, not replacing, the existing PSL_INVALID_QUALIFIED_TYPE the legacy parser uses).

What lands in this PR

Area What it adds / changes
syntax/ast/qualified-name.ts (new) QualifiedNameAst — the unified qualified-name node
parse.ts parseQualifiedName + rewiring of type/attribute/call parsing; removal of parseEnum; string-literal object keys
tokenizer.ts single-quoted string scanning
syntax/ast/{attributes,expressions,type-annotation,declarations,identifier}.ts accessors return QualifiedNameAst; GenericBlockDeclarationAst.attributes(); enum AST classes removed
syntax/syntax-kind.ts, exports/syntax.ts QualifiedName kind; export of QualifiedNameAst / printSyntax
framework-components/.../psl-extension-block.ts additive PSL_INVALID_QUALIFIED_NAME code
test/parse-*.test.ts, syntax/ast.test.ts snapshots + assertions for the new shapes
legacy parser.ts / parsePslDocument untouched — still the interpreters' parser

Reviewer notes

  • The parser pre-exists; this PR is additive functionality. The diff is against a base that already contains the CST parser (feat(psl-parser): fault-tolerant recursive-descent parser (parse + SourceFile) under ./syntax #795), so parse.ts / tokenizer.ts / syntax/ show as modified, not added. The only new file is qualified-name.ts.
  • Nothing downstream is migrated. parsePslDocument and its consumers (SQL/Mongo interpreters) are untouched; this PR only changes the parser surface.
  • Enum support changed shape, not capability. enum no longer has a dedicated AST node; it parses as a GenericBlockDeclarationAst. Tests assert the generic-block shape.
  • One additive diagnostic code only. PSL_INVALID_QUALIFIED_NAME is added (alongside the existing PSL_INVALID_QUALIFIED_TYPE); no other diagnostic codes change.
  • Pre-existing, out of scope: a bare-as lint info at tokenizer.ts:69 (info-level on the ratchet, not introduced here).

Compatibility / migration / risk

Additive to the parser surface: the new QualifiedNameAst and the qualified-name handling are new; parsePslDocument and the ./parser entry are unchanged, so no interpreter is migrated and contract output is identical to base. The one behavioral shape change is internal to the CST (enum → generic block), exercised by the parser tests; no contract consumer observes it on this branch.

Verification

  • pnpm --filter @prisma-next/psl-parser build — green.
  • pnpm --filter @prisma-next/psl-parser test — CST parse-* / syntax/ast suites + the retained legacy parser suites.
  • pnpm --filter @prisma-next/sql-contract-psl typecheck, @prisma-next/mongo-contract-psl typecheck — green, unchanged (still on the legacy parser).
  • pnpm build (full), pnpm typecheck (full workspace), pnpm lint:deps — green.

Alternatives considered

  • Keep the per-site bounded-lookahead handling for qualified names. Rejected: every qualified position (type ref, constructor callee, call callee, @@-attribute) re-implemented its own lookahead. A single QualifiedName node + parseQualifiedName collapses them to one uniform shape.
  • Keep a dedicated enum AST node. Rejected: enum is being reframed as an extension/generic block elsewhere in the effort; routing it through GenericBlockDeclarationAst removes a parallel code path rather than maintaining two.

Checklist

  • Commits are signed off (DCO).
  • Read CONTRIBUTING.md.
  • Tests updated / added.
  • Title follows the $TICKET_ID: <title> convention.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR introduces QualifiedNameAst as a unified CST node for dotted/colon-qualified names, wires a new parseQualifiedName parser into attribute, type annotation, and function-call parsing, removes enum declaration support (parseEnum, EnumDeclarationAst, EnumValueDeclarationAst), extends the tokenizer to handle single-quoted strings, and updates all downstream AST classes and tests accordingly.

Changes

QualifiedName AST, Enum Removal, and String Literal Improvements

Layer / File(s) Summary
SyntaxKind, diagnostic code, and public API contracts
packages/1-framework/2-authoring/psl-parser/src/syntax/syntax-kind.ts, packages/1-framework/1-core/framework-components/src/shared/psl-extension-block.ts, packages/1-framework/2-authoring/psl-parser/src/exports/syntax.ts
Adds QualifiedName to SyntaxKind, removes EnumDeclaration/EnumValueDeclaration, adds PSL_INVALID_QUALIFIED_NAME to PslDiagnosticCode, and updates the barrel to add QualifiedNameAst/printSyntax while dropping enum AST exports.
QualifiedNameAst class, IdentifierAst.name(), and printSyntax
packages/1-framework/2-authoring/psl-parser/src/syntax/ast/qualified-name.ts, packages/1-framework/2-authoring/psl-parser/src/syntax/ast/identifier.ts, packages/1-framework/2-authoring/psl-parser/src/syntax/ast-helpers.ts
Implements QualifiedNameAst with space/namespace/identifier/path/isOverQualified accessors, private segment helpers, and static cast(); adds IdentifierAst.name() and exported printSyntax.
Single-quoted string tokenizer support
packages/1-framework/2-authoring/psl-parser/src/tokenizer.ts
Updates scanString to derive the opening quote and match the closing quote for both ' and " styles; generalizes isTerminatedStringLiteral to both quote styles.
parseQualifiedName and parser refactor
packages/1-framework/2-authoring/psl-parser/src/parse.ts
Adds parseQualifiedName/parseQualifiedSegments emitting PSL_INVALID_QUALIFIED_NAME; refactors parseFunctionCall with isCallAhead lookahead; rewires attribute, type annotation, and call parsing to use parseQualifiedName; removes parseEnum/parseEnumMember/parseEnumValue; allows bare keys and @@ attributes in generic-block members; accepts string-literal object-field keys; updates key-value parsing to emit diagnostic only when = lacks a value.
AST classes updated to return QualifiedNameAst
packages/1-framework/2-authoring/psl-parser/src/syntax/ast/attributes.ts, packages/1-framework/2-authoring/psl-parser/src/syntax/ast/expressions.ts, packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts, packages/1-framework/2-authoring/psl-parser/src/syntax/ast/declarations.ts
Changes FieldAttributeAst.name(), ModelAttributeAst.name(), and TypeAnnotationAst.name() to return QualifiedNameAst; adds FunctionCallAst.path() and ObjectFieldAst.keyName(); adds single-quote escape to decodeStringLiteral; adds TypeAnnotationAst.argList()/isConstructor(); removes enum AST classes; adds GenericBlockDeclarationAst.attributes().
Test suite updates
packages/1-framework/2-authoring/psl-parser/test/parse-leaf.test.ts, packages/1-framework/2-authoring/psl-parser/test/parse-document.test.ts, packages/1-framework/2-authoring/psl-parser/test/parse-diagnostics.test.ts, packages/1-framework/2-authoring/psl-parser/test/syntax/ast.test.ts, packages/1-framework/2-authoring/psl-parser/test/support.ts
Updates all inline snapshots and AST assertions for QualifiedName subtrees, PSL_INVALID_QUALIFIED_NAME diagnostics, enum-as-GenericBlockDeclarationAst, accepted string-literal keys, single-quoted string parsing, qualified call paths, and new parseQualifiedName coverage; adds frameworkScalarTypes to test support.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • prisma/prisma-next#753: Both PRs touch the shared extension-block diagnostic vocabulary by modifying PslDiagnosticCode union.
  • prisma/prisma-next#776: Updates the same syntax barrel (src/exports/syntax.ts) and extends shared AST helpers that PR #776 introduced.
  • prisma/prisma-next#795: Both PRs directly touch qualified-name/type-annotation parsing and diagnostic emission in the PSL parser.
  • prisma/prisma-next#805: Relies on the generic extension-block parsing changes introduced here for its enum2 transitional implementation.

Suggested reviewers

  • wmadden

🐇 A dotted name, a colon too,
Now one bright node holds every clue.
No enum ghosts, no segments split—
QualifiedNameAst is a perfect fit!
Single quotes now scan with ease,
And bare keys bloom just as they please. 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main changes: qualified-name support, single-quote string support, and enum-block parsing changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch psl-cst-parser

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@849

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@849

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@849

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@849

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@849

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@849

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@849

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@849

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@849

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@849

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@849

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@849

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@849

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@849

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@849

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@849

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@849

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@849

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@849

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@849

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@849

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@849

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@849

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@849

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@849

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@849

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@849

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@849

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@849

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@849

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@849

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@849

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@849

prisma-next

npm i https://pkg.pr.new/prisma-next@849

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@849

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@849

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@849

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@849

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@849

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@849

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@849

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@849

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@849

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@849

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@849

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@849

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@849

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@849

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@849

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@849

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@849

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@849

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@849

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@849

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@849

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@849

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@849

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@849

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@849

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@849

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@849

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@849

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@849

commit: a3bf90e

@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 154.55 KB (0%)
postgres / emit 142.13 KB (0%)
mongo / no-emit 78 KB (0%)
mongo / emit 72.09 KB (0%)
cf-worker / no-emit 181.82 KB (0%)
cf-worker / emit 167.78 KB (0%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/1-framework/2-authoring/psl-parser/src/syntax/ast/declarations.ts`:
- Around line 11-15: The JSDoc comment for the NamespaceMemberAst type
declaration mentions enums as valid namespace members, but enums have been
removed from the type definition. Update the comment to remove the reference to
enums and keep only the items that are actually included in NamespaceMemberAst
(models, composite types, and extension block declarations), ensuring the
documentation accurately reflects what the type currently allows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: a1d2a9a1-e8e0-4ed8-ad37-cc618db11413

📥 Commits

Reviewing files that changed from the base of the PR and between c793885 and c3c48b8.

📒 Files selected for processing (17)
  • packages/1-framework/1-core/framework-components/src/shared/psl-extension-block.ts
  • packages/1-framework/2-authoring/psl-parser/src/exports/syntax.ts
  • packages/1-framework/2-authoring/psl-parser/src/parse.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast-helpers.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/attributes.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/declarations.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/expressions.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/identifier.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/qualified-name.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/type-annotation.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/syntax-kind.ts
  • packages/1-framework/2-authoring/psl-parser/src/tokenizer.ts
  • packages/1-framework/2-authoring/psl-parser/test/parse-diagnostics.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/parse-document.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/parse-leaf.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/support.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/ast.test.ts

@SevInf SevInf changed the title TML-2893: land fault-tolerant CST parser alongside the legacy parser TML-2893: ensure feature parity between CST and legacy parser Jun 17, 2026
SevInf added 2 commits June 17, 2026 19:24
…) alongside legacy parser

Signed-off-by: Serhii Tatarintsev <[email protected]>
…FunctionCallAst.qualifiedName→name

Signed-off-by: Serhii Tatarintsev <[email protected]>
@SevInf SevInf changed the title TML-2893: ensure feature parity between CST and legacy parser TML-2893: add qualified-name, single-quote, and enum-block support to the CST parser Jun 17, 2026
@SevInf
SevInf enabled auto-merge June 17, 2026 19:28
@SevInf
SevInf disabled auto-merge June 17, 2026 19:56
@SevInf
SevInf merged commit 46d58b1 into main Jun 17, 2026
28 of 29 checks passed
@SevInf
SevInf deleted the psl-cst-parser branch June 17, 2026 19:56
wmadden-electric added a commit that referenced this pull request Jun 18, 2026
Main shipped the 0.14.0 publish bump (#843) and several follow-ups
(TML-2916 #838, TML-2503 #839, TML-2787 #683, TML-2893 #849, ci-fix
#847) while slice 1 was in review. Merge to pick them up.

Resolution:
- `skills/extension-author/.../0.13-to-0.14/instructions.md` — union of
  the slice's TML-2919 entry and main's TML-2916 entry as two distinct
  HTML-comment blocks, matching the file's per-ticket convention.
  Per the skill spec's rebase scenario (lines 122-130): existing entries
  in the just-shipped 0.13-to-0.14 directory may stay in place; we do
  not relocate the TML-2919 entry to 0.14-to-0.15.
- Lockfile + example fixtures + apps + all other non-slice files —
  take main's side cleanly (the branch hadn't touched them; auto-merge
  resolved to main's content). `pnpm install` confirms the lockfile is
  consistent.
- No `src/` conflicts — only the one instructions.md conflict above.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
SevInf added a commit that referenced this pull request Jun 19, 2026
#850)

## What

Delivers the **PSL formatter** for Prisma Next, end to end: a
deterministic pretty-printer engine plus the `prisma format` CLI command
that runs it.

**1. Engine** — `@prisma-next/psl-parser/format`:

```ts
import { format, type FormatOptions, PslFormatError } from '@prisma-next/psl-parser/format';

format(source);                                  // canonical PSL, LF, 2-space indent
format(source, { indent: 'tab', newline: 'CRLF' });
```

`format(source, options?) -> string` parses via the CST and re-emits
canonical PSL. Pure string→string: no file I/O, no node built-ins, no
`@prisma-next/config` dependency.

**2. CLI** — `prisma format`:

Reads `prisma-next.config.ts`; when the contract source is PSL
(`config.contract.source.sourceFormat === 'psl'`), formats
`config.contract.source.inputs[0]` **in place**. Non-PSL or absent
sources are left untouched. Indent/newline come from an optional
`formatter` config section; the system newline (`os.EOL`) is resolved at
the CLI.

Closes TML-2928 (the whole issue — both the engine and the CLI).

## Why

Prisma Next authors hand-write and machine-emit PSL, but there was no
canonical formatter for the new authoring stack. The new red/green CST
preserves all trivia (whitespace, comments, newlines) as tokens, making
it the right substrate for a lossless pretty-printer: re-emit a
normalized, deterministic layout while retaining comments and the full
token stream.

## Engine behaviour

- **CST-based** (`parse` + typed AST wrappers); does not touch the
legacy `parsePslDocument`.
- **`indent`**: positive integer (spaces) or `'tab'`; default 2.
- **`newline`**: `'LF'` (default) or `'CRLF'`, applied uniformly.
- **Per-block alignment**: field-name→type column and trailing
attributes aligned per block.
- **Trivia preservation**: leading / trailing / dangling comments and
author blank lines (collapsed to one, never adjacent to a brace).
- **Blank line before block attributes**: one blank line always
separates the last field from the first `@@` attribute (house style).
- **Idempotence**: `format(format(x)) === format(x)`.
- **Refuses** input that carries parse diagnostics (`PslFormatError`)
rather than emitting best-effort output.

## Key decisions

- **Engine ships inside `@prisma-next/psl-parser`** via a `./format`
subpath — no separate package, no new runtime dependency. Engine option
validation is hand-rolled (the option space is two enum-ish fields; a
schema lib would have violated the package's no-new-deps constraint).
The `formatter` **config** section, by contrast, is arktype-validated —
`@prisma-next/config` already depends on arktype.
- **`os.EOL` resolution lives only in the CLI.** The engine never reads
`os`; the `prisma format` command resolves `config.formatter.newline ??
(os.EOL === '\r\n' ? 'CRLF' : 'LF')` and passes an explicit `newline`
into the engine.
- **PSL-ness is a structured discriminator, not a filename heuristic.**
`ContractSourceProvider` carries an optional `sourceFormat: 'psl' |
'typescript'`; every first-party provider declares it
(`prismaContract`/`mongoContract` → `'psl'`; the `typescript*`/`empty`
helpers → `'typescript'`). The command formats only `'psl'` sources;
anything else (incl. absent) is left untouched.
- **Inline `//` comments are a hard break barrier.** `field Type
//comment` followed by a continuation `@attribute` preserves the break
rather than hoisting the attribute past the comment — matching Prettier,
Biome, and rustfmt (a `//` comment runs to end-of-line; joining a later
token onto its line is both a correctness and an idempotence hazard).

## Tests — side-by-side fixture pairs

The formatter's integration oracle is a set of hand-authored
**side-by-side pairs** under
`test/format/fixtures/<case>/{input,expected}.prisma` — open a pair to
*see* exactly what the formatter does. The test asserts `format(input)
=== expected`, idempotence, and that formatting actually happened. Cases
cover alignment, comment preservation, the inline-comment hard break,
blank-line handling, block-attribute spacing, enum/generic blocks, and
the namespaced-type round-trip (`space:ns.Type`). The CLI is covered by
an e2e journey (`format.e2e.test.ts`) proving format-in-place,
leave-untouched, and refuse-on-unparseable, each asserting on-disk file
state.

## Validation

- `pnpm lint:deps` — no violations (engine takes no node built-ins; the
CLI→engine edge is layering-safe).
- `@prisma-next/psl-parser` — 529 tests, no type errors; fixture pairs
produce no snapshot churn.
- `@prisma-next/config` — 29 tests (discriminator + `formatter`
section).
- `@prisma-next/cli` — `prisma format` operation tests + the e2e journey
green. (Note: ~9 pre-existing flakes in `version.test.ts` /
`removed-verb-redirects.test.ts` are cold-boot subprocess-timeout
fragility, unrelated to this work.)

## Base

Targets `main`. The formatter consumes the fault-tolerant CST parser
surface, which landed on `main` via #795 and #849; this branch was
originally stacked on the pre-merge `psl-cst-parser` branch and has been
rebased onto `main` now that the CST work is merged.



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added PSL formatter to canonically format Prisma schema language code.
* Added `format` CLI command with `--config` option to format PSL files
in place.
* Added formatter configuration options for indentation and line ending
styles (tabs vs. spaces, LF vs. CRLF).
* Format command only processes PSL sources; TypeScript contracts are
skipped.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Serhii Tatarintsev <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
SevInf added a commit that referenced this pull request Jun 19, 2026
## Linked issue

Refs [TML-2929](https://linear.app/prisma-company/issue/TML-2929)

Branches off [#849](#849)
(TML-2893, the CST parser `parse` + qualified-name/enum-block support),
which is merged to `main`.

## At a glance

PSL providers now build a resolved, scope-aware symbol table from the
CST parser and hand that to the SQL and Mongo interpreters instead of
the legacy line-based parser's pre-resolved AST:

```ts
const { document, sourceFile, diagnostics } = parse(schema);
const { table: symbolTable, diagnostics: symbolDiagnostics } = buildSymbolTable({
  document,
  sourceFile,
  scalarTypes: [...scalarTypeDescriptors.keys()],
  pslBlockDescriptors: authoringContributions.pslBlockDescriptors,
});
// symbolTable.topLevel: namespaces / scalars / typeAliases / blocks / models / compositeTypes,
// each a keyed record discriminated by `kind`; every symbol carries `.node` (its CST AST node).
// Fields and named type bindings carry resolved type/attribute shape; blocks carry their resolved PslExtensionBlock.
// Parse diagnostics and symbol-table diagnostics are surfaced together by the providers, not merged at the source.
```

Before this PR, both interpreters consumed `parsePslDocument`'s
pre-resolved `PslDocumentAst`. That parser — and its ~3.5k lines — is
now gone; the CST `parse` is the only parser in the package, and
`buildSymbolTable` owns the resolution layer the old parser used to
provide.

## Decision

This PR carries four substantive pieces:

1. **A new resolution layer, `buildSymbolTable`,** co-located with the
CST `parse` in `@prisma-next/psl-parser`. It turns the CST `DocumentAst`
into the keyed, scope-aware symbol table the interpreters need, rebuilt
on the CST. It is fault-tolerant, keeps parser diagnostics separate from
symbol-table diagnostics, and is the sole owner of
`PSL_DUPLICATE_DECLARATION` for same-name collisions (first-wins,
collide-regardless-of-kind).
2. **Resolution moved into the symbol table.** Field/named-type
resolution and extension-block reconstruction now happen once in
`@prisma-next/psl-parser`: fields carry split qualified type references,
optional/list/constructor state, rendered attributes, and malformed-type
markers; scalar/type-alias bindings carry their resolved shape; block
symbols carry descriptor-classified `PslExtensionBlock` values built
with the required `pslBlockDescriptors` input.
3. **Both interpreters migrated** (SQL then Mongo) to consume the symbol
table directly, reaching diagnostic feature parity with the legacy path.
The per-package CST field/view adapters and SQL enum-block
reconstruction were removed after their responsibilities moved to
`buildSymbolTable`.
4. **`parsePslDocument` deleted** — the function, its ~1.6k-line
implementation, its `./parser` export, and its ~1.8k lines of legacy
tests. The legacy `PslDocumentAst` types stay because the introspection
printer still consumes them; only the legacy parser is removed.

## How it fits together

1. **Build the symbol table** —
[`psl-parser/src/symbol-table.ts`](packages/1-framework/2-authoring/psl-parser/src/symbol-table.ts)
walks the CST `DocumentAst`, buckets declarations into keyed records
discriminated by `kind`, nests namespace members and block fields under
their owner, classifies `types {}` bindings as scalar-vs-alias against
the target's `scalarTypes`, and emits duplicate-declaration diagnostics.
Every symbol references its originating CST node.

2. **Resolve field and named-type shape once** —
[`psl-parser/src/resolve.ts`](packages/1-framework/2-authoring/psl-parser/src/resolve.ts)
centralizes the qualified-name split, optional/list/constructor
handling, attribute rendering, and malformed-type cascade guard that the
SQL and Mongo packages used to duplicate in package-local view layers.

3. **Resolve extension blocks once** —
[`psl-parser/src/block-reconstruction.ts`](packages/1-framework/2-authoring/psl-parser/src/block-reconstruction.ts)
reconstructs descriptor-classified `PslExtensionBlock` values for
`BlockSymbol.block`;
[`psl-parser/src/extension-block.ts`](packages/1-framework/2-authoring/psl-parser/src/extension-block.ts)
keeps descriptor lookup and validation helpers. SQL now reads
`BlockSymbol.block` directly, so its old `enum-block.ts` reconstruction
is gone.

4. **Walk the table in each interpreter** — [SQL
`interpreter.ts`](packages/2-sql/2-authoring/contract-psl/src/interpreter.ts)
and [Mongo
`interpreter.ts`](packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts)
consume the symbol table instead of `document.ast.namespaces`,
preserving every diagnostic code while removing the defensive
duplicate-model throw and the interpreter-local diagnostic dedupe
helpers that existed only because duplicate ownership was not yet clean.

5. **Wire the providers** — [SQL
`provider.ts`](packages/2-sql/2-authoring/contract-psl/src/provider.ts)
and [Mongo
`provider.ts`](packages/2-mongo-family/2-authoring/contract-psl/src/provider.ts)
call `parse` + `buildSymbolTable`, pass target scalar descriptors and
block descriptors, seed both diagnostic lists into the interpreter, and
emit the combined diagnostic set in one run (no fail-before-interpret
short-circuit).

6. **Delete the legacy parser** — with no consumer left,
`parsePslDocument` and its tests are removed; the printer's round-trip
tests are reworked to build their legacy AST inputs without it.

## Reviewer notes

- **Largest diff is still subtractive.** The headline deletion removes
[`parser.ts`](packages/1-framework/2-authoring/psl-parser/src/parser.ts)
(−1642),
[`parser.test.ts`](packages/1-framework/2-authoring/psl-parser/test/parser.test.ts)
(−1507), and
[`parser-enum.test.ts`](packages/1-framework/2-authoring/psl-parser/test/parser-enum.test.ts)
(−329). The PR is net negative overall. Spot-check the export prune in
[`psl-parser/src/exports/index.ts`](packages/1-framework/2-authoring/psl-parser/src/exports/index.ts):
only `parsePslDocument` / `ParsePslDocumentInput` /
`ParsePslDocumentResult` and the dead parser subpath were removed;
still-used `Psl*` types remain exported.
- **The symbol table now owns resolution, not just bucketing.** Earlier
slices temporarily let interpreters rebuild field views and enum blocks
from raw CST nodes. Follow-up slices deliberately moved those
responsibilities into `buildSymbolTable`, matching the old parser's
single-resolver shape and deleting the downstream duplication.
- **Two diagnostic lists, surfaced together.** `parse` diagnostics and
`buildSymbolTable` diagnostics remain separate at the source
(deliberate), then providers seed both into the interpreter so callers
see one combined result. There is no longer SQL/Mongo interpreter-local
diagnostic dedupe; probe-backed validation showed it was collapsing
nothing real after `buildSymbolTable` became the sole
duplicate-declaration owner.
- **`policy_select` is preserved, not dropped.** Descriptor-typed
extension blocks reconstruct from the CST via the symbol table and are
validated with the framework's standalone `validateExtensionBlock`. The
`declarative-policy-select.round-trip.test.ts` rework drives the real
`parse → buildSymbolTable → validate → factory → print` pipeline over
malformed text; its diagnostic assertions are real, not laundered.
- **A few diagnostic spans/wording shifted; codes did not.** Where the
CST gives a more precise anchor (for example duplicate enum members or
over-qualified types), spans moved, but every diagnostic code a consumer
or test keys on is preserved.
- **One accepted behavior change:** an over-qualified field type
(`a.b.c`) now surfaces both `PSL_INVALID_QUALIFIED_NAME` (from the CST
parser, native) and `PSL_INVALID_QUALIFIED_TYPE` (from symbol-table
field resolution); legacy emitted only the latter. Both are accurate;
collapsing to one remains a noted follow-up.

## Compatibility / migration / risk

- No `contract.json` / IR shape change; this is a
parser-and-interpreter-internal migration. The legacy `PslDocumentAst`
types remain exported for the introspection printer.
- The `@prisma-next/psl-parser` `./parser` subpath export is removed. No
code consumed it; downstream code should import `parse` and
`buildSymbolTable` instead, and pass both target scalar types and
`pslBlockDescriptors` when constructing a symbol table.
- `buildSymbolTable` is now the single place to look for
duplicate-declaration ownership, field/named-type resolution, and block
reconstruction. That reduces parity risk between SQL and Mongo, but it
also makes symbol-table tests the primary coverage surface for
resolution behavior.

## Testing performed

Latest validation on final pushed HEAD:

- `pnpm --filter @prisma-next/psl-parser test` — clean: 12 files / 368
tests.
- `pnpm --filter @prisma-next/sql-contract-psl test` — clean: 17 files /
251 tests.
- `pnpm --filter @prisma-next/mongo-contract-psl test` — clean: 4 files
/ 137 tests.
- `pnpm build` — clean: 66/66 tasks.
- `pnpm typecheck` — clean: 138/138 tasks.
- `pnpm lint:deps` — clean.
- `pnpm test:packages` — attempted on final HEAD, but not green in this
local environment: Mongo memory-server cannot resolve a `mongod` binary
on NixOS (`Unknown/unsupported linux "nixos" id_like's: []`) and several
CLI tests hit their 500ms timeout. This matches the already-recorded
environmental class; CI with the proper Mongo/CLI environment should be
used as the full package-suite authority.
- Required cleanup checks on final HEAD: `rg "throw new
Error\(.*duplicate model" packages/2-sql/2-authoring/contract-psl/src`
empty; `rg "function dedupeDiagnostics" packages` empty.

## Follow-ups

- Collapse the doubled qualified-name codes
(`PSL_INVALID_QUALIFIED_NAME` + `PSL_INVALID_QUALIFIED_TYPE`) on
over-qualified types to a single code — decide which layer owns the
rejection (touches the shared CST parser).
- Revisit whether `BlockSymbol.block: PslExtensionBlock` is the right
long-term carried shape, or whether the symbol table should expose a
leaner resolved block representation. This PR restores single ownership
of block reconstruction; it does not settle the long-term shape
question.

## Alternatives considered

- **Pointing the interpreters straight at the raw CST** (no symbol
table) — would scatter name-resolution, bucketing, duplicate detection,
field resolution, and block reconstruction across both interpreters
independently, a parity risk. The symbol table centralizes it in one
resolution layer.
- **Keeping package-local CST read/view adapters** — initially useful to
derisk the SQL canary, but it duplicated the legacy parser's resolved
read-set in both interpreter packages. Follow-up slices moved that
resolution into `buildSymbolTable` and deleted the adapters.
- **Keeping SQL enum-block reconstruction downstream** — rejected after
`BlockSymbol.block` became descriptor-classified at symbol-table
construction. SQL now consumes the same resolved block shape as every
other consumer.
- **Merging the two diagnostic lists at the source** inside
`buildSymbolTable` — rejected; keeping parser diagnostics and
symbol-table diagnostics separate lets callers attribute whether a
problem came from parsing or resolution while still surfacing both at
the provider boundary.
- **Retiring the `policy_select` round-trip test** when it appeared to
depend on the deleted parser — rejected; the capability was rebuildable
on the CST, so we wired it rather than lose coverage.

## Checklist

- [x] Commits are signed off (DCO).
- [x] Read CONTRIBUTING.md.
- [x] Tests updated / added for the change.
- [x] PR title follows the `TML-NNNN: …` convention.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added scope-aware `PSL_DUPLICATE_DECLARATION` diagnostics with
first-wins behavior and reporting on the later declaration span.
* Updated PSL authoring and contract generation flow to use a
provider-driven `parse(...)` + `buildSymbolTable(...)` pipeline.
* **Bug Fixes**
* Reduced diagnostic cascades by halting downstream processing for
malformed type information.
* **Documentation**
* Refreshed PSL parser public API docs and removed legacy
`parsePslDocument` entry points/subpath exports.
* **Tests**
* Expanded/adjusted PSL symbol-table and SQL/Mongo interpreter test
coverage to match the new pipeline.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Serhii Tatarintsev <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant