Ants need a lot of energy to survive, and the need for energy is where sugar comes into play. Ants get excited about sugar, just as humans do, so when they find it, they will rush back to the colony and spread the word. They do this by leaving a chemical trail, which invites the other ants to follow.
The ants will also communicate physically by telling the other ants what kind of food to expect at the end of the trail. This is why the ants can often be found in packs, swarmed around sugar, or other foods.
Although ants are attracted to almost every food, the truth is that they easily get attracted to foods that contain more sugar and, most especially, pure sugar. The reason for this is very simple. Ants are easily attracted to sugar because they can easily break it down and get the needed energy from it. Whenever an ant wants to get some foods, it uses its antenna and its eyes to detect the food location.
As soon as it gets to the food, it uses its antenna to check if it is something that can be eaten. Once this is sorted out, the ant will go for the food and take it to its nest. I think ants have a very strong ability to perceive the odor of sugar wherever they are. Ants spend most of their time on how they can quickly build their nest, so to achieve this, they need more energy.