Created
December 4, 2016 17:15
-
-
Save haya14busa/d84004170caf97ad55162aecb5adfc9e to your computer and use it in GitHub Desktop.
How go/ast represents syntax tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://github.com/golang/go/blob/d54b60a2b2470ea42559b58995e86ff20dd70471/src/go/ast/ast.go | |
type Node interface { | |
Pos() token.Pos | |
End() token.Pos | |
} | |
type Expr interface { | |
Node | |
exprNode() | |
} | |
type Stmt interface { | |
Node | |
stmtNode() | |
} | |
// Pos and End implementations for expression/type nodes. | |
func (x *BadExpr) Pos() token.Pos { return x.From } | |
func (x *Ident) Pos() token.Pos { return x.NamePos } | |
// ... | |
// exprNode() ensures that only expression/type nodes can be | |
// assigned to an Expr. | |
// | |
func (*BadExpr) exprNode() {} | |
func (*Ident) exprNode() {} | |
// ... | |
// stmtNode() ensures that only statement nodes can be | |
// assigned to a Stmt. | |
// | |
func (*BadStmt) stmtNode() {} | |
func (*DeclStmt) stmtNode() {} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment