-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathStatement.ts
More file actions
113 lines (106 loc) · 3.74 KB
/
Statement.ts
File metadata and controls
113 lines (106 loc) · 3.74 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as ast from '@nomicfoundation/slang/ast';
import { NonterminalKind } from '@nomicfoundation/slang/cst';
import { SlangNode } from './SlangNode.js';
import { ExpressionStatement } from './ExpressionStatement.js';
import { VariableDeclarationStatement } from './VariableDeclarationStatement.js';
import { TupleDeconstructionStatement } from './TupleDeconstructionStatement.js';
import { IfStatement } from './IfStatement.js';
import { ForStatement } from './ForStatement.js';
import { WhileStatement } from './WhileStatement.js';
import { DoWhileStatement } from './DoWhileStatement.js';
import { ContinueStatement } from './ContinueStatement.js';
import { BreakStatement } from './BreakStatement.js';
import { ReturnStatement } from './ReturnStatement.js';
import { ThrowStatement } from './ThrowStatement.js';
import { EmitStatement } from './EmitStatement.js';
import { TryStatement } from './TryStatement.js';
import { RevertStatement } from './RevertStatement.js';
import { AssemblyStatement } from './AssemblyStatement.js';
import { Block } from './Block.js';
import { UncheckedBlock } from './UncheckedBlock.js';
import type { ParserOptions } from 'prettier';
import type { AstNode } from './types.d.ts';
function createNonterminalVariant(
variant: ast.Statement['variant'],
options: ParserOptions<AstNode>
): Statement['variant'] {
if (variant instanceof ast.ExpressionStatement) {
return new ExpressionStatement(variant, options);
}
if (variant instanceof ast.VariableDeclarationStatement) {
return new VariableDeclarationStatement(variant, options);
}
if (variant instanceof ast.TupleDeconstructionStatement) {
return new TupleDeconstructionStatement(variant, options);
}
if (variant instanceof ast.IfStatement) {
return new IfStatement(variant, options);
}
if (variant instanceof ast.ForStatement) {
return new ForStatement(variant, options);
}
if (variant instanceof ast.WhileStatement) {
return new WhileStatement(variant, options);
}
if (variant instanceof ast.DoWhileStatement) {
return new DoWhileStatement(variant, options);
}
if (variant instanceof ast.ContinueStatement) {
return new ContinueStatement(variant);
}
if (variant instanceof ast.BreakStatement) {
return new BreakStatement(variant);
}
if (variant instanceof ast.ReturnStatement) {
return new ReturnStatement(variant, options);
}
if (variant instanceof ast.ThrowStatement) {
return new ThrowStatement(variant);
}
if (variant instanceof ast.EmitStatement) {
return new EmitStatement(variant, options);
}
if (variant instanceof ast.TryStatement) {
return new TryStatement(variant, options);
}
if (variant instanceof ast.RevertStatement) {
return new RevertStatement(variant, options);
}
if (variant instanceof ast.AssemblyStatement) {
return new AssemblyStatement(variant, options);
}
if (variant instanceof ast.Block) {
return new Block(variant, options);
}
if (variant instanceof ast.UncheckedBlock) {
return new UncheckedBlock(variant, options);
}
const exhaustiveCheck: never = variant;
return exhaustiveCheck;
}
export class Statement extends SlangNode {
readonly kind = NonterminalKind.Statement;
variant:
| ExpressionStatement
| VariableDeclarationStatement
| TupleDeconstructionStatement
| IfStatement
| ForStatement
| WhileStatement
| DoWhileStatement
| ContinueStatement
| BreakStatement
| ReturnStatement
| ThrowStatement
| EmitStatement
| TryStatement
| RevertStatement
| AssemblyStatement
| Block
| UncheckedBlock;
constructor(ast: ast.Statement, options: ParserOptions<AstNode>) {
super(ast);
this.variant = createNonterminalVariant(ast.variant, options);
this.updateMetadata(this.variant);
}
}