gotlin/internal/lang/ast.go

313 lines
4.2 KiB
Go

package lang
type Program struct {
PackagePath string
Imports []ImportDecl
Interfaces []InterfaceDecl
Enums []EnumDecl
Classes []ClassDecl
Workers []WorkerDecl
Functions []FunctionDecl
Embeds []EmbedDecl
}
type EmbedDecl struct{ Path, Name, Type string }
type EnumDecl struct {
Name string
Variants []EnumVariant
String bool
}
type EnumVariant struct {
Name string
PayloadTypes []string
StringValue string
}
type ImportDecl struct {
Alias string
Path string
}
type InterfaceDecl struct {
Name string
Methods []FunctionSignature
}
type ClassDecl struct {
Name string
Data bool
JSONNaming string
Table string
Fields []FieldDecl
Parents []string
Methods []FunctionDecl
}
type WorkerDecl struct {
Name string
Fields []WorkerFieldDecl
Methods []FunctionDecl
}
type WorkerFieldDecl struct {
Mutable bool
Name string
Type string
Value Expr
}
type FieldDecl struct {
Mutable bool
Private bool
Name string
Type string
Column string
ID bool
Generated bool
}
type FunctionSignature struct {
Name string
Params []Param
ReturnType string
}
type FunctionDecl struct {
Name string
Params []Param
ReturnType string
Body []Stmt
}
type Param struct {
Name string
Type string
}
type Stmt interface {
stmtNode()
}
type Expr interface {
exprNode()
}
type VarDecl struct {
Mutable bool
Name string
Type string
Value Expr
}
func (VarDecl) stmtNode() {}
type MultiVarDecl struct {
Mutable bool
Names []string
Value Expr
}
func (MultiVarDecl) stmtNode() {}
type AssignStmt struct {
Name string
Pos int
Value Expr
}
func (AssignStmt) stmtNode() {}
type AddAssignStmt struct {
Name string
Pos int
Value Expr
}
func (AddAssignStmt) stmtNode() {}
type MultiAssignStmt struct {
Names []string
Positions []int
Value Expr
}
func (MultiAssignStmt) stmtNode() {}
type ReturnStmt struct {
Value Expr
}
func (ReturnStmt) stmtNode() {}
type ThrowStmt struct {
Value Expr
}
func (ThrowStmt) stmtNode() {}
type GoStmt struct {
Value Expr
}
func (GoStmt) stmtNode() {}
type DeferStmt struct {
Value Expr
}
func (DeferStmt) stmtNode() {}
type ExprStmt struct {
Value Expr
}
func (ExprStmt) stmtNode() {}
type IfStmt struct {
Cond Expr
Then []Stmt
Else []Stmt
}
func (IfStmt) stmtNode() {}
type WhileStmt struct {
Cond Expr
Body []Stmt
}
func (WhileStmt) stmtNode() {}
type ForEachStmt struct {
Name string
Source Expr
Body []Stmt
}
func (ForEachStmt) stmtNode() {}
type TryCatchStmt struct {
TryBody []Stmt
CatchName string
CatchType string
CatchBody []Stmt
}
func (TryCatchStmt) stmtNode() {}
type SelectStmt struct {
Cases []SelectCase
}
func (SelectStmt) stmtNode() {}
type MatchStmt struct {
Value Expr
Cases []MatchCase
}
func (MatchStmt) stmtNode() {}
type MatchCase struct {
EnumName, VariantName string
Bindings []string
Body []Stmt
}
type SelectCase struct {
Source Expr
Body []Stmt
}
type IdentExpr struct {
Name string
}
func (IdentExpr) exprNode() {}
type IntExpr struct {
Value string
}
func (IntExpr) exprNode() {}
type FloatExpr struct {
Value string
}
func (FloatExpr) exprNode() {}
type StringExpr struct {
Value string
}
func (StringExpr) exprNode() {}
type BoolExpr struct {
Value bool
}
func (BoolExpr) exprNode() {}
type NullExpr struct{}
func (NullExpr) exprNode() {}
type UnaryExpr struct {
Op string
Value Expr
}
func (UnaryExpr) exprNode() {}
type BinaryExpr struct {
Left Expr
Op string
Right Expr
}
func (BinaryExpr) exprNode() {}
type CallExpr struct {
Callee Expr
Args []Expr
TypeArgs []string
NamedArgs []NamedArg
}
type NamedArg struct {
Name string
Value Expr
}
func (CallExpr) exprNode() {}
type SelectorExpr struct {
Receiver Expr
Name string
}
func (SelectorExpr) exprNode() {}
type IndexExpr struct {
Receiver Expr
Index Expr
}
func (IndexExpr) exprNode() {}
type EnumVariantExpr struct {
EnumName, VariantName string
Values []Expr
}
func (EnumVariantExpr) exprNode() {}
type LambdaExpr struct {
Params []Param
ImplicitIt bool
Body []Stmt
}
func (LambdaExpr) exprNode() {}