本文整理汇总了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()
}