Documentation
¶
Index ¶
- func IsAggregate(typ Type) bool
- func IsScalar(typ Type) bool
- type AccessLevel
- type AggregateType
- type BaseGenerator
- type BinaryOperator
- type BooleanOperator
- type Expr
- type FuncDef
- type Generator
- type ObjectDef
- type Operator
- type PkgDef
- type ScalarType
- type SrcDef
- type StmtDef
- type StmtKind
- type Type
- type TypeDef
- func OfArrayType(elementTyp *TypeDef, bounds []uint, access ...AccessLevel) *TypeDef
- func OfEnumType(name string, baseType *TypeDef, constants []string, access ...AccessLevel) *TypeDef
- func OfJSONType(access ...AccessLevel) *TypeDef
- func OfListType(elementType *TypeDef, access ...AccessLevel) *TypeDef
- func OfMapType(keyType *TypeDef, valueType *TypeDef, access ...AccessLevel) *TypeDef
- func OfMaybeType(elementType *TypeDef, access ...AccessLevel) *TypeDef
- func OfObjectType(baseType *TypeDef, name string, generics []string, access ...AccessLevel) *TypeDef
- func OfScalarType(typ ScalarType, access ...AccessLevel) *TypeDef
- func OfSetType(elementType *TypeDef, access ...AccessLevel) *TypeDef
- type Types
- type UnaryOperator
- type Val
- type ValKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAggregate ¶
IsAggregate is true if the Type is an Aggregate Type
Types ¶
type AccessLevel ¶
type AccessLevel int
AccessLevel indicates the level of access to a source member Depending on the target language, not all access levels may be supported The default level is Private
const ( Private AccessLevel = iota // Private access Package // Same package PackageSub // Same package or sub objects Public // All code )
type AggregateType ¶
type AggregateType Type
Aggregate is a type that has multiple values
const ( JSON AggregateType = iota + AggregateType(afterScalar) Array Enum List Map Maybe Object Set )
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 BinaryOperator ¶
type BinaryOperator Operator
BinaryOperator is a non-boolean operator with two arguments
const ( // Four basic ops Add BinaryOperator = iota + BinaryOperator(afterUnary) Sub Mul Div // String Concat // Bitwise BitAnd BitOr BitXor BitShiftLeft BitShiftRight BitShiftRightArithmetic )
type BooleanOperator ¶
type BooleanOperator Operator
BooleanOperator is a boolean operator with one to three arguments
const ( // Logical Unary Not BooleanOperator = iota + BooleanOperator(afterBinary) // Logical Binary And Or // Relational Binary Lesser LesserEquals Equals GreaterEquals Greater // Logical Ternary Ternary )
type Expr ¶
Expr is an expression If the Operator is a UnaryOperator, then Val2 is empty If the Operator is not Ternary, then Val3 is empty
func OfBinaryExpr ¶
func OfBinaryExpr( op BinaryOperator, val1 *Val, val2 *Val, ) Expr
OfBinaryExpr constructs a binary Expr
func OfBooleanExpr ¶
func OfBooleanExpr( op BooleanOperator, val1 *Val, val23 ...*Val, ) Expr
OfBooleanExpr constructs a binary boolean Expr If the operator is Not, then val23 is ignored If the operator is Ternary, then val23 must have two values All other operators are binary, so val23 must have one value
func OfUnaryExpr ¶
func OfUnaryExpr( op UnaryOperator, val *Val, ) Expr
OfUnaryExpr constructs a unary Expr
type FuncDef ¶
type FuncDef struct {
Access AccessLevel // The level of access
Params map[string]Val // Parameters of function
Locals map[string]Val // Local constants and vars
Results []TypeDef // 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 ...Val) Generator
// Create global vars in the current source file
GlobalVars(globals ...Val) 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 {
TypeDef TypeDef // Name of the object type, and any generics
Fields map[string]TypeDef // Object fields
Funcs map[string]FuncDef // Object methods
}
ObjectDef is an object, which can have fields and functions that operate on them
type Operator ¶
type Operator uint
Operator describes all types of operators
type PkgDef ¶
type PkgDef struct {
Path string // Relative path to dir containing sources
Sources []SrcDef // Source files
// Init is an optional initialization function for the package.
// The set of all package 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]
}
PkgDef is a directory of source files
type ScalarType ¶
type ScalarType Type
Scalar is a Type that has only one value
const ( Bool ScalarType = iota // Unsigned ints Uint Uint8 Uint16 Uint32 Uint64 // Signed ints Int Int8 Int16 Int32 Int64 // Floating point Float Double // String, UUID, JSON String UUID // Date, DateTime, and Duration Date // days since 1970 DateTimeSecs // seconds since 1970 DateTimeMillis // milliseconds since 1970 DurationDays // days elapsed DurationSecs // seconds elapsed DurationMillis // elapsed milliseconds )
type SrcDef ¶
type SrcDef struct {
Globals map[string]TypeDef // Global constants and vars
Objects map[string]ObjectDef // Objects
Funcs map[string]FuncDef // Top level functions that are not methods
Main FuncDef // Main function
}
SrcDef is a source file
type StmtDef ¶
type StmtDef struct {
Kind StmtKind // The kind of statement
Type union.Maybe[*TypeDef] // The TypeDef for a Constant or Local
Expr union.Maybe[*Expr] // The Value to assign a Constant or Local
}
StmtDef is a statement
type TypeDef ¶
type TypeDef struct {
Access AccessLevel // Level of access, if applicable. Empty means default level.
Typ Type // Type
ArrayBounds []uint // Bounds of an array. A dimension can be -1 for unspecified dimension, slice can
// be zero length for one unspecified dimension.
// For a list, one element >= 1 that indicates list, or list of list, etc.
Name string // Name of an enum or object
Names []string // Names of enum constants or object generics - zero-based indexes are the enum values, strings are the names
KeyType union.Maybe[*TypeDef] // Map key type
ValueType union.Maybe[*TypeDef] // Array element type, Enum base type, list element type, map value type, maybe type, object base type, or set element type
}
TypeDef is a type definition
func OfArrayType ¶
func OfArrayType( elementTyp *TypeDef, bounds []uint, access ...AccessLevel, ) *TypeDef
OfArrayType constructs an array TypeDef
func OfEnumType ¶
func OfEnumType( name string, baseType *TypeDef, constants []string, access ...AccessLevel, ) *TypeDef
OfEnumType constructs an enum TypeDef
func OfJSONType ¶
func OfJSONType(access ...AccessLevel) *TypeDef
OfJSONType constructs a JSON TypeDef
func OfListType ¶
func OfListType( elementType *TypeDef, access ...AccessLevel, ) *TypeDef
OfListType constructs a list TypeDef
func OfMapType ¶
func OfMapType( keyType *TypeDef, valueType *TypeDef, access ...AccessLevel, ) *TypeDef
OfMapType constructs a map TypeDef
func OfMaybeType ¶
func OfMaybeType( elementType *TypeDef, access ...AccessLevel, ) *TypeDef
OfMaybeType constructs a Maybe TypeDef
func OfObjectType ¶
func OfObjectType( baseType *TypeDef, name string, generics []string, access ...AccessLevel, ) *TypeDef
OfObjectType constructs an Object TypeDef
func OfScalarType ¶
func OfScalarType( typ ScalarType, access ...AccessLevel, ) *TypeDef
OfScalarType constructs a scalar TypeDef
func OfSetType ¶
func OfSetType( elementType *TypeDef, access ...AccessLevel, ) *TypeDef
OfSetType constructs a set TypeDef
type Types ¶
type Types interface {
Type | ScalarType | AggregateType
}
Types is a constraint on Type and all known subtypes of it
type UnaryOperator ¶
type UnaryOperator Operator
UnaryOperator is a non-boolean operator with one argument
const ( // Increment/decrement Inc UnaryOperator = iota Dec // Negation Neg // Bitwise not BitNot )
type Val ¶
type Val struct {
Access union.Maybe[AccessLevel] // Level of access
Kind ValKind // The kind of value
Typ *TypeDef // The TypeDef
Value string // The literal value or variable name
}
Val represents a value of some type It is a (non-)constant variable or literal