code: func ParseRuleFromExpr(module *Module, expr *Expr) (*Rule, error) {
  
  	if len(expr.With) > 0 {
  		return nil, fmt.Errorf("expressions using with keyword cannot be used for rule head")
  	}
  
  	if expr.Negated {
  		return nil, fmt.Errorf("negated expressions cannot be used for rule head")
  	}
  
  	if term, ok := expr.Terms.(*Term); ok {
  		switch v := term.Value.(type) {
  		case Ref:
  			return ParsePartialSetDocRuleFromTerm(module, term)
  		default:
  			return nil, fmt.Errorf("%v cannot be used for rule name", TypeName(v))
  		}
  	}
  
  	if !expr.IsEquality() && expr.IsCall() {
  		if _, ok := BuiltinMap[expr.Operator().String()]; ok {
  			return nil, fmt.Errorf("rule name conflicts with built-in function")
  		}
  		return ParseRuleFromCallExpr(module, expr.Terms.([]*Term))
  	}
  
  	lhs, rhs := expr.Operand(0), expr.Operand(1)
  
  	rule, err := ParseCompleteDocRuleFromEqExpr(module, lhs, rhs)
  	if err == nil {
  		return rule, nil
  	}
  
  	rule, err = ParseRuleFromCallEqExpr(module, lhs, rhs)
  	if err == nil {
  		return rule, nil
  	}
  
  	return ParsePartialObjectDocRuleFromEqExpr(module, lhs, rhs)
  }
docs: // ParseRuleFromExpr returns a rule if the expression can be interpreted as a
  // rule definition.