The adsorption of fluorine, chlorine, bromine, and iodine diatomic molecules on graphene has been investigated using density functional theory with taking into account nonlocal correlation effects by means of vdW-DF approach. It is shown that the van der Waals interaction plays a crucial role in the formation of chemical bonding between graphene and halogen molecules, and is therefore important for a proper description of adsorption in this system. In-plane orientation of the molecules has been found to be more stable than the orientation perpendicular to the graphene layer. In the cases of F$_2$, Br$_2$ and I$_2$ we also found an ionic contribution to the binding energy, slowly vanishing with distance. Analysis of the electronic structure shows that ionic interaction arises due to the charge transfer from graphene to the molecules. Furthermore, we found that the increase of impurity concentration leads to the conduction band formation in graphene due to interaction between halogen molecules. In addition, graphite intercalation by halogen molecules has been investigated. In the presence of halogen molecules the binding between graphite layers becomes significantly weaker, which is in accordance with the results of recent experiments on sonochemical exfoliation of intercalated graphite.