Skip to content

Commit 3827bd1

Browse files
committed
make Statement sum type
1 parent 8df930d commit 3827bd1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

ast/node.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ type Node interface {
1414
// Statement is the interface for statement (Ex command or Comment).
1515
type Statement interface {
1616
Node
17+
stmtNode()
1718
}
1819

1920
// ExCommand is the interface for Ex-command.
2021
type ExCommand interface {
2122
Node
2223
Cmd() Cmd
24+
stmtNode()
2325
}
2426

2527
// Expr is the interface for expression.
@@ -524,6 +526,40 @@ type LambdaExpr struct {
524526

525527
func (i *LambdaExpr) Pos() Pos { return i.Lcurlybrace }
526528

529+
// stmtNode() ensures that only ExComamnd and Comment nodes can be assigned to
530+
// an Statement.
531+
//
532+
func (*Break) stmtNode() {}
533+
func (*Catch) stmtNode() {}
534+
func (*Continue) stmtNode() {}
535+
func (DelFunction) stmtNode() {}
536+
func (*EchoCmd) stmtNode() {}
537+
func (*Echohl) stmtNode() {}
538+
func (*Else) stmtNode() {}
539+
func (*ElseIf) stmtNode() {}
540+
func (*EndFor) stmtNode() {}
541+
func (EndFunction) stmtNode() {}
542+
func (*EndIf) stmtNode() {}
543+
func (*EndTry) stmtNode() {}
544+
func (*EndWhile) stmtNode() {}
545+
func (*ExCall) stmtNode() {}
546+
func (Excmd) stmtNode() {}
547+
func (*Execute) stmtNode() {}
548+
func (*Finally) stmtNode() {}
549+
func (*For) stmtNode() {}
550+
func (Function) stmtNode() {}
551+
func (*If) stmtNode() {}
552+
func (*Let) stmtNode() {}
553+
func (*LockVar) stmtNode() {}
554+
func (*Return) stmtNode() {}
555+
func (*Throw) stmtNode() {}
556+
func (*Try) stmtNode() {}
557+
func (*UnLet) stmtNode() {}
558+
func (*UnLockVar) stmtNode() {}
559+
func (*While) stmtNode() {}
560+
561+
func (*Comment) stmtNode() {}
562+
527563
// exprNode() ensures that only expression nodes can be assigned to an Expr.
528564
//
529565
func (*TernaryExpr) exprNode() {}

0 commit comments

Comments
 (0)