Worms live on decaying organic matter (the stuff you put in the compost) and as this matter passes through the worm it is broken up and neutralized by secretions of calcium carbonate from calciferous glands near the worm's gizzard. Once in the gizzard, material is finely ground prior to digestion. Digestive intestinal juices rich in hormones, enzymes, and other fermenting substances continue the breakdown process. The matter passes out of the worm's body in the form of casts, which are the richest and finest quality of all humus material. Fresh casts are markedly higher in bacteria, organic material, and available nitrogen, calcium, magnesium, phosphorus and potassium than soil itself.
Also, as the worm burrows and tunnels through the heap it is aerating and oxygenating it, allowing water and nutrients to filter down.
So Hurrah for the worm in your compost.
Snail live mainly on living matter but will attack fresh organic matter. But their digestive systems are different and they suck all the goodness out. They do not make compost nor tunnel to aerate the heap. They are all take and no give! So if you see a snail in your compost you will have to remove it by hand. You can't use snail pellets because they would change the balance of your compost heap.