acal

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownValueName = "Unknown"
)

Variables

View Source
var AppendTags = func(t ITagger, tags ...Tag) Tags {
	if t == nil {
		return nil
	}

	curTags := t.GetTags()
	if curTags == nil {
		return tags
	}

	return curTags.AddTags(tags...)
}

AppendTags appends the provided Tag to collection of tags of the given ITagger.

View Source
var PerformStandardValueExtraction = func(v Value, cache IValueCache) IValueCache {
	if IsNilValue(v) {
		return cache
	}

	if HasIdentity(v) {
		if !cache.Take(v) {
			return cache
		}
	}

	if c, ok := v.(StaticConditionalValue); ok && c.IsConditional() {
		c.GetCondition().criteria.ExtractValues(cache)
	}

	if t, ok := v.(ITagger); ok {
		for _, tag := range t.GetTags() {
			if tag.aVal != nil {
				tag.aVal.ExtractValues(cache)
			}
		}
	}

	fp, ok := v.(formulaProvider)
	if !ok || !fp.HasFormula() {
		return cache
	}

	formula := fp.GetFormulaFn()()

	for _, operand := range formula.GetOperands() {
		if ev, ok := operand.(extractable); ok {
			ev.ExtractValues(cache)
		}
	}

	return cache
}

PerformStandardValueExtraction extracts all Value that were used to calculate the given value and put them in the provided cache.

Functions

func ApplyStaticCondition

func ApplyStaticCondition(criteria TypedValue[bool], values ...StaticConditionalValue)

ApplyStaticCondition creates a Condition and applies it on all given StaticConditionalValue.

func Describe

func Describe(v Value) string

Describe returns a full description of the given Value, including its identity and current value in string format.

func DescribeValueAsFormula

func DescribeValueAsFormula[T any](v TypedValue[T]) func() *SyntaxNode

DescribeValueAsFormula returns a full description of the given Value, in the form of a formula.

func ExtractTypedValue

func ExtractTypedValue[T any](tv TypedValue[T]) T

ExtractTypedValue returns the typed value the given TypedValue contains.

func HasIdentity

func HasIdentity(v Value) bool

HasIdentity returns whether the given Value is anchored.

func Identify

func Identify(v Value) string

Identify returns the identity of the given Value, which is its alias if not nil. Otherwise, the result should be its name.

func IsNilValue

func IsNilValue(v Value) bool

IsNilValue returns whether the given Value is nil.

func MarshalJSON

func MarshalJSON(values ...Value) ([]byte, error)

MarshalJSON puts the provided Value and all other Value that were used to calculate the given Value into a map and returns a JSON encoding of this map.

func MarshalJSONByFields

func MarshalJSONByFields(data any) ([]byte, error)

MarshalJSONByFields will execute MarshalJSON on the provided data if it's a Value. Otherwise, each exported field of the provided data will be put into a map. If such field is a Value, all other Value that were used to calculate this field will also be added to this map. Finally, a JSON encoding of this map will be returned.

If the alias of any Value happens to collide with the name of non-Value fields, such Value will be de-duplicated in the JSON map by appending a suffix to the alias of all duplicates. Format for alias of de-duplicated variables: <name_of_variable>.<count>. - count starts from 2 - example: duplicate.2, duplicate3.2

func Stringify

func Stringify(v Value) string

Stringify returns the value this Value contains as a string.

func ToString

func ToString(aVal ...Value) string

ToString returns the JSON structure representing the given Value as a string

Types

type CloseIfFunc

type CloseIfFunc func()

CloseIfFunc is to be called when an if clause ends so that progressive variables can record the close if stage index.

var DoNothingCloseIfFunc CloseIfFunc = func() {}

DoNothingCloseIfFunc is a CloseIfFunc that does nothing.

func ApplyProgressiveCondition

func ApplyProgressiveCondition(criteria TypedValue[bool], values ...ProgressiveConditionalValue) CloseIfFunc

ApplyProgressiveCondition applies the provided Condition on all given ProgressiveConditionalValue and returns a single CloseIfFunc to close all conditions at once.

type Condition

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

Condition represents an if clause in a calculation algorithm.

func NewCondition

func NewCondition(criteria TypedValue[bool]) *Condition

NewCondition returns a new Condition with the provided fields.

func NewProgressiveCondition

func NewProgressiveCondition(criteria TypedValue[bool], prevCondition *Condition, openIfStageIdx int) *Condition

NewProgressiveCondition returns a new Condition with the provided fields.

func (*Condition) MarshalJSON

func (c *Condition) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this Condition.

type Constant

type Constant[T any] struct {
	// contains filtered or unexported fields
}

Constant ...

func NewConstant

func NewConstant[T any](value T) *Constant[T]

NewConstant ...

func NewConstantWithFormat

func NewConstantWithFormat[T any](value T, formatFn func(T) string) *Constant[T]

NewConstantWithFormat ...

func (*Constant[T]) ExtractValues

func (c *Constant[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues does nothing for Constant as it's a constant.

func (*Constant) GetAlias

func (v *Constant) GetAlias() string

GetAlias ...

func (*Constant) GetFormatFn

func (f *Constant) GetFormatFn() func(T) string

func (*Constant[T]) GetFormulaFn

func (c *Constant[T]) GetFormulaFn() func() *SyntaxNode

GetFormulaFn returns the function to build a formula of this Constant.

func (*Constant) GetName

func (v *Constant) GetName() string

GetName ...

func (*Constant[T]) GetTypedValue

func (c *Constant[T]) GetTypedValue() T

GetTypedValue returns the typed value this Constant contains.

func (*Constant[T]) GetValue

func (c *Constant[T]) GetValue() any

GetValue returns the untyped value this Constant contains.

func (*Constant[T]) HasFormula

func (c *Constant[T]) HasFormula() bool

HasFormula returns whether this Constant has a formula.

func (*Constant) HasIdentity

func (v *Constant) HasIdentity() bool

HasIdentity ...

func (*Constant) Identify

func (v *Constant) Identify() string

Identify ...

func (*Constant[T]) IsNil

func (c *Constant[T]) IsNil() bool

IsNil returns whether this Constant is nil.

func (*Constant[T]) SetAlias

func (c *Constant[T]) SetAlias(alias string)

SetAlias does nothing for Constant as it's a constant.

func (*Constant[T]) Stringify

func (c *Constant[T]) Stringify() string

Stringify returns the value this Constant contains as a string.

func (*Constant[T]) ToSyntaxOperand

func (c *Constant[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Constant.

func (*Constant) WithFormatFn

func (f *Constant) WithFormatFn(formatFn func(T) string)

type ICondOps

type ICondOps interface {
	// ApplyStaticCondition ...
	ApplyStaticCondition(criteria TypedValue[bool], values ...StaticConditionalValue)
	// ApplyProgressiveCondition ...
	ApplyProgressiveCondition(criteria TypedValue[bool], values ...ProgressiveConditionalValue) CloseIfFunc
}

ICondOps ...

type IMarshalOps

type IMarshalOps interface {
	// MarshalJSON ...
	MarshalJSON(values ...Value) ([]byte, error)
	// MarshalJSONByFields ...
	MarshalJSONByFields(data any) ([]byte, error)
}

IMarshalOps ...

type ITagger

type ITagger interface {
	// Tag append the given Tag to the existing tags of this ITagger.
	Tag(...Tag)
	// GetTags returns the current tags of this ITagger.
	GetTags() Tags
}

ITagger represents any struct that can have tags attached to it.

type IValueCache

type IValueCache interface {
	// Take accepts a Value to put into ValueCache. It will automatically de-duplicate
	// variables under the same name by giving duplicates an alias if it doesn't have
	// one already. The return value indicates whether the given value was accepted
	// into the cache.
	//
	// Format for alias of de-duplicated variables: <name_of_variable><count>.
	// - count starts from 2
	// - example: duplicate2, duplicate3
	Take(v Value) bool
	// Flatten returns a map of calculated variables that is ready for marshalling into
	// JSON. Variables with colliding alias will be de-duplicated by appending a count
	// suffix to the alias of all duplicates.
	//
	// Format for alias of de-duplicated variables: <name_of_variable>_<count>.
	// - count starts from 2
	// - example: duplicate_2, duplicate3_2
	Flatten() map[string]Value
}

IValueCache keeps extracted values during marshalling so that we can build a complete JSON structure containing all calculated variables from a small set of input variables.

func NewValueCache

func NewValueCache() IValueCache

NewValueCache ...

type IValueOps

type IValueOps interface {
	// IsNilValue ...
	IsNilValue(v Value) bool
	// HasIdentity ...
	HasIdentity(v Value) bool
	// Identify ...
	Identify(v Value) string
	// Stringify ...
	Stringify(v Value) string
	// Describe ...
	Describe(v Value) string
	// DescribeValueAsFormula ...
	DescribeValueAsFormula(v Value) func() *SyntaxNode
}

IValueOps ...

type Local

type Local[T any] struct {
	// contains filtered or unexported fields
}

Local ...

func NewLocal

func NewLocal[T any](name string, original TypedValue[T]) *Local[T]

NewLocal ...

func (*Local) AddCondition

func (c *Local) AddCondition(condition *Condition)

AddCondition attaches the given Condition to this Simple.

func (*Local[T]) DoAnchor

func (l *Local[T]) DoAnchor(name string) *Simple[T]

DoAnchor returns a new Simple initialized to the value of this Local and anchored with the given name.

func (*Local[T]) ExtractValues

func (l *Local[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues extracts this Local and all Value that were used to calculate it.

func (*Local) GetAlias

func (v *Local) GetAlias() string

GetAlias ...

func (*Local) GetCondition

func (c *Local) GetCondition() *Condition

GetCondition returns the Condition attached to this Simple.

func (*Local) GetFormatFn

func (f *Local) GetFormatFn() func(T) string

func (*Local) GetName

func (v *Local) GetName() string

GetName ...

func (*Local) GetTags

func (t *Local) GetTags() Tags

GetTags returns the current tags of this tagger.

func (*Local[T]) GetTypedValue

func (l *Local[T]) GetTypedValue() T

GetTypedValue returns the typed value this Local contains.

func (*Local[T]) GetValue

func (l *Local[T]) GetValue() any

GetValue returns the untyped value this Local contains.

func (*Local) HasIdentity

func (v *Local) HasIdentity() bool

HasIdentity ...

func (*Local) Identify

func (v *Local) Identify() string

Identify ...

func (*Local) IsConditional

func (c *Local) IsConditional() bool

IsConditional returns whether a Condition is attached to this iStaticConditioner.

func (*Local[T]) IsNil

func (l *Local[T]) IsNil() bool

IsNil returns whether this Local is nil.

func (*Local[T]) MarshalJSON

func (l *Local[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this Local.

func (*Local) SetAlias

func (v *Local) SetAlias(alias string)

SetAlias ...

func (*Local[T]) Stringify

func (l *Local[T]) Stringify() string

Stringify returns the value this Local contains as a string.

func (*Local) Tag

func (t *Local) Tag(tags ...Tag)

Tag append the given Tag to the existing tags of this tagger.

func (*Local[T]) ToSyntaxOperand

func (l *Local[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Local.

func (*Local) WithFormatFn

func (f *Local) WithFormatFn(formatFn func(T) string)

type MockICondOps

type MockICondOps struct {
	mock.Mock
}

MockICondOps is an autogenerated mock type for the ICondOps type

func NewMockICondOps

func NewMockICondOps(t mockConstructorTestingTNewMockICondOps) *MockICondOps

NewMockICondOps creates a new instance of MockICondOps. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockICondOps) ApplyProgressiveCondition

func (_m *MockICondOps) ApplyProgressiveCondition(criteria TypedValue[bool], values ...ProgressiveConditionalValue) CloseIfFunc

ApplyProgressiveCondition provides a mock function with given fields: criteria, values

func (*MockICondOps) ApplyStaticCondition

func (_m *MockICondOps) ApplyStaticCondition(criteria TypedValue[bool], values ...StaticConditionalValue)

ApplyStaticCondition provides a mock function with given fields: criteria, values

type MockIMarshalOps

type MockIMarshalOps struct {
	mock.Mock
}

MockIMarshalOps is an autogenerated mock type for the IMarshalOps type

func NewMockIMarshalOps

func NewMockIMarshalOps(t mockConstructorTestingTNewMockIMarshalOps) *MockIMarshalOps

NewMockIMarshalOps creates a new instance of MockIMarshalOps. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockIMarshalOps) MarshalJSON

func (_m *MockIMarshalOps) MarshalJSON(values ...Value) ([]byte, error)

MarshalJSON provides a mock function with given fields: values

func (*MockIMarshalOps) MarshalJSONByFields

func (_m *MockIMarshalOps) MarshalJSONByFields(data interface{}) ([]byte, error)

MarshalJSONByFields provides a mock function with given fields: data

type MockITagger

type MockITagger struct {
	mock.Mock
}

MockITagger is an autogenerated mock type for the ITagger type

func NewMockITagger

func NewMockITagger(t mockConstructorTestingTNewMockITagger) *MockITagger

NewMockITagger creates a new instance of MockITagger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockITagger) GetTags

func (_m *MockITagger) GetTags() Tags

GetTags provides a mock function with given fields:

func (*MockITagger) Tag

func (_m *MockITagger) Tag(_a0 ...Tag)

Tag provides a mock function with given fields: _a0

type MockIValueCache

type MockIValueCache struct {
	mock.Mock
}

MockIValueCache is an autogenerated mock type for the IValueCache type

func NewMockIValueCache

func NewMockIValueCache(t mockConstructorTestingTNewMockIValueCache) *MockIValueCache

NewMockIValueCache creates a new instance of MockIValueCache. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockIValueCache) Flatten

func (_m *MockIValueCache) Flatten() map[string]Value

Flatten provides a mock function with given fields:

func (*MockIValueCache) Take

func (_m *MockIValueCache) Take(v Value) bool

Take provides a mock function with given fields: v

type MockIValueOps

type MockIValueOps struct {
	mock.Mock
}

MockIValueOps is an autogenerated mock type for the IValueOps type

func NewMockIValueOps

func NewMockIValueOps(t mockConstructorTestingTNewMockIValueOps) *MockIValueOps

NewMockIValueOps creates a new instance of MockIValueOps. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockIValueOps) Describe

func (_m *MockIValueOps) Describe(v Value) string

Describe provides a mock function with given fields: v

func (*MockIValueOps) DescribeValueAsFormula

func (_m *MockIValueOps) DescribeValueAsFormula(v Value) func() *SyntaxNode

DescribeValueAsFormula provides a mock function with given fields: v

func (*MockIValueOps) HasIdentity

func (_m *MockIValueOps) HasIdentity(v Value) bool

HasIdentity provides a mock function with given fields: v

func (*MockIValueOps) Identify

func (_m *MockIValueOps) Identify(v Value) string

Identify provides a mock function with given fields: v

func (*MockIValueOps) IsNilValue

func (_m *MockIValueOps) IsNilValue(v Value) bool

IsNilValue provides a mock function with given fields: v

func (*MockIValueOps) Stringify

func (_m *MockIValueOps) Stringify(v Value) string

Stringify provides a mock function with given fields: v

type MockProgressiveConditionalValue

type MockProgressiveConditionalValue struct {
	mock.Mock
}

MockProgressiveConditionalValue is an autogenerated mock type for the ProgressiveConditionalValue type

func NewMockProgressiveConditionalValue

func NewMockProgressiveConditionalValue(t mockConstructorTestingTNewMockProgressiveConditionalValue) *MockProgressiveConditionalValue

NewMockProgressiveConditionalValue creates a new instance of MockProgressiveConditionalValue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockProgressiveConditionalValue) AddCondition

AddCondition provides a mock function with given fields: _a0

type MockStaticConditionalValue

type MockStaticConditionalValue struct {
	mock.Mock
}

MockStaticConditionalValue is an autogenerated mock type for the StaticConditionalValue type

func NewMockStaticConditionalValue

func NewMockStaticConditionalValue(t mockConstructorTestingTNewMockStaticConditionalValue) *MockStaticConditionalValue

NewMockStaticConditionalValue creates a new instance of MockStaticConditionalValue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockStaticConditionalValue) AddCondition

func (_m *MockStaticConditionalValue) AddCondition(_a0 *Condition)

AddCondition provides a mock function with given fields: _a0

func (*MockStaticConditionalValue) GetCondition

func (_m *MockStaticConditionalValue) GetCondition() *Condition

GetCondition provides a mock function with given fields:

func (*MockStaticConditionalValue) IsConditional

func (_m *MockStaticConditionalValue) IsConditional() bool

IsConditional provides a mock function with given fields:

type MockTypedValue

type MockTypedValue[T interface{}] struct {
	mock.Mock
}

MockTypedValue is an autogenerated mock type for the TypedValue type

func NewMockTypedValue

func NewMockTypedValue[T interface{}](t mockConstructorTestingTNewMockTypedValue) *MockTypedValue[T]

NewMockTypedValue creates a new instance of MockTypedValue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockTypedValue[T]) ExtractValues

func (_m *MockTypedValue[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues provides a mock function with given fields: cache

func (*MockTypedValue[T]) GetAlias

func (_m *MockTypedValue[T]) GetAlias() string

GetAlias provides a mock function with given fields:

func (*MockTypedValue[T]) GetName

func (_m *MockTypedValue[T]) GetName() string

GetName provides a mock function with given fields:

func (*MockTypedValue[T]) GetTypedValue

func (_m *MockTypedValue[T]) GetTypedValue() T

GetTypedValue provides a mock function with given fields:

func (*MockTypedValue[T]) GetValue

func (_m *MockTypedValue[T]) GetValue() interface{}

GetValue provides a mock function with given fields:

func (*MockTypedValue[T]) HasIdentity

func (_m *MockTypedValue[T]) HasIdentity() bool

HasIdentity provides a mock function with given fields:

func (*MockTypedValue[T]) Identify

func (_m *MockTypedValue[T]) Identify() string

Identify provides a mock function with given fields:

func (*MockTypedValue[T]) IsNil

func (_m *MockTypedValue[T]) IsNil() bool

IsNil provides a mock function with given fields:

func (*MockTypedValue[T]) SetAlias

func (_m *MockTypedValue[T]) SetAlias(_a0 string)

SetAlias provides a mock function with given fields: _a0

func (*MockTypedValue[T]) Stringify

func (_m *MockTypedValue[T]) Stringify() string

Stringify provides a mock function with given fields:

func (*MockTypedValue[T]) ToSyntaxOperand

func (_m *MockTypedValue[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand provides a mock function with given fields: nextOp

type MockValue

type MockValue struct {
	mock.Mock
}

MockValue is an autogenerated mock type for the Value type

func NewMockValue

func NewMockValue(t mockConstructorTestingTNewMockValue) *MockValue

NewMockValue creates a new instance of MockValue. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockValue) ExtractValues

func (_m *MockValue) ExtractValues(cache IValueCache) IValueCache

ExtractValues provides a mock function with given fields: cache

func (*MockValue) GetAlias

func (_m *MockValue) GetAlias() string

GetAlias provides a mock function with given fields:

func (*MockValue) GetName

func (_m *MockValue) GetName() string

GetName provides a mock function with given fields:

func (*MockValue) GetValue

func (_m *MockValue) GetValue() interface{}

GetValue provides a mock function with given fields:

func (*MockValue) HasIdentity

func (_m *MockValue) HasIdentity() bool

HasIdentity provides a mock function with given fields:

func (*MockValue) Identify

func (_m *MockValue) Identify() string

Identify provides a mock function with given fields:

func (*MockValue) IsNil

func (_m *MockValue) IsNil() bool

IsNil provides a mock function with given fields:

func (*MockValue) SetAlias

func (_m *MockValue) SetAlias(_a0 string)

SetAlias provides a mock function with given fields: _a0

func (*MockValue) Stringify

func (_m *MockValue) Stringify() string

Stringify provides a mock function with given fields:

func (*MockValue) ToSyntaxOperand

func (_m *MockValue) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand provides a mock function with given fields: nextOp

type Op

type Op int

Op represents an operation that can be performed on Value.

const (
	// OpTransparent is a transparent op that does not show up in formulas.
	OpTransparent Op = -1
)

func (Op) IsTransparent

func (o Op) IsTransparent() bool

IsTransparent returns whether this Op is the special OpTransparent.

type OpCategory

type OpCategory int

OpCategory represents the kind of operation being performed, which can decide how such operation should be displayed in a formula.

const (
	// OpCategoryFunctionCall represents an operation that looks like a function call.
	OpCategoryFunctionCall OpCategory = iota
	// OpCategoryTwoValMiddleOp represents an operation with the operator lies in the middle of 2 operands.
	OpCategoryTwoValMiddleOp
	// OpCategoryAssignVariable represents an assign operation where a variable is assigned as the value of another variable.
	OpCategoryAssignVariable
	// OpCategoryAssignStatic represents an assign operation where a static value is assigned as the value of a variable.
	OpCategoryAssignStatic
)

type Progressive

type Progressive[T any] struct {
	// contains filtered or unexported fields
}

Progressive ...

func NewProgressive

func NewProgressive[T any](name string) *Progressive[T]

NewProgressive ...

func (*Progressive[T]) AddCondition

func (p *Progressive[T]) AddCondition(criteria TypedValue[bool]) CloseIfFunc

AddCondition attaches the given condition to this Progressive, returning a CloseIfFunc that must be triggered when an if clause ends so that the framework can record at which stage this condition ends.

func (*Progressive[T]) AsTag

func (p *Progressive[T]) AsTag() Tag

AsTag returns a Tag represented by this Progressive.

func (*Progressive[T]) DoAnchor

func (p *Progressive[T]) DoAnchor(name string) *Simple[T]

DoAnchor returns a new Simple initialized to the current value of this Progressive and anchored with the given name.

func (*Progressive[T]) ExtractValues

func (p *Progressive[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues extracts this Progressive and all Value that were used to calculate it.

func (*Progressive) GetAlias

func (v *Progressive) GetAlias() string

GetAlias ...

func (*Progressive) GetFormatFn

func (f *Progressive) GetFormatFn() func(T) string

func (*Progressive) GetName

func (v *Progressive) GetName() string

GetName ...

func (*Progressive) GetTags

func (t *Progressive) GetTags() Tags

GetTags returns the current tags of this tagger.

func (*Progressive[T]) GetTypedValue

func (p *Progressive[T]) GetTypedValue() T

GetTypedValue returns the typed value this Progressive contains.

func (*Progressive[T]) GetValue

func (p *Progressive[T]) GetValue() any

GetValue returns the untyped value this Progressive contains.

func (*Progressive) HasIdentity

func (v *Progressive) HasIdentity() bool

HasIdentity ...

func (*Progressive) Identify

func (v *Progressive) Identify() string

Identify ...

func (*Progressive[T]) IsNil

func (p *Progressive[T]) IsNil() bool

IsNil returns whether this Progressive is nil.

func (*Progressive[T]) MarshalJSON

func (p *Progressive[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this FloatP

func (*Progressive) SetAlias

func (v *Progressive) SetAlias(alias string)

SetAlias ...

func (*Progressive[T]) Stringify

func (p *Progressive[T]) Stringify() string

Stringify returns the value this Progressive contains as a string.

func (*Progressive) Tag

func (t *Progressive) Tag(tags ...Tag)

Tag append the given Tag to the existing tags of this tagger.

func (*Progressive[T]) ToSyntaxOperand

func (p *Progressive[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Progressive.

func (*Progressive[T]) Update

func (p *Progressive[T]) Update(value TypedValue[T])

Update adds a new Stage to this Progressive to record its new value.

func (*Progressive) WithFormatFn

func (f *Progressive) WithFormatFn(formatFn func(T) string)

type ProgressiveConditionalValue

type ProgressiveConditionalValue interface {
	// AddCondition attaches the given Condition to this ProgressiveConditionalValue
	// and returns a CloseIfFunc to close the Condition.
	AddCondition(TypedValue[bool]) CloseIfFunc
}

ProgressiveConditionalValue needs to be implemented by progressive Value that might involve conditional calculation.

type Remote

type Remote[T any] struct {
	// contains filtered or unexported fields
}

Remote ...

func NewRemote

func NewRemote[T any](name string, value T, remoteFieldName string, remoteLogKey string) *Remote[T]

NewRemote ...

func (*Remote) AddCondition

func (c *Remote) AddCondition(condition *Condition)

AddCondition attaches the given Condition to this Simple.

func (*Remote[T]) DoAnchor

func (r *Remote[T]) DoAnchor(name string) *Simple[T]

DoAnchor returns a new Simple initialized to the value of this Remote and anchored with the given name.

func (*Remote[T]) ExtractValues

func (r *Remote[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues extracts this Remote and all Value that were used to calculate it.

func (*Remote) GetAlias

func (v *Remote) GetAlias() string

GetAlias ...

func (*Remote) GetCondition

func (c *Remote) GetCondition() *Condition

GetCondition returns the Condition attached to this Simple.

func (*Remote) GetFormatFn

func (f *Remote) GetFormatFn() func(T) string

func (*Remote) GetName

func (v *Remote) GetName() string

GetName ...

func (*Remote) GetTags

func (t *Remote) GetTags() Tags

GetTags returns the current tags of this tagger.

func (*Remote[T]) GetTypedValue

func (r *Remote[T]) GetTypedValue() T

GetTypedValue returns the typed value this Remote contains.

func (*Remote[T]) GetValue

func (r *Remote[T]) GetValue() any

GetValue returns the untyped value this Remote contains.

func (*Remote) HasIdentity

func (v *Remote) HasIdentity() bool

HasIdentity ...

func (*Remote) Identify

func (v *Remote) Identify() string

Identify ...

func (*Remote) IsConditional

func (c *Remote) IsConditional() bool

IsConditional returns whether a Condition is attached to this iStaticConditioner.

func (*Remote[T]) IsNil

func (r *Remote[T]) IsNil() bool

IsNil returns whether this Remote is nil.

func (*Remote[T]) MarshalJSON

func (r *Remote[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this Remote.

func (*Remote) SetAlias

func (v *Remote) SetAlias(alias string)

SetAlias ...

func (*Remote[T]) Stringify

func (r *Remote[T]) Stringify() string

Stringify returns the value this Remote contains as a string.

func (*Remote) Tag

func (t *Remote) Tag(tags ...Tag)

Tag append the given Tag to the existing tags of this tagger.

func (*Remote[T]) ToSyntaxOperand

func (r *Remote[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Remote.

func (*Remote) WithFormatFn

func (f *Remote) WithFormatFn(formatFn func(T) string)

type Simple

type Simple[T any] struct {
	// contains filtered or unexported fields
}

Simple ...

func NewSimple

func NewSimple[T any](name string, value T) *Simple[T]

NewSimple ...

func NewSimpleFrom

func NewSimpleFrom[T any](value TypedValue[T]) *Simple[T]

NewSimpleFrom returns a new Simple using the given value as formula.

func NewSimpleWithFormula

func NewSimpleWithFormula[T any](value T, formulaFn func() *SyntaxNode) *Simple[T]

NewSimpleWithFormula returns a new Simple with the given value and formula.

func ZeroSimple

func ZeroSimple[T any](name string) *Simple[T]

ZeroSimple ...

func (*Simple) AddCondition

func (c *Simple) AddCondition(condition *Condition)

AddCondition attaches the given Condition to this Simple.

func (*Simple[T]) DoAnchor

func (s *Simple[T]) DoAnchor(name string) (*Simple[T], bool)

DoAnchor updates the name of this Simple to the provided string.

func (*Simple[T]) ExtractValues

func (s *Simple[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues extracts this Simple and all Value that were used to calculate it.

func (*Simple[T]) From

func (s *Simple[T]) From(source Source)

From updates the source of this Simple to the provided Source.

func (*Simple) GetAlias

func (v *Simple) GetAlias() string

GetAlias ...

func (*Simple) GetCondition

func (c *Simple) GetCondition() *Condition

GetCondition returns the Condition attached to this Simple.

func (*Simple) GetFormatFn

func (f *Simple) GetFormatFn() func(T) string

func (*Simple[T]) GetFormulaFn

func (s *Simple[T]) GetFormulaFn() func() *SyntaxNode

GetFormulaFn returns the function to build a formula of this Simple.

func (*Simple) GetName

func (v *Simple) GetName() string

GetName ...

func (*Simple[T]) GetSource

func (s *Simple[T]) GetSource() Source

GetSource returns the source of this Simple.

func (*Simple) GetTags

func (t *Simple) GetTags() Tags

GetTags returns the current tags of this tagger.

func (*Simple[T]) GetTypedValue

func (s *Simple[T]) GetTypedValue() T

GetTypedValue returns the typed value this Simple contains.

func (*Simple[T]) GetValue

func (s *Simple[T]) GetValue() any

GetValue returns the untyped value this Simple contains.

func (*Simple[T]) HasFormula

func (s *Simple[T]) HasFormula() bool

HasFormula returns whether this Simple has a formula.

func (*Simple) HasIdentity

func (v *Simple) HasIdentity() bool

HasIdentity ...

func (*Simple) Identify

func (v *Simple) Identify() string

Identify ...

func (*Simple) IsConditional

func (c *Simple) IsConditional() bool

IsConditional returns whether a Condition is attached to this iStaticConditioner.

func (*Simple[T]) IsNil

func (s *Simple[T]) IsNil() bool

IsNil returns whether this Simple is nil.

func (*Simple[T]) MarshalJSON

func (s *Simple[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this Simple.

func (*Simple) SetAlias

func (v *Simple) SetAlias(alias string)

SetAlias ...

func (*Simple[T]) Stringify

func (s *Simple[T]) Stringify() string

Stringify returns the value this Simple contains as a string.

func (*Simple) Tag

func (t *Simple) Tag(tags ...Tag)

Tag append the given Tag to the existing tags of this tagger.

func (*Simple[T]) ToSyntaxOperand

func (s *Simple[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Simple.

func (*Simple) WithFormatFn

func (f *Simple) WithFormatFn(formatFn func(T) string)

type Source

type Source string

Source represents where a Value comes from.

const (

	// These are the common sources that the framework provides for
	// all clients to share.
	SourceRequest  Source = "request"
	SourceHardcode Source = "hardcode"
	SourceUnknown  Source = "unknown"
	SourceLogic    Source = "logic"
)

func (Source) Apply

func (s Source) Apply(targets ...sourcer)

Apply applies this Source on all given sourcer.

func (Source) String

func (s Source) String() string

String returns the string representation of this Source.

type Stage

type Stage[T any] struct {
	// contains filtered or unexported fields
}

Stage ...

func (*Stage[T]) ExtractValues

func (s *Stage[T]) ExtractValues(cache IValueCache) IValueCache

ExtractValues extracts this Stage and all Value that were used to calculate it.

func (*Stage[T]) GetAlias

func (s *Stage[T]) GetAlias() string

GetAlias returns the alias of the underlying Progressive.

func (*Stage[T]) GetName

func (s *Stage[T]) GetName() string

GetName returns the name of the underlying Progressive.

func (*Stage[T]) GetTypedValue

func (s *Stage[T]) GetTypedValue() T

GetTypedValue returns the typed value this Stage contains.

func (*Stage[T]) GetValue

func (s *Stage[T]) GetValue() any

GetValue returns the untyped value this Stage contains.

func (*Stage[T]) HasIdentity

func (s *Stage[T]) HasIdentity() bool

HasIdentity returns whether the underlying Progressive was given an identity.

func (*Stage[T]) Identify

func (s *Stage[T]) Identify() string

Identify returns the identity that was given to the underlying Progressive.

func (*Stage[T]) IsNil

func (s *Stage[T]) IsNil() bool

IsNil returns whether this Stage is nil.

func (*Stage[T]) SetAlias

func (s *Stage[T]) SetAlias(alias string)

SetAlias updates the alias of the underlying Progressive to the provided string.

func (*Stage[T]) Stringify

func (s *Stage[T]) Stringify() string

Stringify returns the value this Stage contains as a string.

func (*Stage[T]) ToSyntaxOperand

func (s *Stage[T]) ToSyntaxOperand(nextOp Op) *SyntaxOperand

ToSyntaxOperand returns the SyntaxOperand representation of this Stage.

type StaticConditionalValue

type StaticConditionalValue interface {
	// IsConditional returns whether a Condition is attached to this StaticConditionalValue.
	IsConditional() bool
	// GetCondition returns the Condition attached to this StaticConditionalValue.
	GetCondition() *Condition
	// AddCondition attaches the given Condition to this StaticConditionalValue.
	AddCondition(*Condition)
}

StaticConditionalValue needs to be implemented by static Value that holds a Condition.

type SyntaxNode

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

SyntaxNode is the representation of an operation performed on Value.

func NewFormulaForFunctionCall

func NewFormulaForFunctionCall(fnName string, arguments ...any) *SyntaxNode

NewFormulaForFunctionCall returns a new SyntaxNode representing a function call taking in the provided arguments. Clients must make sure to call PreProcessOperand on all args of Value type before sending them into this method.

func NewFormulaForTwoValMiddleOp

func NewFormulaForTwoValMiddleOp(v1 Value, v2 Value, op Op, opDesc string) *SyntaxNode

NewFormulaForTwoValMiddleOp returns a new SyntaxNode representing a binary operation that has an operator lied in the middle of two operands. Clients must make sure that to call PreProcessOperand on both v1 and v2 before sending them into this method.

func NewSyntaxNode

func NewSyntaxNode(category OpCategory, op Op, opDesc string, operands []any) *SyntaxNode

NewSyntaxNode returns a new SyntaxNode with the provided fields.

func (*SyntaxNode) GetCategory

func (n *SyntaxNode) GetCategory() OpCategory

GetCategory returns the category of this SyntaxNode.

func (*SyntaxNode) GetOp

func (n *SyntaxNode) GetOp() Op

GetOp returns the operation performed of this SyntaxNode.

func (*SyntaxNode) GetOpDesc

func (n *SyntaxNode) GetOpDesc() string

GetOpDesc returns the operation description of this SyntaxNode.

func (*SyntaxNode) GetOperands

func (n *SyntaxNode) GetOperands() []any

GetOperands returns the operands of this SyntaxNode.

func (*SyntaxNode) MarshalJSON

func (n *SyntaxNode) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this SyntaxNode.

type SyntaxOperand

type SyntaxOperand struct {
	Name              string      `json:",omitempty"`
	StageIdx          int         `json:",omitempty"`
	StaticValue       string      `json:",omitempty"`
	Node              *SyntaxNode `json:",omitempty"`
	WrapInParentheses bool        `json:",omitempty"`
}

SyntaxOperand represents how an operand of a SyntaxNode should be encoded in JSON format.

func NewSyntaxOperand

func NewSyntaxOperand(v Value) *SyntaxOperand

NewSyntaxOperand returns a new SyntaxOperand for those Value that come without stageIdx.

func NewSyntaxOperandWithFormula

func NewSyntaxOperandWithFormula(formula *SyntaxNode, wrapInParentheses bool) *SyntaxOperand

NewSyntaxOperandWithFormula returns a new SyntaxOperand for those Value that are not anchored but have a formula.

func NewSyntaxOperandWithStageIdx

func NewSyntaxOperandWithStageIdx(v Value, stageIdx int) *SyntaxOperand

NewSyntaxOperandWithStageIdx returns a new SyntaxOperand for those Value that come with stageIdx.

func NewSyntaxOperandWithStaticValue

func NewSyntaxOperandWithStaticValue(value string) *SyntaxOperand

NewSyntaxOperandWithStaticValue returns a new SyntaxOperand for static values.

type Tag

type Tag struct {
	Name  string
	Value any
	// contains filtered or unexported fields
}

Tag is a simple pair of name and value that can be attached to a Value to provide extra information.

func NewTagFrom

func NewTagFrom(v Value) Tag

NewTagFrom returns a Tag from the given Value.

func (Tag) GetName

func (t Tag) GetName() string

GetName returns the name of this Tag.

func (Tag) GetValue

func (t Tag) GetValue() any

GetValue returns the untyped value this Tag contains.

type Tags

type Tags []Tag

Tags is the collection of tags that was applied on a Value.

func (Tags) AddTags

func (t Tags) AddTags(tags ...Tag) Tags

AddTags adds the provided Tag to this Tags.

func (Tags) MarshalJSON

func (t Tags) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of this Tags.

func (Tags) Tag

func (t Tags) Tag(taggers ...ITagger)

Tag applies this collection of tags on the provided ITagger.

type TypedValue

type TypedValue[T any] interface {
	Value
	// GetTypedValue returns the typed value this TypedValue contains.
	GetTypedValue() T
}

TypedValue is a Value bounded by a particular type.

func PreProcessOperand

func PreProcessOperand[T any](tv TypedValue[T]) TypedValue[T]

PreProcessOperand returns a replacement for the input value if it's nil.

type Value

type Value interface {

	// IsNil returns whether this Value is nil.
	IsNil() bool
	// GetValue returns the untyped value this Value contains.
	GetValue() any
	// Stringify returns the value this Value contains as a string.
	Stringify() string
	// contains filtered or unexported methods
}

Value is a wrapper that gives an identity to any variables that are used in our code.

Jump to

Keyboard shortcuts

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