All Projects → moznion → Gowrtr

moznion / Gowrtr

Licence: mit
gowrtr is a library that supports golang code generation

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Gowrtr

Gradle Xjc Plugin
A Gradle plugin to run the XJC binding compiler during a build
Stars: ✭ 38 (-45.71%)
Mutual labels:  code-generation
Pymbolic
A simple package to do symbolic math (focus on code gen and DSLs)
Stars: ✭ 57 (-18.57%)
Mutual labels:  code-generation
Byte Buddy Tutorial
“Byte Buddy Tutorial” 中文翻译:Byte Buddy 教程。
Stars: ✭ 67 (-4.29%)
Mutual labels:  code-generation
Dogen
Reference implementation of the MASD Code Generator.
Stars: ✭ 44 (-37.14%)
Mutual labels:  code-generation
Ffcx
Next generation FEniCS Form Compiler
Stars: ✭ 55 (-21.43%)
Mutual labels:  code-generation
Expressiontreetostring
String representations of expression trees + library of expression tree objects
Stars: ✭ 62 (-11.43%)
Mutual labels:  code-generation
Maple
Elixir GraphQL Client | Compile time client code generator for GraphQL APIs based on introspection queries and schema files
Stars: ✭ 20 (-71.43%)
Mutual labels:  code-generation
Json2java4idea
A JSON to Java conversion plugin for Intellij IDEA and AndroidStudio.
Stars: ✭ 69 (-1.43%)
Mutual labels:  code-generation
Idris Elixir
A code-generator for Idris that targets Elixir
Stars: ✭ 56 (-20%)
Mutual labels:  code-generation
Umesimd
UME::SIMD A library for explicit simd vectorization.
Stars: ✭ 66 (-5.71%)
Mutual labels:  code-generation
Scala Db Codegen
Scala code/boilerplate generator from a db schema
Stars: ✭ 49 (-30%)
Mutual labels:  code-generation
Spoon
Spoon is a metaprogramming library to analyze and transform Java source code (up to Java 15). 🥄 is made with ❤️, 🍻 and ✨. It parses source files to build a well-designed AST with powerful analysis and transformation API.
Stars: ✭ 1,078 (+1440%)
Mutual labels:  code-generation
Elm Street
🌳 Crossing the road between Haskell and Elm
Stars: ✭ 65 (-7.14%)
Mutual labels:  code-generation
Devflowcharter
Flowchart builder and code generator.
Stars: ✭ 41 (-41.43%)
Mutual labels:  code-generation
Dbx
A neat codegen-based database wrapper written in Go
Stars: ✭ 68 (-2.86%)
Mutual labels:  code-generation
Drupal Console
The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
Stars: ✭ 913 (+1204.29%)
Mutual labels:  code-generation
Genco
A whitespace-aware quasiquoter for beautiful code generation.
Stars: ✭ 59 (-15.71%)
Mutual labels:  code-generation
Snowflaqe
A dotnet CLI tool to work with GraphQL queries: static query verification, type checking and code generating type-safe clients for F# and Fable.
Stars: ✭ 69 (-1.43%)
Mutual labels:  code-generation
Mid
mid is a generic domain-specific language for generating code and documentation
Stars: ✭ 68 (-2.86%)
Mutual labels:  code-generation
Pqt
Postgres schema definition, sql/go, code generation package.
Stars: ✭ 65 (-7.14%)
Mutual labels:  code-generation

gowrtr CircleCI codecov GoDoc Go Report Card

gowrtr (pronunciation:go writer) is a library that supports golang code generation.

This library is inspired by square/javapoet.

Synopsis

Here is a simple example:

package main

import (
	"fmt"

	"github.com/moznion/gowrtr/generator"
)

func main() {
	generator := generator.NewRoot(
		generator.NewComment(" THIS CODE WAS AUTO GENERATED"),
		generator.NewPackage("main"),
		generator.NewNewline(),
	).AddStatements(
		generator.NewFunc(
			nil,
			generator.NewFuncSignature("main"),
		).AddStatements(
			generator.NewRawStatement(`fmt.Println("hello, world!")`),
		),
	).
		Gofmt("-s").
		Goimports()

	generated, err := generator.Generate(0)
	if err != nil {
		panic(err)
	}
	fmt.Println(generated)
}

then it generates the golang code like so:

// THIS CODE WAS AUTO GENERATED
package main

import "fmt"

func main() {
        fmt.Println("hello, world!")
}

And GoDoc shows you a greater number of examples.

Description

Please refer to the godoc: GoDoc

Root

  • Root is an entry point to generate the go code.
  • Root supports following code formatting on code generating phase. It applies such formatters to generated code.
    • gofmt: with Gofmt(gofmtOptions ...string)
    • goimports: with Goimports()

Immutability

Methods of this library act as immutable. It means it doesn't change any internal state implicitly, so you can take a snapshot of the code generator. That is useful to reuse and derive the code generator instance.

Debug friendly

This library shows "where is a cause of the error" when code generator raises an error. This means each error message contains a pointer for the error source (i.e. file name and the line number). This should be helpful for debugging.

Error messages example:

[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at /tmp/main.go:22)

Supported syntax

  • [x] package
  • [x] import
  • [x] struct
  • [x] interface
  • [x] composite literal
  • [x] if
    • [x] else if
    • [x] else
  • [x] switch
    • [x] case
    • [x] default
  • [x] for
  • [x] code block
  • [x] func
  • [x] anonymous func
    • [x] immediately invoking
  • one line statement
    • [x] raw
    • [x] newline
    • [x] return
    • [x] comment

For developers of this library

Setup development environment

$ make bootstrap

How to define and generate error messages

Please edit internal/errmsg/errmsg.go and execute make errgen.

See also: moznion/go-errgen

Blog posts

License

The MIT License (MIT)
Copyright © 2019 moznion, http://moznion.net/ <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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].