Command gencodec generates marshaling methods for Go struct types.
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 add support for map/slice conversions, tests 8 years ago
..
README.md add support for map/slice conversions, tests 8 years ago
assign.go add support for map/slice conversions, tests 8 years ago
binary_op.go add support for map/slice conversions, tests 8 years ago
builtins.go add support for map/slice conversions, tests 8 years ago
declaration.go add support for map/slice conversions, tests 8 years ago
declare.go add support for map/slice conversions, tests 8 years ago
declare_and_assign.go add support for map/slice conversions, tests 8 years ago
dotted.go add support for map/slice conversions, tests 8 years ago
expression.go add support for map/slice conversions, tests 8 years ago
for.go add support for map/slice conversions, tests 8 years ago
function.go add support for map/slice conversions, tests 8 years ago
function_call.go add support for map/slice conversions, tests 8 years ago
if.go add support for map/slice conversions, tests 8 years ago
import.go add support for map/slice conversions, tests 8 years ago
package.go add support for map/slice conversions, tests 8 years ago
range.go add support for map/slice conversions, tests 8 years ago
return.go add support for map/slice conversions, tests 8 years ago
star.go add support for map/slice conversions, tests 8 years ago
statement.go add support for map/slice conversions, tests 8 years ago
stdlib_imports.go add support for map/slice conversions, tests 8 years ago
struct.go add support for map/slice conversions, tests 8 years ago
thunk.go add support for map/slice conversions, tests 8 years ago
type.go add support for map/slice conversions, tests 8 years ago
typenames.go add support for map/slice conversions, tests 8 years ago
unary_op.go add support for map/slice conversions, tests 8 years ago
var.go add support for map/slice conversions, tests 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