-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathYulSwitchCase.ts
More file actions
36 lines (29 loc) · 1.13 KB
/
YulSwitchCase.ts
File metadata and controls
36 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as ast from '@nomicfoundation/slang/ast';
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { SlangNode } from './SlangNode.js';
import { YulDefaultCase } from './YulDefaultCase.js';
import { YulValueCase } from './YulValueCase.js';
import type { ParserOptions } from 'prettier';
import type { AstNode } from './types.d.ts';
function createNonterminalVariant(
variant: ast.YulSwitchCase['variant'],
options: ParserOptions<AstNode>
): YulSwitchCase['variant'] {
if (variant instanceof ast.YulDefaultCase) {
return new YulDefaultCase(variant, options);
}
if (variant instanceof ast.YulValueCase) {
return new YulValueCase(variant, options);
}
const exhaustiveCheck: never = variant;
throw new Error(`Unexpected variant: ${JSON.stringify(exhaustiveCheck)}`);
}
export class YulSwitchCase extends SlangNode {
readonly kind = NonterminalKind.YulSwitchCase;
variant: YulDefaultCase | YulValueCase;
constructor(ast: ast.YulSwitchCase, options: ParserOptions<AstNode>) {
super(ast);
this.variant = createNonterminalVariant(ast.variant, options);
this.updateMetadata(this.variant);
}
}