You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Felix Lange
5b3e75f776
|
8 years ago | |
---|---|---|
.. | ||
README.md | 8 years ago | |
assign.go | 8 years ago | |
binary_op.go | 8 years ago | |
builtins.go | 8 years ago | |
declaration.go | 8 years ago | |
declare.go | 8 years ago | |
declare_and_assign.go | 8 years ago | |
dotted.go | 8 years ago | |
expression.go | 8 years ago | |
for.go | 8 years ago | |
function.go | 8 years ago | |
function_call.go | 8 years ago | |
if.go | 8 years ago | |
import.go | 8 years ago | |
package.go | 8 years ago | |
range.go | 8 years ago | |
return.go | 8 years ago | |
star.go | 8 years ago | |
statement.go | 8 years ago | |
stdlib_imports.go | 8 years ago | |
struct.go | 8 years ago | |
thunk.go | 8 years ago | |
type.go | 8 years ago | |
typenames.go | 8 years ago | |
unary_op.go | 8 years ago | |
var.go | 8 years ago |
README.md
gogen
A simplification of Go's go/ast
package that allows for some
interesting code generation. Currently very rough.
Examples
Hello World
package main
import (
"os"
. "github.com/garslo/gogen"
)
func main() {
pkg := Package{Name: "main"}
pkg.Declare(Import{"fmt"})
pkg.Declare(Function{
Name: "main",
Body: []Statement{
CallFunction{
Func: Dotted{Var{"fmt"}, "Println"},
Params: []Expression{Var{`"Hello World!"`}},
},
},
})
pkg.WriteTo(os.Stdout)
}
Output:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
More
See the examples directory for more examples and a build/run script.
$ ./run-example.sh for_loop.go
CODE:
package main
import "os"
import "fmt"
func main() {
var i int
for i = 0; i <= 10; i++ {
fmt.Println(i)
}
os.Exit(i)
}
RUN RESULT:
0
1
2
3
4
5
6
7
8
9
10
exit status 11