about summary refs log tree commit diff
path: root/pkg/lang/ast/expr.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/ast/expr.go')
-rw-r--r--pkg/lang/ast/expr.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/pkg/lang/ast/expr.go b/pkg/lang/ast/expr.go
new file mode 100644
index 0000000..a4d6f56
--- /dev/null
+++ b/pkg/lang/ast/expr.go
@@ -0,0 +1,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{}