diff options
| author | Mel <einebeere@gmail.com> | 2022-04-20 02:48:45 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-04-20 02:48:45 +0200 |
| commit | 20bc0c2243888900d2f04328e57ad2d7ca0a2403 (patch) | |
| tree | 6f0fc535fd8a74eb8f91c4a35fa3c32f012f0a59 /pkg/lang/ast/expr.go | |
| parent | db3dd28cdf9009880c1ab5f12c47b673dd00bc43 (diff) | |
| download | jinx-20bc0c2243888900d2f04328e57ad2d7ca0a2403.tar.zst jinx-20bc0c2243888900d2f04328e57ad2d7ca0a2403.zip | |
Basic AST for lang
Diffstat (limited to 'pkg/lang/ast/expr.go')
| -rw-r--r-- | pkg/lang/ast/expr.go | 87 |
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{} |
