Documentation ¶
Overview ¶
Package generate provides the generation of useful methods, variables, and constants for Cogent Core code.
Index ¶
- Variables
- func Generate(c *config.Config) error
- func GetPagesExamples(c *config.Config) (ordmap.Map[string, []byte], error)
- func HasEmbedDirective(typ *typegen.Type) bool
- func HasNoNewDirective(typ *typegen.Type) bool
- func Pages(c *config.Config) error
- func ParsePackages(cfg *config.Config) ([]*packages.Package, error)
- func TreePkg(typ *typegen.Type) string
- func WritePagegen(c *config.Config, examples ordmap.Map[string, []byte]) error
Constants ¶
This section is empty.
Variables ¶
var TreeMethodsTmpl = template.Must(template.New("TreeMethods"). Funcs(template.FuncMap{ "HasEmbedDirective": HasEmbedDirective, "HasNoNewDirective": HasNoNewDirective, "DocToComment": typegen.DocToComment, "TreePkg": TreePkg, }).Parse( ` {{if not (HasNoNewDirective .)}} // New{{.LocalName}} adds a new [{{.LocalName}}] with the given name to the given parent: {{DocToComment .Doc}} func New{{.LocalName}}(parent {{TreePkg .}}Node, name ...string) *{{.LocalName}} { return parent.NewChild({{.LocalName}}Type, name...).(*{{.LocalName}}) } {{end}} // NodeType returns the [*types.Type] of [{{.LocalName}}] func (t *{{.LocalName}}) NodeType() *types.Type { return {{.LocalName}}Type } // New returns a new [*{{.LocalName}}] value func (t *{{.LocalName}}) New() {{TreePkg .}}Node { return &{{.LocalName}}{} } {{if HasEmbedDirective .}} // {{.LocalName}}Embedder is an interface that all types that embed {{.LocalName}} satisfy type {{.LocalName}}Embedder interface { As{{.LocalName}}() *{{.LocalName}} } // As{{.LocalName}} returns the given value as a value of type {{.LocalName}} if the type // of the given value embeds {{.LocalName}}, or nil otherwise func As{{.LocalName}}(k {{TreePkg .}}Node) *{{.LocalName}} { if k == nil || k.This() == nil { return nil } if t, ok := k.({{.LocalName}}Embedder); ok { return t.As{{.LocalName}}() } return nil } // As{{.LocalName}} satisfies the [{{.LocalName}}Embedder] interface func (t *{{.LocalName}}) As{{.LocalName}}() *{{.LocalName}} { return t } {{end}} `, ))
TreeMethodsTmpl is a template that contains the methods and functions specific to [tree.Node] types.
Functions ¶
func Generate ¶
Generate is the main entry point to code generation that does all of the generation according to the given config info. It overrides the [config.Config.Generate.Typegen.InterfaceConfigs] info.
func GetPagesExamples ¶
GetPagesExamples collects and returns all of the pages examples.
func HasEmbedDirective ¶
HasEmbedDirective returns whether the given typegen.Type has a "core:embedder" comment directive. This function is used in TreeMethodsTmpl.
func HasNoNewDirective ¶
HasNoNewDirective returns whether the given typegen.Type has a "core:no-new" comment directive. This function is used in TreeMethodsTmpl.
func ParsePackages ¶
ParsePackages parses the package(s) based on the given config info.
Types ¶
This section is empty.