-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathYulExpression.ts
More file actions
50 lines (40 loc) · 1.62 KB
/
YulExpression.ts
File metadata and controls
50 lines (40 loc) · 1.62 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js';
import { YulFunctionCallExpression } from './YulFunctionCallExpression.js';
import { YulLiteral } from './YulLiteral.js';
import { YulPath } from './YulPath.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { AstNode } from './types.d.ts';
import type { PrintFunction, SlangNode } from '../types.d.ts';
export class YulExpression implements SlangNode {
readonly kind = NonterminalKind.YulExpression;
comments;
loc;
variant: YulFunctionCallExpression | YulLiteral | YulPath;
constructor(ast: ast.YulExpression, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast);
switch (ast.variant.cst.kind) {
case NonterminalKind.YulFunctionCallExpression:
this.variant = new YulFunctionCallExpression(
ast.variant as ast.YulFunctionCallExpression,
options
);
break;
case NonterminalKind.YulLiteral:
this.variant = new YulLiteral(ast.variant as ast.YulLiteral, options);
break;
case NonterminalKind.YulPath:
this.variant = new YulPath(ast.variant as ast.YulPath);
break;
default:
throw new Error(`Unexpected variant: ${ast.variant.cst.kind}`);
}
metadata = updateMetadata(metadata, [this.variant]);
this.comments = metadata.comments;
this.loc = metadata.loc;
}
print(path: AstPath<YulExpression>, print: PrintFunction): Doc {
return path.call(print, 'variant');
}
}