Documentation
¶
Overview ¶
Package utl provides helpers to extend the xelf language and some common library function specs.
Index ¶
- Variables
- func ApplyDelta(o lit.Keyer, d *lit.Dict) error
- func DayEnd(t time.Time) time.Time
- func DayStart(t time.Time) time.Time
- func DynPrepper(p *exp.Prog, env exp.Env, n *exp.Tag) (lit.Lit, error)
- func ListPrepper(p *exp.Prog, env exp.Env, n *exp.Tag) (lit.Lit, error)
- func MergeDeltas(a, b *lit.Dict) error
- func MustReflectFmap(m Fmap) exp.LookupFunc
- func NewDelta(a, b lit.Record) (*lit.Dict, error)
- func ParseTags(p *exp.Prog, env exp.Env, els []exp.El, v interface{}, rules TagRules) error
- func PathSetter(n Node, key string, el lit.Lit) error
- func ReflectFmap(m Fmap) (exp.LookupFunc, error)
- func ReflectFunc(name string, val interface{}, names ...string) (*exp.Spec, error)
- type Fmap
- type IdxKeyer
- type KeyPrepper
- type KeyRule
- type KeySetter
- type LazyFmap
- type Node
- type NodeResolver
- type NodeRules
- type ReflectBody
- type TagRules
Constants ¶
This section is empty.
Variables ¶
var StrLib = Lazy(Fmap{ "str_contains": strings.Contains, "str_contains_any": strings.ContainsAny, "str_prefix": strings.HasPrefix, "str_suffix": strings.HasSuffix, "str_upper": strings.ToUpper, "str_lower": strings.ToLower, "str_trim": strings.TrimSpace, })
var TimeLib = Lazy(Fmap{ "time_sub": time.Time.Sub, "time_add_date": time.Time.AddDate, "time_add_days": timeAddDays, "time_year": time.Time.Year, "time_month": time.Time.Month, "time_weekday": time.Time.Weekday, "time_yearday": time.Time.YearDay, "time_format": time.Time.Format, "time_date_long": timeDateLong, "time_day_start": DayStart, "time_day_end": DayEnd, })
var ZeroKeyer = OffsetKeyer(0)
ZeroKeyer is an index keyer without offset.
Functions ¶
func DynPrepper ¶
DynPrepper resolves args using c and env and returns a literal or an error. Empty args return a untyped null literal. Multiple args are resolved as dyn expression.
func ListPrepper ¶
ListPrepper resolves args using c and env and returns a list or an error.
func MergeDeltas ¶
func MustReflectFmap ¶
func MustReflectFmap(m Fmap) exp.LookupFunc
MustReflectFmap reflects m and returns a lookup function or panics.
func PathSetter ¶
PathSetter sets el to n using key as path or returns an error.
func ReflectFmap ¶
func ReflectFmap(m Fmap) (exp.LookupFunc, error)
ReflectFmap reflects m and returns a lookup function or an error.
Types ¶
type Fmap ¶
type Fmap = map[string]interface{}
Fmap is a go template.FuncMap compatible map type alias
type IdxKeyer ¶
IdxKeyer returns a key for an unnamed tag at idx.
func OffsetKeyer ¶
OffsetKeyer returns an index keyer that looks up a field at the index plus the offset.
type KeyPrepper ¶
KeyPrepper resolves els and returns a literal for key or an error.
func BitsPrepper ¶
func BitsPrepper(consts []typ.Const) KeyPrepper
BitsPrepper returns a key prepper that tries to resolve a bits constant.
type KeyRule ¶
type KeyRule struct {
KeyPrepper
KeySetter
}
KeyRule is a configurable helper for assigning tags to nodes.
type KeySetter ¶
KeySetter sets l to node with key or returns an error.
func BitsSetter ¶
BitsSetter returns a key setter that tries to add to a node bits field with key.
func ExtraMapSetter ¶
ExtraMapSetter returns a key setter that tries to add to a node map field with key.
type LazyFmap ¶
type LazyFmap struct {
// contains filtered or unexported fields
}
LazyFmap reflects a fmap on first use and is protected by a mutex
func (*LazyFmap) Lookup ¶
func (m *LazyFmap) Lookup() exp.LookupFunc
Lookup returns the same fmap lookup function, it is created once on the first call
type NodeResolver ¶
type NodeResolver struct {
NodeRules
// contains filtered or unexported fields
}
NodeResolver is a form resolver that returns nodes of a specific type.
func NewNodeResolver ¶
func NewNodeResolver(rules NodeRules, v interface{}) *NodeResolver
NewNodeResolver returns a node resolver using rules and returning new nodes based on v.
type ReflectBody ¶
type ReflectBody struct {
// contains filtered or unexported fields
}
ReflectBody is a function resolver wrapping a reflected go function.
type TagRules ¶
type TagRules struct {
// Rules holds optional per key rules
Rules map[string]KeyRule
// IdxKeyer will map unnamed tags to a key, when null unnamed tags result in an error
IdxKeyer
// KeyRule holds optional default rules.
// If neither specific nor default rules are found DynPrepper and PathSetter are used.
KeyRule
}
TagRules is a configurable helper for assigning tags to nodes.
func (*TagRules) Resolve ¶
Resolve resolves tags using c and env and assigns them to node or returns an error
func (*TagRules) ResolveTag ¶
func (tr *TagRules) ResolveTag(p *exp.Prog, env exp.Env, tag *exp.Tag, idx int, node Node) (err error)
ResolveTag resolves tag using c and env and assigns them to node or returns an error
func (TagRules) WithOffset ¶
WithOffset return a with an offset keyer.