All Projects → goplus → gox

goplus / gox

Licence: Apache-2.0 License
Code generator for the Go language

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gox

Gop
GoPlus - The Go+ language for engineering, STEM education, and data science
Stars: ✭ 7,829 (+8228.72%)
Mutual labels:  goplus, stem-education
spx
spx - A Go+ 2D Game Engine for STEM education
Stars: ✭ 72 (-23.4%)
Mutual labels:  goplus, stem-education
gossa
The Go/Go+ Interpreter
Stars: ✭ 53 (-43.62%)
Mutual labels:  goplus, stem-education
hubi
Humanitarian ubiquitous language helper
Stars: ✭ 17 (-81.91%)
Mutual labels:  code-generator
xgen
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
Stars: ✭ 153 (+62.77%)
Mutual labels:  code-generator
molicode
molicode
Stars: ✭ 75 (-20.21%)
Mutual labels:  code-generator
php-code-generator
PHP code generator library
Stars: ✭ 144 (+53.19%)
Mutual labels:  code-generator
php-json-schema-model-generator
Creates (immutable) PHP model classes from JSON-Schema files including all validation rules as PHP code
Stars: ✭ 36 (-61.7%)
Mutual labels:  code-generator
TIGER
implement a full compiler based on c++ 11
Stars: ✭ 17 (-81.91%)
Mutual labels:  code-generator
ncg-crud-ngx-md
Angular 4+ Material Design CRUD/Admin app by NinjaCodeGen http://DNAfor.NET
Stars: ✭ 36 (-61.7%)
Mutual labels:  code-generator
nunavut
Generate code from DSDL using PyDSDL and Jinja2
Stars: ✭ 23 (-75.53%)
Mutual labels:  code-generator
GENERIS
Versatile Go code generator.
Stars: ✭ 32 (-65.96%)
Mutual labels:  code-generator
autogenu-jupyter
An automatic code generator for nonlinear model predictive control (NMPC) and the continuation/GMRES method (C/GMRES) based numerical solvers for NMPC
Stars: ✭ 89 (-5.32%)
Mutual labels:  code-generator
Kodgen
C++17 parser and code generator
Stars: ✭ 19 (-79.79%)
Mutual labels:  code-generator
my curd
超轻量 快速开发脚手架、流程平台。
Stars: ✭ 38 (-59.57%)
Mutual labels:  code-generator
copygen
Go generator to copy values from type to type and fields from struct to struct (copier without reflection). Generate any code based on types.
Stars: ✭ 121 (+28.72%)
Mutual labels:  code-generator
yoma
一个小而美的低代码全栈开发平台,一键生成后端api接口+前端页面代码+在线接口文档,节省50%的前后端开发的工作量。基于springboot +mybatis+spring security+vue 技术栈
Stars: ✭ 137 (+45.74%)
Mutual labels:  code-generator
protocell
Conjures up convenient OCaml types and serialization functions based on protobuf definition files
Stars: ✭ 18 (-80.85%)
Mutual labels:  code-generator
yii-gii
Yii code generator extension
Stars: ✭ 27 (-71.28%)
Mutual labels:  code-generator
crisp
CRISP is a Google Chrome extension for automated testing that generates test code and automates time-consuming operations in test development. It speeds up test development by replacing time-consuming manual operations with automated features.
Stars: ✭ 22 (-76.6%)
Mutual labels:  code-generator

gox - Code generator for the Go language

Build Status Go Report Card GitHub release Coverage Status GoDoc

Quick start

Create a file named hellogen.go, like below:

package main

import (
	"go/token"
	"go/types"
	"os"

	"github.com/goplus/gox"
	"github.com/goplus/gox/packages"
)

func ctxRef(pkg *gox.Package, name string) gox.Ref {
	return pkg.CB().Scope().Lookup(name)
}

func main() {
	imp, _, _ := packages.NewImporter(nil, "fmt", "strings", "strconv")
	pkg := gox.NewPackage("", "main", &gox.Config{Importer: imp})
	fmt := pkg.Import("fmt")
	v := pkg.NewParam(token.NoPos, "v", types.Typ[types.String]) // v string

	pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
		DefineVarStart(token.NoPos, "a", "b").Val("Hi").Val(3).EndInit(2). // a, b := "Hi", 3
		NewVarStart(nil, "c").Val(ctxRef(pkg, "b")).EndInit(1).            // var c = b
		NewVar(gox.TyEmptyInterface, "x", "y").                            // var x, y interface{}
		Val(fmt.Ref("Println")).
		/**/ Val(ctxRef(pkg, "a")).Val(ctxRef(pkg, "b")).Val(ctxRef(pkg, "c")). // fmt.Println(a, b, c)
		/**/ Call(3).EndStmt().
		NewClosure(gox.NewTuple(v), nil, false).BodyStart(pkg).
		/**/ Val(fmt.Ref("Println")).Val(v).Call(1).EndStmt(). // fmt.Println(v)
		/**/ End().
		Val("Hello").Call(1).EndStmt(). // func(v string) { ... } ("Hello")
		End()

	gox.WriteTo(os.Stdout, pkg, false)
}

Try it like:

go mod init hello
go mod tidy
go run hellogen.go

This will dump Go source code to stdout. The following is the output content:

package main

import fmt "fmt"

func main() {
	a, b := "Hi", 3
	var c = b
	var x, y interface {
	}
	fmt.Println(a, b, c)
	func(v string) {
		fmt.Println(v)
	}("Hello")
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].