gopp

package
v0.0.0-...-c90ad4d Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2014 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

gopp provides an easy to use (but somewhat illogical) preprocessor for Go. It allows similar functionality to cpp, such as ifdef, ifndef, define, undef and other odd combinations thereof.

Note: There is currently no support for nested ifdef/ifndefs.

Index

Constants

View Source
const Version = "0.4.2"

Variables

This section is empty.

Functions

This section is empty.

Types

type Gopp

type Gopp struct {
	Macros map[string]interface{}

	StripComments bool
	Prefix        string
	// contains filtered or unexported fields
}

func New

func New(strip bool) (g *Gopp)

New creates a new gopp instance with sane defaults. The macro `_GOPP` is automatically set to the gopp version.

func (*Gopp) Define

func (g *Gopp) Define(name string)

Define takes a name, and sets it to the sane default of 1, which can then be used when preprocessing a Go file.

func (*Gopp) DefineValue

func (g *Gopp) DefineValue(name string, value interface{})

DefineValue takes a name and a value, and defines them as a macro to use when preprocessing a Go file.

func (*Gopp) Parse

func (g *Gopp) Parse(r io.Reader) error

Parse takes an io.Reader (usually from an os.Open call), and will process the resulting code read from it, preprocessing and substituting in macros as required.

func (*Gopp) Print

func (g *Gopp) Print(w io.Writer) error

Print takes the resulting new AST after a call to Parse, and will print it to the given io.Writer

func (*Gopp) Reset

func (g *Gopp) Reset()

Reset will redefine the bits of a gopp instance, which you can use (e.g.) each time you want to parse a new file.

func (*Gopp) Undefine

func (g *Gopp) Undefine(name string)

Undefine will remove a given name from the macro list used when processing Go files.

type Token

type Token struct {
	Position token.Pos
	Token    token.Token
	String   string
}

Token provides a simple struct face to the `pos, tok, lit` returned by Go's go/scanner package. This is passed around by gopp internally in a chan.

Jump to

Keyboard shortcuts

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