Documentation ¶
Overview ¶
Use production grammer with a rudimentary S expression like language to generate permutations and combinations. Every element in the grammer including the S expressions will be converted into a Form object.
Parser uses `parsec` tool to parse production grammar and construct generator tree.
Monster grammar
bnf : forms nterminal* nterminal : ":" rules "." rules : ruletok+ : rules "|" ruletok+ ruletok : ident | ref | terminal | string | form forms : form* form : "(" formarg+ ")" ident : `[a-z0-9]+` terminal : `[A-Z][A-Z0-9]*` formarg : `[^ \t\r\n\(\)]+` | form ws : `[ \t\r\n]+`
nomenclature of forms constructed while compiling a production file,
forms["##literaltok"] evaluating INT/HEX/OCT/FLOAT/TRUE/FALSE in form-args forms["##formtok"] evaluating any other form-args, an open ended spec forms["##ident"] evaluating non-terminal identifiers in rule-args forms["##term"] evaluating terminals like DQ, NL in farm-args or rule-args forms["##string"] evaluating literal strings in form-args and rule-args forms["##ref"] evaluating references into local/global namespace forms["##rule"] evaluating a non-terminal rule forms[<symbol>] evaluating builtin or application supplied functions forms["#<ident>] evaluating non-terminal forms from top-level forms["##var"] in unused as of now
these forms are evaluated from one of top-level forms to generate permutations and combinations.
Form evaluation happens at the following points using Eval() or EvalForms() APIs,
- when a global S-expression invokes a builtin function
- when a global S-expression invokes a non-terminal
- before passing S-expression arguments to a form.
- when special form `weigh` is identified at the begining of a non-terminal rule definition.
- when a non-terminal rule is randomly picked by EvalForms()
- before passing rule arguments to a rule-form.
references:
$<symbol> specified in a rule or, #<symbol> specified in a form argument, will evaluate a lookup into local or global scope.
Programmatically invoking monster {
root, _ := monster.Y(parsec.NewScanner(text)).(common.Scope) scope := monster.BuildContext(root, seed, bagdir, prodfile) nterms := scope["_nonterminals"].(common.NTForms) for i := 0; i < count; i++ { scope = scope.RebuildContext() val := monster.EvalForms("root", scope, nterms["s"]) } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EvalForms = common.EvalForms
EvalForms refer to common.EvalForms for more documentation
var Y parsec.Parser
Y root combinator for monster.
Functions ¶
func BuildContext ¶
BuildContext to initialize a new scope for evaluating production grammars. The scope contains the following elements,
_globalForms: list of top-level S-expression definitions _nonterminals: list of top-level non-terminals in production _weights: running weights for each non-terminal rule _globals: global scope _bagdir: absolute path to directory containing bags of data _prodfile: absolute path to production file _random: reference to seeded *math.rand.Rand object