code: func NewRuleTree(mtree *ModuleTreeNode) *TreeNode {
  
  	ruleSets := map[String][]util.T{}
  
  	// Build rule sets for this package.
  	for _, mod := range mtree.Modules {
  		for _, rule := range mod.Rules {
  			key := String(rule.Head.Name)
  			ruleSets[key] = append(ruleSets[key], rule)
  		}
  	}
  
  	// Each rule set becomes a leaf node.
  	children := map[Value]*TreeNode{}
  
  	for key, rules := range ruleSets {
  		children[key] = &TreeNode{
  			Key:      key,
  			Children: nil,
  			Values:   rules,
  		}
  	}
  
  	// Each module in subpackage becomes child node.
  	for _, child := range mtree.Children {
  		children[child.Key] = NewRuleTree(child)
  	}
  
  	return &TreeNode{
  		Key:      mtree.Key,
  		Values:   nil,
  		Children: children,
  		Hide:     mtree.Hide,
  	}
  }
docs: // NewRuleTree returns a new TreeNode that represents the root
  // of the rule tree populated with the given rules.