LeaVerou/prism — pull request #424 by Golmote (2014-12-12 23:44:20+00:00)
Title: Competition between patterns to solve the comment/string/regexp problem

This is a proposition to solve the main problem of Prism. (#307, #412, #187, #183, #155, #153...)

The PR add the notion of competition between patterns.

Before highlighting the code, we loop through the patterns to group together the ones that are in competition with each other (each group contains what I call competitors).
Then we loop through the groups and for each part of the string, we try to match each competitor. The winner is the one which matches the closest from the start of the substring.

To indicate that some patterns are in competition, you need to add a "competition" key on the pattern, specifying an identifier for the competition. All patterns in the grammar that have the same competition identifier are in competition with each other.

If you don't change the language definitions, the behaviour is the same as before.

A behaviour that needs to be mentionned is that the position of the first competitor in the grammar determines the position all the whole competition (i.e. all the competitors), wherever the other competitors are defined in the grammar. This should normally not be a problem, as candidates for competition are most of the time consecutives in the grammar.

I configured C-like and JS as an example. Here is a before/after comparison :
![prism-before](https://cloud.githubusercontent.com/assets/565460/5421269/fe756a26-8260-11e4-9453-72941de316ee.png) ![prism-after](https://cloud.githubusercontent.com/assets/565460/5421270/fe762286-8260-11e4-9790-7ee8dd4d9dd7.png)

What do you think of it ?