aboutsummaryrefslogtreecommitdiff
path: root/pkg/lang/ast
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/lang/ast')
-rw-r--r--pkg/lang/ast/nodes.go9
-rw-r--r--pkg/lang/ast/op.go8
-rw-r--r--pkg/lang/ast/stmt.go5
3 files changed, 21 insertions, 1 deletions
diff --git a/pkg/lang/ast/nodes.go b/pkg/lang/ast/nodes.go
index 117d8bf..74ebd2a 100644
--- a/pkg/lang/ast/nodes.go
+++ b/pkg/lang/ast/nodes.go
@@ -17,3 +17,12 @@ type CondNode struct {
Cond Expr
Then BlockNode
}
+
+type TypeMethodNode struct {
+ At source.Loc
+ HasThis bool
+ IsConstructor bool
+ Name IdentNode
+ Args []IdentNode
+ Body BlockNode
+}
diff --git a/pkg/lang/ast/op.go b/pkg/lang/ast/op.go
index 6f48e0c..063a309 100644
--- a/pkg/lang/ast/op.go
+++ b/pkg/lang/ast/op.go
@@ -21,6 +21,8 @@ const (
BinOpLte
BinOpGt
BinOpGte
+
+ BinOpDot
)
func BinOpFromToken(tok token.Token) (BinOp, bool) {
@@ -50,6 +52,8 @@ func BinOpFromToken(tok token.Token) (BinOp, bool) {
op = BinOpGt
case token.Gte:
op = BinOpGte
+ case token.Dot:
+ op = BinOpDot
default:
return 0, false
}
@@ -67,6 +71,8 @@ func (op BinOp) Precedence() int {
return 3
case BinOpStar, BinOpSlash, BinOpPercent:
return 4
+ case BinOpDot:
+ return 5
default:
panic(fmt.Sprintf("unknown binary operator: %d", op))
@@ -88,6 +94,8 @@ func (op BinOp) Associativity() Associativity {
return AssociativityRight
case BinOpEq, BinOpNeq, BinOpLt, BinOpLte, BinOpGt, BinOpGte:
return AssociativityLeft
+ case BinOpDot:
+ return AssociativityLeft
default:
panic(fmt.Sprintf("unknown binary operator: %d", op))
}
diff --git a/pkg/lang/ast/stmt.go b/pkg/lang/ast/stmt.go
index 8a538f2..7545bee 100644
--- a/pkg/lang/ast/stmt.go
+++ b/pkg/lang/ast/stmt.go
@@ -41,7 +41,10 @@ type StmtFnDecl struct {
Body BlockNode
}
-type StmtTypeDecl struct {}
+type StmtTypeDecl struct {
+ Name IdentNode
+ Methods []TypeMethodNode
+}
type StmtVarDecl struct {
Name IdentNode