From 20bc0c2243888900d2f04328e57ad2d7ca0a2403 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 20 Apr 2022 02:48:45 +0200 Subject: Basic AST for lang --- pkg/lang/ast/stmt.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 pkg/lang/ast/stmt.go (limited to 'pkg/lang/ast/stmt.go') diff --git a/pkg/lang/ast/stmt.go b/pkg/lang/ast/stmt.go new file mode 100644 index 0000000..e924f8c --- /dev/null +++ b/pkg/lang/ast/stmt.go @@ -0,0 +1,74 @@ +package ast + +import "jinx/pkg/lang/scanner/token" + +type StmtKind int + +const ( + StmtKindUse StmtKind = iota + StmtKindFnDecl + StmtKindObjectDecl + StmtKindVarDecl + StmtKindIf + StmtKindTry + StmtKindReturn + StmtKindContinue + StmtKindBreak + StmtKindThrow + StmtKindExpr +) + +type Stmt[T any] struct { + At token.Loc + Kind StmtKind + Value T +} + +type StmtUse struct { + Globals []IdentNode + Modules []IdentNode + Author IdentNode +} + +type StmtFnDecl struct { + Name IdentNode + Args []IdentNode + Body BlockNode +} + +type StmtObjectDecl struct{} + +type StmtVarDecl struct { + Name IdentNode + Value Expr[any] +} + +type StmtIf struct { + Cond Expr[any] + Then BlockNode + Elifs []CondNode + Else BlockNode +} + +type StmtTry struct { + Try BlockNode + CatchedName IdentNode + Catch BlockNode + Finally BlockNode +} + +type StmtReturn struct { + Value Expr[any] +} + +type StmtContinue struct{} + +type StmtBreak struct{} + +type StmtThrow struct { + Value Expr[any] +} + +type StmtExpr struct { + Value Expr[any] +} -- cgit 1.4.1