about summary refs log tree commit diff
path: root/pkg/lang/ast/expr.go
blob: a4d6f5626063e0c88724588217451de3aca2e21e (plain)
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
package ast

import "jinx/pkg/lang/scanner/token"

type ExprKind int

const (
	ExprKindBinary ExprKind = iota
	ExprKindUnary
	ExprKindCall
	ExprKindSubscription

	ExprKindGroup
	ExprKindFnLit
	ExprKindArrayLit
	ExprKindIdent
	ExprKindIntLit
	ExprKindFloatLit
	ExprKindStringLit
	ExprKindBoolLit
	ExprKindNullLit
	ExprKindThis
)

type Expr[T any] struct {
	At    token.Loc
	Kind  ExprKind
	Value T
}

type ExprBinary struct {
	Left  Expr[any]
	Op    BinOp
	Right Expr[any]
}

type ExprUnary struct {
	Op    UnOp
	Value Expr[any]
}

type ExprCall struct {
	Callee Expr[any]
	Args   []Expr[any]
}

type ExprSubscription struct {
	Obj Expr[any]
	Key Expr[any]
}

type ExprGroup struct {
	Value Expr[any]
}

type ExprFnLit struct {
	Args []IdentNode
	Body BlockNode
}

type ExprArrayLit struct {
	Values []Expr[any]
}

type ExprIdent struct {
	Value IdentNode
}

type ExprIntLit struct {
	Value uint64
}

type ExprFloatLit struct {
	Value float64
}

type ExprStringLit struct {
	Value string
}

type ExprBoolLit struct {
	Value bool
}

type ExprNullLit struct{}

type ExprThis struct{}