本文整理匯總了Golang中github.com/prataprc/monster/common.Scope.SetBagdir方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scope.SetBagdir方法的具體用法?Golang Scope.SetBagdir怎麽用?Golang Scope.SetBagdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/prataprc/monster/common.Scope
的用法示例。
在下文中一共展示了Scope.SetBagdir方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
func BuildContext(
scope common.Scope,
seed uint64,
bagdir, prodfile string) common.Scope {
scope["_prodfile"] = prodfile
scope.SetBagdir(bagdir)
if seed != 0 {
scope.SetRandom(rand.New(rand.NewSource(int64(seed))))
} else {
now := time.Now().UnixNano()
scope.SetRandom(rand.New(rand.NewSource(int64(now))))
}
// verify conflicts between user provided form-names
// and builtin form-names.
for name := range scope["_nonterminals"].(common.NTForms) {
if _, ok := builtins[name]; ok {
log.Printf("warn: `%v` non-terminal is defined as builtin\n", name)
}
}
return scope.RebuildContext()
}