Skip to content

Commit 9f7532e

Browse files
committed
Drop the kind discriminator from the CST: shapes discriminate structurally
kind carried zero information — a leaf always has tokenType and a node always has rule + children, two disjoint field sets, so the tag was derivable from property presence. A leaf is now {tokenType, offset, end} and a node {rule, children, offset, end}; consumers discriminate with 'tokenType' in n / 'children' in n (TypeScript property-presence narrowing covers the union), and the generated *.cst-types.ts drop the field. The cst-text-invariant gate now pins the full shape on both sides: no kind, no text, leaf/node field sets exact, sane spans. In-engine reads (the no-unary-LHS head check, markup tag-name extraction, the html/coverage tree walkers, exec-trace) switch to structural checks; the emitted pratt path simplifies (head.tokenType === '$operator' alone — a node's tokenType is undefined and never matches). interp ≡ emit on the full 18,805-file corpus, reject messages identical, 27/27 gates. Serialized CSTs shrink by one field per object; bench: +3.4..+6.7% aggregate, 4/4 runs positive (one fewer slot per object and one fewer store per build).
1 parent ebeeff6 commit 9f7532e

17 files changed

Lines changed: 75 additions & 252 deletions

html.cst-types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ export type TokenType =
3030

3131
/** A terminal: one lexer token (or synthetic keyword/punct/operator leaf). */
3232
export interface CstLeaf extends CstPos {
33-
kind: 'leaf';
3433
tokenType: TokenType;
3534
}
3635

3736
/** `Element` node. Children (flattened, in source order) are drawn from: */
3837
export interface ElementNode extends CstPos {
39-
kind: 'node';
4038
rule: 'Element';
4139
children: Array<
4240
| (CstLeaf & { tokenType: '$punct' })
@@ -50,7 +48,6 @@ export interface ElementNode extends CstPos {
5048

5149
/** `Attr` node. Children (flattened, in source order) are drawn from: */
5250
export interface AttrNode extends CstPos {
53-
kind: 'node';
5451
rule: 'Attr';
5552
children: Array<
5653
| (CstLeaf & { tokenType: '$punct' })
@@ -62,7 +59,6 @@ export interface AttrNode extends CstPos {
6259

6360
/** `Node` node. Children (flattened, in source order) are drawn from: */
6461
export interface NodeNode extends CstPos {
65-
kind: 'node';
6662
rule: 'Node';
6763
children: Array<
6864
| (CstLeaf & { tokenType: 'Comment' })
@@ -74,7 +70,6 @@ export interface NodeNode extends CstPos {
7470

7571
/** `Document` node. Children (flattened, in source order) are drawn from: */
7672
export interface DocumentNode extends CstPos {
77-
kind: 'node';
7873
rule: 'Document';
7974
children: Array<
8075
| (CstLeaf & { tokenType: 'Comment' })

javascript.cst-types.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,17 @@ export type TokenType =
3939

4040
/** A terminal: one lexer token (or synthetic keyword/punct/operator leaf). */
4141
export interface CstLeaf extends CstPos {
42-
kind: 'leaf';
4342
tokenType: TokenType;
4443
}
4544

4645
/** Synthetic node the parser builds for an interpolated template literal. */
4746
export interface $templateNode extends CstPos {
48-
kind: 'node';
4947
rule: '$template';
5048
children: CstChild[];
5149
}
5250

5351
/** `DecoratorExpr` node. Children (flattened, in source order) are drawn from: */
5452
export interface DecoratorExprNode extends CstPos {
55-
kind: 'node';
5653
rule: 'DecoratorExpr';
5754
children: Array<
5855
| (CstLeaf & { tokenType: '$punct' })
@@ -63,7 +60,6 @@ export interface DecoratorExprNode extends CstPos {
6360

6461
/** `Expr` node. Children (flattened, in source order) are drawn from: */
6562
export interface ExprNode extends CstPos {
66-
kind: 'node';
6763
rule: 'Expr';
6864
children: Array<
6965
| $templateNode
@@ -94,7 +90,6 @@ export interface ExprNode extends CstPos {
9490

9591
/** `Prop` node. Children (flattened, in source order) are drawn from: */
9692
export interface PropNode extends CstPos {
97-
kind: 'node';
9893
rule: 'Prop';
9994
children: Array<
10095
| (CstLeaf & { tokenType: '$keyword' })
@@ -109,7 +104,6 @@ export interface PropNode extends CstPos {
109104

110105
/** `MemberName` node. Children (flattened, in source order) are drawn from: */
111106
export interface MemberNameNode extends CstPos {
112-
kind: 'node';
113107
rule: 'MemberName';
114108
children: Array<
115109
| (CstLeaf & { tokenType: '$punct' })
@@ -127,7 +121,6 @@ export interface MemberNameNode extends CstPos {
127121

128122
/** `NewTarget` node. Children (flattened, in source order) are drawn from: */
129123
export interface NewTargetNode extends CstPos {
130-
kind: 'node';
131124
rule: 'NewTarget';
132125
children: Array<
133126
| (CstLeaf & { tokenType: '$punct' })
@@ -139,7 +132,6 @@ export interface NewTargetNode extends CstPos {
139132

140133
/** `ClassHeritage` node. Children (flattened, in source order) are drawn from: */
141134
export interface ClassHeritageNode extends CstPos {
142-
kind: 'node';
143135
rule: 'ClassHeritage';
144136
children: Array<
145137
| (CstLeaf & { tokenType: '$punct' })
@@ -151,7 +143,6 @@ export interface ClassHeritageNode extends CstPos {
151143

152144
/** `Stmt` node. Children (flattened, in source order) are drawn from: */
153145
export interface StmtNode extends CstPos {
154-
kind: 'node';
155146
rule: 'Stmt';
156147
children: Array<
157148
| (CstLeaf & { tokenType: '$keyword' })
@@ -171,7 +162,6 @@ export interface StmtNode extends CstPos {
171162

172163
/** `Block` node. Children (flattened, in source order) are drawn from: */
173164
export interface BlockNode extends CstPos {
174-
kind: 'node';
175165
rule: 'Block';
176166
children: Array<
177167
| (CstLeaf & { tokenType: '$punct' })
@@ -181,7 +171,6 @@ export interface BlockNode extends CstPos {
181171

182172
/** `BindingProperty` node. Children (flattened, in source order) are drawn from: */
183173
export interface BindingPropertyNode extends CstPos {
184-
kind: 'node';
185174
rule: 'BindingProperty';
186175
children: Array<
187176
| (CstLeaf & { tokenType: '$punct' })
@@ -196,7 +185,6 @@ export interface BindingPropertyNode extends CstPos {
196185

197186
/** `BindingElement` node. Children (flattened, in source order) are drawn from: */
198187
export interface BindingElementNode extends CstPos {
199-
kind: 'node';
200188
rule: 'BindingElement';
201189
children: Array<
202190
| (CstLeaf & { tokenType: '$punct' })
@@ -208,7 +196,6 @@ export interface BindingElementNode extends CstPos {
208196

209197
/** `ArrayBindingElement` node. Children (flattened, in source order) are drawn from: */
210198
export interface ArrayBindingElementNode extends CstPos {
211-
kind: 'node';
212199
rule: 'ArrayBindingElement';
213200
children: Array<
214201
| (CstLeaf & { tokenType: '$punct' })
@@ -220,7 +207,6 @@ export interface ArrayBindingElementNode extends CstPos {
220207

221208
/** `BindingPattern` node. Children (flattened, in source order) are drawn from: */
222209
export interface BindingPatternNode extends CstPos {
223-
kind: 'node';
224210
rule: 'BindingPattern';
225211
children: Array<
226212
| (CstLeaf & { tokenType: '$punct' })
@@ -231,7 +217,6 @@ export interface BindingPatternNode extends CstPos {
231217

232218
/** `Binding` node. Children (flattened, in source order) are drawn from: */
233219
export interface BindingNode extends CstPos {
234-
kind: 'node';
235220
rule: 'Binding';
236221
children: Array<
237222
| (CstLeaf & { tokenType: '$punct' })
@@ -243,7 +228,6 @@ export interface BindingNode extends CstPos {
243228

244229
/** `ForBinding` node. Children (flattened, in source order) are drawn from: */
245230
export interface ForBindingNode extends CstPos {
246-
kind: 'node';
247231
rule: 'ForBinding';
248232
children: Array<
249233
| (CstLeaf & { tokenType: '$punct' })
@@ -255,7 +239,6 @@ export interface ForBindingNode extends CstPos {
255239

256240
/** `Param` node. Children (flattened, in source order) are drawn from: */
257241
export interface ParamNode extends CstPos {
258-
kind: 'node';
259242
rule: 'Param';
260243
children: Array<
261244
| (CstLeaf & { tokenType: '$punct' })
@@ -268,7 +251,6 @@ export interface ParamNode extends CstPos {
268251

269252
/** `ForHead` node. Children (flattened, in source order) are drawn from: */
270253
export interface ForHeadNode extends CstPos {
271-
kind: 'node';
272254
rule: 'ForHead';
273255
children: Array<
274256
| (CstLeaf & { tokenType: '$keyword' })
@@ -280,7 +262,6 @@ export interface ForHeadNode extends CstPos {
280262

281263
/** `SwitchCase` node. Children (flattened, in source order) are drawn from: */
282264
export interface SwitchCaseNode extends CstPos {
283-
kind: 'node';
284265
rule: 'SwitchCase';
285266
children: Array<
286267
| (CstLeaf & { tokenType: '$keyword' })
@@ -292,7 +273,6 @@ export interface SwitchCaseNode extends CstPos {
292273

293274
/** `Decl` node. Children (flattened, in source order) are drawn from: */
294275
export interface DeclNode extends CstPos {
295-
kind: 'node';
296276
rule: 'Decl';
297277
children: Array<
298278
| (CstLeaf & { tokenType: '$keyword' })
@@ -314,7 +294,6 @@ export interface DeclNode extends CstPos {
314294

315295
/** `ClassMember` node. Children (flattened, in source order) are drawn from: */
316296
export interface ClassMemberNode extends CstPos {
317-
kind: 'node';
318297
rule: 'ClassMember';
319298
children: Array<
320299
| (CstLeaf & { tokenType: '$keyword' })
@@ -329,7 +308,6 @@ export interface ClassMemberNode extends CstPos {
329308

330309
/** `ImportClause` node. Children (flattened, in source order) are drawn from: */
331310
export interface ImportClauseNode extends CstPos {
332-
kind: 'node';
333311
rule: 'ImportClause';
334312
children: Array<
335313
| (CstLeaf & { tokenType: '$keyword' })
@@ -341,7 +319,6 @@ export interface ImportClauseNode extends CstPos {
341319

342320
/** `ImportSpecifier` node. Children (flattened, in source order) are drawn from: */
343321
export interface ImportSpecifierNode extends CstPos {
344-
kind: 'node';
345322
rule: 'ImportSpecifier';
346323
children: Array<
347324
| (CstLeaf & { tokenType: '$keyword' })
@@ -351,7 +328,6 @@ export interface ImportSpecifierNode extends CstPos {
351328

352329
/** `Program` node. Children (flattened, in source order) are drawn from: */
353330
export interface ProgramNode extends CstPos {
354-
kind: 'node';
355331
rule: 'Program';
356332
children: Array<
357333
| DeclNode

0 commit comments

Comments
 (0)