-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.ts
52 lines (48 loc) · 1.22 KB
/
ast.ts
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
export enum NodeTypes {
Program = 'Program',
NumberLiteral = 'NumberLiteral',
StringLiteral = 'StringLiteral',
CallExpression = 'CallExpression'
}
interface Node {
type: NodeTypes
}
export type ChildNode =
| NumberLiteralNode
| CallExpressionNode
| StringLiteralNode
export interface RootNode extends Node {
type: NodeTypes.Program
body: ChildNode[]
context?: ChildNode[]
}
export interface NumberLiteralNode extends Node {
type: NodeTypes.NumberLiteral
value: string
}
export interface StringLiteralNode extends Node {
type: NodeTypes.StringLiteral
value: string
}
export interface CallExpressionNode extends Node {
type: NodeTypes.CallExpression
name: string
params: ChildNode[]
context?: ChildNode[]
}
export function createRootNode(): RootNode {
return { type: NodeTypes.Program, body: [] }
}
export function createNumberLiteralNode(value: string): NumberLiteralNode {
return { type: NodeTypes.NumberLiteral, value }
}
export function createStringLiteralNode(value: string): StringLiteralNode {
return { type: NodeTypes.StringLiteral, value }
}
export function createCallExpressionNode(name: string): CallExpressionNode {
return {
type: NodeTypes.CallExpression,
name,
params: []
}
}