code

package
v0.0.0-...-02bf512 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Boolean
	Bool   = "bool"
	Uint8  = "uint8"
	Uint16 = "uint16"
	Uint32 = "uint32"
	Uint64 = "uint64"

	// Signed ints
	Int8  = "int8"
	Int16 = "int16"
	Int32 = "int32"
	Int64 = "int64"

	// String, UUID, JSON
	String = "string"
	Uuid   = "uuid"
	Json   = "json"

	// Date, DateTime, and Interval
	Date           = "date"           // days since 2970
	DateTimeSecs   = "dateTimeSecs"   // seconds since 1970
	DateTimeMillis = "dateTimeMillis" // milliseconds since 1970
	DurationDays   = "durationDays"   // days elapsed
	DurationSecs   = "durationSecs"   // seconds elapsed
	DurationMillis = "durationMillis" // elapsed milliseconds

	// Aray, Enum, List, Map, Maybe, Object, Set
	Array  = "array"
	Enum   = "enum"
	List   = "list"
	Map    = "map"
	Maybe  = "maybe"
	Object = "object"
	Set    = "set"

	Main = "main" // name of main function
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseGenerator

type BaseGenerator struct {
	// contains filtered or unexported fields
}

BaseGenerator contains the base parts of the Generator interface

func (BaseGenerator) CurrentSrc

func (bg BaseGenerator) CurrentSrc() writer.Writer[string]

CurrentSrc returns the writer for the current src

func (*BaseGenerator) Dir

func (bg *BaseGenerator) Dir(name string)

Dir panics if dir already exists, or creating the dir has an error

func (BaseGenerator) GetBasePath

func (bg BaseGenerator) GetBasePath() string

GetBasePath panics if SetBasePath has not been called

func (*BaseGenerator) SetBasePath

func (bg *BaseGenerator) SetBasePath(bp string)

SetBasePath panics if the base path has already been set

func (*BaseGenerator) Src

func (bg *BaseGenerator) Src(name string)

Src panics if the file already exists

type Dir

type Dir struct {
	Sources []Src

	// Init is an optional initialization function for the directory.
	// The set of all Init functions execute in some arbitrary order at runtime.
	// Depending on the target language, they may all execute before main starts, or they may execute some time later, such
	// as when files that need them are loaded.
	Init union.Maybe[FuncDef]
}

Dir is a directory of source files

type FuncDef

type FuncDef struct {
	Params      []VarDef          // Parameters of function
	LocalConsts map[string]VarDef // Local constants
	LocalVars   map[string]VarDef // Local vars
	Results     []VarDef          // Results of function
}

FuncDef is a function definition

type Generator

type Generator interface {
	// Return the base path to generate dirs under
	GetBasePath() string
	// Set the base path once to generate dirs under. Setting again panics.
	SetBasePath(basePath string) Generator
	// Creates a directory, or wipes out the contents (assuming they are from a prior run of the same generator).
	// The caller must generate parent directories before child directories, or a panic occurs.
	// This will be the current directory until another call is made
	Dir(name string) Generator
	// Creates a src file in the current directory
	// This will be the current source file under another call is made
	Src(name string) Generator
	// Create global constants in the current source file
	GlobalConsts(constants ...VarDef) Generator
	// Create global vars in the current source file
	GlobalVars(globals ...VarDef) Generator
	// Create types in the current source file
	Types(objects ...ObjectDef) Generator
	// Create funcs in the current source file
	Funcs(funcs ...FuncDef) Generator
}

Generator is the interface describing an easy to use fluent API for generating packages of code. If anything goes wrong, the generator panics.

type ObjectDef

type ObjectDef struct {
	Fields map[string]VarDef
	Funcs  map[string]FuncDef
}

ObjectDef is an object, which can have fields and functions that operate on them

type Package

type Package struct {
	Dirs map[string]Dir
}

Package is a package of code, not necessarily a complete program

type Src

type Src struct {
	GlobalConsts map[string]VarDef
	GlobalVars   map[string]VarDef
	Objects      map[string]ObjectDef
	Funcs        map[string]FuncDef
}

Src is a source file

type TypeDef

type TypeDef struct {
	Type          string   // The type
	ArrayBounds   []int    // The bounds of an array, cannot be empty
	Name          string   // The name of an enum or object
	Names         []string // The names of enum constants or object generics - zero-based indexes are the enum values, strings are the names
	ListDimension int      // The dimension of the list (eg, list of string, list of list of string, etc), cannot be 0
	KeyType       *TypeDef // The map key type
	ValueType     *TypeDef // The array element type, list element type, map value type, maybe type, or set type
}

type VarDef

type VarDef struct {
	Type TypeDef // The type of variable
	Name string  // The name of the variable
}

VarDef is a variable type definition

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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