Documentation
¶
Overview ¶
Package gengo is a code-generation framework.
Index ¶
- Constants
- func Execute(nameSystems namer.NameSystems, defaultSystem string, ...) error
- func ExtractCommentTags(marker string, lines []string) map[string][]stringdeprecated
- func ExtractFunctionStyleCommentTags(marker string, tagNames []string, lines []string) (map[string][]Tag, error)
- func ExtractSingleBoolCommentTag(marker string, key string, defaultVal bool, lines []string) (bool, error)
- func GoBoilerplate(headerFile, buildTag, generatedBy string) ([]byte, error)
- type Tag
Constants ¶
const StdBuildTag = "ignore_autogenerated"
StdBuildTag is a suggested build-tag which tools can use both as an argument to GoBoilerplate and to Execute.
const StdGeneratedBy = "// Code generated by GENERATOR_NAME. DO NOT EDIT."
StdGeneratedBy is a suggested "generated by" line which tools can use as an argument to GoBoilerplate.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute(nameSystems namer.NameSystems, defaultSystem string, getTargets func(*generator.Context) []generator.Target, buildTag string, patterns []string) error
Execute implements most of a tool's main loop.
func ExtractCommentTags
deprecated
ExtractCommentTags parses comments for lines of the form:
'marker' + "key=value".
Values are optional; "" is the default. A tag can be specified more than one time and all values are returned. If the resulting map has an entry for a key, the value (a slice) is guaranteed to have at least 1 element.
Example: if you pass "+" for 'marker', and the following lines are in the comments:
+foo=value1 +bar +foo=value2 +baz="qux"
Then this function will return:
map[string][]string{"foo":{"value1, "value2"}, "bar": {""}, "baz": {`"qux"`}}
Deprecated: Use ExtractFunctionStyleCommentTags.
func ExtractFunctionStyleCommentTags ¶
func ExtractFunctionStyleCommentTags(marker string, tagNames []string, lines []string) (map[string][]Tag, error)
ExtractFunctionStyleCommentTags parses comments for special metadata tags. The marker argument should be unique enough to identify the tags needed, and should not be a marker for tags you don't want, or else the caller takes responsibility for making that distinction.
The tagNames argument is a list of specific tags being extracted. If this is nil or empty, all lines which match the marker are considered. If this is specified, only lines with begin with marker + one of the tags will be considered. This is useful when a common marker is used which may match lines which fail this syntax (e.g. which predate this definition).
This function looks for input lines of the following forms:
- 'marker' + "key=value"
- 'marker' + "key()=value"
- 'marker' + "key(arg)=value"
The arg is optional. If not specified (either as "key=value" or as "key()=value"), the resulting Tag will have an empty Args list.
The value is optional. If not specified, the resulting Tag will have "" as the value.
Tag comment-lines may have a trailing end-of-line comment.
The map returned here is keyed by the Tag's name without args.
A tag can be specified more than one time and all values are returned. If the resulting map has an entry for a key, the value (a slice) is guaranteed to have at least 1 element.
Example: if you pass "+" as the marker, and the following lines are in the comments:
+foo=val1 // foo +bar +foo=val2 // also foo +baz="qux" +foo(arg) // still foo
Then this function will return:
map[string][]Tag{ "foo": []Tag{{ Name: "foo", Args: nil, Value: "val1", }, { Name: "foo", Args: nil, Value: "val2", }, { Name: "foo", Args: []string{"arg"}, Value: "", }, { Name: "bar", Args: nil, Value: "" }, { Name: "baz", Args: nil, Value: "\"qux\"" }}
This function should be preferred instead of ExtractCommentTags.
func ExtractSingleBoolCommentTag ¶
func ExtractSingleBoolCommentTag(marker string, key string, defaultVal bool, lines []string) (bool, error)
ExtractSingleBoolCommentTag parses comments for lines of the form:
'marker' + "key=value1"
If the tag is not found, the default value is returned. Values are asserted to be boolean ("true" or "false"), and any other value will cause an error to be returned. If the key has multiple values, the first one will be used.
func GoBoilerplate ¶
GoBoilerplate returns the Go file header: - an optional build tag (negative, set it to ignore generated code) - an optional boilerplate file - an optional "generated by" comment
Types ¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
kilroy
kilroy is a trivial gengo/v2 program which adds a tag-method to types.
|
kilroy is a trivial gengo/v2 program which adds a tag-method to types. |
pointuh
pointuh is a trivial gengo/v2 program which consider its inputs, and emits to new packages the same types, except for structs, where all fields are pointers.
|
pointuh is a trivial gengo/v2 program which consider its inputs, and emits to new packages the same types, except for structs, where all fields are pointers. |
tracer
tracer is a trivial gengo/v2 program which prints the various hooks as they are called.
|
tracer is a trivial gengo/v2 program which prints the various hooks as they are called. |
Package generator defines an interface for code generators to implement.
|
Package generator defines an interface for code generators to implement. |
Package namer has support for making different type naming systems.
|
Package namer has support for making different type naming systems. |
Package parser provides code to parse go files, type-check them, extract the types.
|
Package parser provides code to parse go files, type-check them, extract the types. |
Package types contains go type information, packaged in a way that makes auto-generation convenient, whether by template or straight go functions.
|
Package types contains go type information, packaged in a way that makes auto-generation convenient, whether by template or straight go functions. |