common

package
v0.0.0-...-07525cc Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: Apache-2.0, MIT Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalForms

func EvalForms(name string, scope Scope, forms []*Form) interface{}

EvalForms will evaluate the non-terminal form `name` by randomly picking one of the []*Form defined by its rules.

Types

type Form

type Form struct {
	Name     string
	Fn       FormFn
	Weight   float64
	Restrain float64
}

Form defines the structure of any form.

func NewForm

func NewForm(name string, fun interface{}) *Form

NewForm will instantiate a form structure and return the same.

func (*Form) Eval

func (form *Form) Eval(scope Scope, args ...interface{}) interface{}

Eval will evaulate this form passing `scope` and `args`.

func (*Form) SetDefaultWeight

func (form *Form) SetDefaultWeight(weight float64)

SetDefaultWeight will set a default weightage for this form, if a weightage is not defined already. Typically this form will be rule-form.

func (*Form) SetWeight

func (form *Form) SetWeight(weight, restrain float64)

SetWeight will set the weightage for this form. Typically this form will be rule-form.

func (*Form) String

func (form *Form) String() string

type FormFn

type FormFn func(scope Scope, args ...interface{}) interface{}

FormFn function signature for all forms.

type NTForms

type NTForms map[string][]*Form

NTForms is a map of non-terminal name to its rule definitions.

type Scope

type Scope map[string]interface{}

Scope of production grammar, a scope can be evaluated to generate permutations and combinations. For the first time after compiling the production grammar into a scope, BuildContext() shall be called on the scope before evaluating it. Mutiple evaluation on the same scope is possible after calling the RebuildContext() on the scope.

func NewScopeFromRoot

func NewScopeFromRoot(ns []parsec.ParsecNode) Scope

NewScopeFromRoot will create a new scope from root non-terminal.

func (Scope) Clone

func (scope Scope) Clone() Scope

Clone local scope and return back a new scope.

func (Scope) Del

func (scope Scope) Del(name string, value interface{}, g bool) Scope

Del will delete `name` from local scope or global scope (based on `g`).

func (Scope) Get

func (scope Scope) Get(name string) (value interface{}, g, ok bool)

Get will fetch `name` from local scope or global scope indicated by `g`.

func (Scope) GetBagdir

func (scope Scope) GetBagdir() string

GetBagdir will return the current bagdir.

func (Scope) GetInt64

func (scope Scope) GetInt64(name string) (i int64, g, ok bool)

GetInt64 will get the variable name, convert it and return as int64.

func (Scope) GetNonTerminal

func (scope Scope) GetNonTerminal(name string) (nt []*Form, ok bool)

GetNonTerminal will return the rule-forms for non-terminal `name`.

func (Scope) GetProdfile

func (scope Scope) GetProdfile() string

GetProdfile will return the current production filename.

func (Scope) GetRandom

func (scope Scope) GetRandom() *rand.Rand

GetRandom will return current *math/rand.Rand object.

func (Scope) GetString

func (scope Scope) GetString(name string) (s string, g, ok bool)

GetString will get the variable name, convert it and return as string.

func (Scope) GetWeight

func (scope Scope) GetWeight(name string) (value float64, ok bool)

GetWeight will return the weightage for form `name`.

func (Scope) RebuildContext

func (scope Scope) RebuildContext() Scope

RebuildContext to evaluate same generation tree multiple times.

func (Scope) Set

func (scope Scope) Set(name string, value interface{}, g bool) Scope

Set will set `name` to `value` in local scope or global scope (based on `g`).

func (Scope) SetBagdir

func (scope Scope) SetBagdir(bagdir string) Scope

SetBagdir will set the bag-dir to be used by `bag` form.

func (Scope) SetNonTerminal

func (scope Scope) SetNonTerminal(name string, nt []*Form) Scope

SetNonTerminal will set the rule-forms for non-terminal `name`.

func (Scope) SetProdfile

func (scope Scope) SetProdfile(prodfile string) Scope

SetProdfile will production filename.

func (Scope) SetRandom

func (scope Scope) SetRandom(rnd *rand.Rand) Scope

SetRandom will set *math/rand.Rand object.

func (Scope) SetWeight

func (scope Scope) SetWeight(name string, value float64) Scope

SetWeight will set the weightage for form `name`.

Jump to

Keyboard shortcuts

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