ifdef

command module
v0.0.0-...-9a7df72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2018 License: MIT Imports: 8 Imported by: 0

README

ifdef

#ifdef golang code generation

GitHub license

Preprocessor pattern
// #ifdef LIST_OF_MACRO_NAMES

controlled text

// #endif
Preprocessor key-value pattern
// #kv MACRO_NAME key:value

That pattern are removed at the result source.

Example:

// #kv Float64 short:F64
// #kv Float64 type:float64
// #kv Float32 short:F32
// #kv Float32 type:float32

// Min#short return minimal of 2 values with type #type
func Min#short(a,b #type) #type{
	if a > b {
		return b
	}
	return a
}
Installation
go install
CLI commands
./ifdef -h
Usage of ./ifdef:
  -i string
    	name of input Go source
  -l	show list of preprocessor names
  -o string
    	name of output Go source
  -p string
    	allowable preprocessors #ifdef...#endif
Example on test file

Go template (see file ./testdata/test.gotmpl):

package test

// some comment

// #ifdef pre1
// a1 function return zero value of int
 func a1() int {
// #endif
// #ifdef pre2
// a2 function return zero value of float64
func a2() float64{
// #endif
// templorary variable
	b := 0
	return b
}
# show list of preprocessor names
ifdef -l -i=./testdata/test.gotmpl

# Preprocessor names :
# * pre1
# * pre2

Example of generate pre1:

# generate file `pre1.go` with preprocessor flag `pre1`
ifdef -p=pre1 -i=./testdata/test.gotmpl -o=./testdata/pre1.go

Result of file pre1.go:

package test

// some comment

// a2 function return zero value of float64
func a2() float64{
// templorary variable
	b := 0
	return b
}

Example of generate pre2:

# generate file `pre2.go` with preprocessor flag `pre2`
ifdef -p=pre2 -i=./testdata/test.gotmpl -o=./testdata/pre2.go

Result of file pre2.go:

package test

// some comment

// a1 function return zero value of int
func a1() int {
	// templorary variable
	b := 0
	return b
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL