Created
August 19, 2018 08:58
-
-
Save as/ccdd8ff8507d02dcbe27547ae592fc05 to your computer and use it in GitHub Desktop.
hello world in go...ast
This file contains hidden or 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
package main | |
import ( | |
. "go/ast" | |
"go/format" | |
"go/token" | |
"os" | |
) | |
func main() { | |
format.Node(os.Stdout, token.NewFileSet(), &File{ | |
Name: &Ident{Name: "main"}, | |
Decls: []Decl{ | |
&GenDecl{ | |
Tok: token.IMPORT, | |
Specs: []Spec{ | |
&ImportSpec{Path: &BasicLit{Kind: token.STRING, Value: `"fmt"`}}, | |
}, | |
}, | |
&FuncDecl{ | |
Name: &Ident{ | |
Name: "main", | |
}, | |
Type: &FuncType{ | |
Params: &FieldList{}, | |
Results: &FieldList{}, | |
}, | |
Body: &BlockStmt{ | |
List: []Stmt{ | |
&ExprStmt{ | |
X: &CallExpr{ | |
Fun: &SelectorExpr{ | |
X: &Ident{Name: "fmt"}, | |
Sel: &Ident{Name: "Println"}, | |
}, | |
Args: []Expr{ | |
&BasicLit{Kind: token.STRING, Value: `"Hello, playground"`}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment