Skip to content

Commit 3059804

Browse files
committed
Remove gen-ast-types: the typed-CST generator had no load-bearing consumer
`gen-ast-types.ts` emitted `<grammar>.cst-types.ts` (discriminated-union typing of the CST). Those artifacts are gitignored build outputs, and nothing depended on them: the only consumer was a non-gated smoke test, and gen-cst-match's `importFrom` parameter (the cst-types path) was never used in its body — so the gated cst-match subsystem is fully independent of cst-types. Removed the generator and its smoke test, dropped the cst-types emit + the dead `importFrom` parameter from the gen pipeline, and cleaned the references (.gitignore/.gitattributes/CI comment/README diagram/emit-corpus filter). Verified: `npm run gen` emits no cst-types and the committed artifacts stay in sync; src type-checks; cst-match-totality 31356/0 and the full suite 42/42.
1 parent 7d47ca3 commit 3059804

9 files changed

Lines changed: 15 additions & 483 deletions

File tree

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Generated artifacts (npm run gen) — committed for consumers, CI-gated for
22
# staleness, collapsed in GitHub diffs. The grammar sources (*.ts at the repo
33
# root) are the hand-written truth; everything below is derived from them.
4-
# (*.cst-types.ts / *.cst-match.ts are generated too but NOT committed — see
5-
# .gitignore; they regenerate locally and in CI before typecheck/gates.)
4+
# (*.cst-match.ts is generated too but NOT committed — see .gitignore;
5+
# it regenerates locally and in CI before typecheck/gates.)
66
*.tmLanguage.json linguist-generated=true
77
*.language-configuration.json linguist-generated=true
88
*.monarch.json linguist-generated=true

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929

3030
- run: npm ci
3131

32-
# Regenerate every grammar's artifacts FIRST: the uncommitted ones
33-
# (*.cst-types.ts / *.cst-match.ts, gitignored) must exist before Typecheck
34-
# and the gates, which import them. Then fail if any COMMITTED artifact
32+
# Regenerate every grammar's artifacts FIRST: the uncommitted one
33+
# (*.cst-match.ts, gitignored) must exist before Typecheck
34+
# and the gates, which import it. Then fail if any COMMITTED artifact
3535
# drifts from the regenerated output (someone edited a grammar but forgot
3636
# to regenerate). Covers all grammars (sources at the repo root) + the
3737
# tree-sitter packages.

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ tree-sitter/*/src/node-types.json
1818
tree-sitter/*/src/tree_sitter/
1919
tree-sitter/*/*.wasm
2020

21-
# Generated CST consumer artifacts (npm run gen) — derived from the grammar, not
21+
# Generated CST consumer artifact (npm run gen) — derived from the grammar, not
2222
# committed: generate locally / in CI before typecheck and gates.
23-
*.cst-types.ts
2423
*.cst-match.ts

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ typescript.ts one grammar (TypeScript combinator API)
375375
├─ src/gen-tm.ts ───────────▶ typescript.tmLanguage.json (TextMate highlighter)
376376
├─ src/gen-vscode-config.ts ▶ typescript.language-configuration.json (editor behavior)
377377
├─ src/gen-treesitter.ts ───▶ tree-sitter/ (grammar.js + highlights.scm + scanner.c)
378-
├─ src/gen-monarch.ts ──────▶ typescript.monarch.json
379-
└─ src/gen-ast-types.ts ────▶ typescript.cst-types.ts
378+
└─ src/gen-monarch.ts ──────▶ typescript.monarch.json
380379
381380
shared src/grammar-utils.ts structural helpers used across stages
382381
src/api.ts, types.ts the grammar's combinator + type surface

src/cli.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { generateTmLanguage, generateMarkupInjection, generateAliasGrammar, gene
44
import { generateLanguageConfig } from './gen-vscode-config.ts';
55
import { generateTreeSitter } from './gen-treesitter.ts';
66
import { generateMonarch } from './gen-monarch.ts';
7-
import { generateAstTypes } from './gen-ast-types.ts';
87
import { generateCstMatch } from './gen-cst-match.ts';
98
import type { CstGrammar, RuleExpr } from './types.ts';
109
import { tokenPatternSource } from './token-pattern.ts';
@@ -115,11 +114,8 @@ emit(`tree-sitter/${langName}/package.json`,
115114
// Monaco Monarch tokenizer (markup-aware: emits a tag/text/raw-text state machine).
116115
emit(`${langName}.monarch.json`, JSON.stringify(generateMonarch(grammar), null, 2));
117116

118-
// CST node types (TypeScript) — generic over rules, fine for markup too.
119-
emit(`${langName}.cst-types.ts`, generateAstTypes(grammar));
120-
121-
// Per-arm CST destructurers (value-level sibling of the types above).
122-
emit(`${langName}.cst-match.ts`, generateCstMatch(grammar, `./${langName}.cst-types.ts`));
117+
// Per-arm CST destructurers.
118+
emit(`${langName}.cst-match.ts`, generateCstMatch(grammar));
123119

124120
function formatExpr(expr: RuleExpr): string {
125121
switch (expr.type) {

src/gen-ast-types.ts

Lines changed: 0 additions & 277 deletions
This file was deleted.

src/gen-cst-match.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Generate per-rule, per-ARM destructurers for a grammar's CST — the VALUE-level
2-
// sibling of gen-ast-types.ts. For every rule it emits
1+
// Generate per-rule, per-ARM destructurers for a grammar's CST. For every rule it emits
32
//
43
// export type <Rule>Match = { arm: 'if', expr: NodeEntry<'Expr'>, … } | …
54
// export function match<Rule>(t: TreeAccess, n: NodeEntry<'Rule'>, src: string): <Rule>Match
@@ -74,7 +73,7 @@ function sanitizeIdent(s: string): string {
7473

7574
const J = (v: unknown) => JSON.stringify(v);
7675

77-
export function generateCstMatch(grammar: CstGrammar, importFrom: string): string {
76+
export function generateCstMatch(grammar: CstGrammar): string {
7877
// Same [Await]/[Yield] fork the parsers apply, so the rule-id space (ruleIdOf)
7978
// agrees with the tree. Matchers/types are emitted for BASE rules only (a fork
8079
// collapses to its base via RULE_CANON); no-op without ctx markers.

0 commit comments

Comments
 (0)