{"action":"created","issue":{"url":"https://api.github.com/repos/LeaVerou/prism/issues/424","labels_url":"https://api.github.com/repos/LeaVerou/prism/issues/424/labels{/name}","comments_url":"https://api.github.com/repos/LeaVerou/prism/issues/424/comments","events_url":"https://api.github.com/repos/LeaVerou/prism/issues/424/events","html_url":"https://github.com/LeaVerou/prism/pull/424","id":51866249,"number":424,"title":"Competition between patterns to solve the comment/string/regexp problem","user":{"login":"Golmote","id":565460,"avatar_url":"https://avatars.githubusercontent.com/u/565460?v=3","gravatar_id":"","url":"https://api.github.com/users/Golmote","html_url":"https://github.com/Golmote","followers_url":"https://api.github.com/users/Golmote/followers","following_url":"https://api.github.com/users/Golmote/following{/other_user}","gists_url":"https://api.github.com/users/Golmote/gists{/gist_id}","starred_url":"https://api.github.com/users/Golmote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Golmote/subscriptions","organizations_url":"https://api.github.com/users/Golmote/orgs","repos_url":"https://api.github.com/users/Golmote/repos","events_url":"https://api.github.com/users/Golmote/events{/privacy}","received_events_url":"https://api.github.com/users/Golmote/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":19,"created_at":"2014-12-12T23:44:20Z","updated_at":"2015-01-04T19:39:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/LeaVerou/prism/pulls/424","html_url":"https://github.com/LeaVerou/prism/pull/424","diff_url":"https://github.com/LeaVerou/prism/pull/424.diff","patch_url":"https://github.com/LeaVerou/prism/pull/424.patch"},"body":"This is a proposition to solve the main problem of Prism. (#307, #412, #187, #183, #155, #153...)\r\n\r\nThe PR adds the notion of competition between patterns.\r\n\r\nBefore 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).\r\nThen 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.\r\n\r\nTo 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.\r\n\r\nIf you don't change the language definitions, the behaviour is the same as before.\r\n\r\nA behaviour that needs to be mentionned is that the position of the first competitor in the grammar determines the position all the whole competition with that identifier (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.\r\n\r\nI configured C-like and JS as an example, by setting the same competition key for the tokens \"comment\", \"string\" and \"regexp\" (that are all three \"enclosing\" patterns). Here is a before/after comparison :\r\n![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)\r\n\r\nWhat do you think of it ?\r\n"},"comment":{"url":"https://api.github.com/repos/LeaVerou/prism/issues/comments/68645720","html_url":"https://github.com/LeaVerou/prism/pull/424#issuecomment-68645720","issue_url":"https://api.github.com/repos/LeaVerou/prism/issues/424","id":68645720,"user":{"login":"Golmote","id":565460,"avatar_url":"https://avatars.githubusercontent.com/u/565460?v=3","gravatar_id":"","url":"https://api.github.com/users/Golmote","html_url":"https://github.com/Golmote","followers_url":"https://api.github.com/users/Golmote/followers","following_url":"https://api.github.com/users/Golmote/following{/other_user}","gists_url":"https://api.github.com/users/Golmote/gists{/gist_id}","starred_url":"https://api.github.com/users/Golmote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Golmote/subscriptions","organizations_url":"https://api.github.com/users/Golmote/orgs","repos_url":"https://api.github.com/users/Golmote/repos","events_url":"https://api.github.com/users/Golmote/events{/privacy}","received_events_url":"https://api.github.com/users/Golmote/received_events","type":"User","site_admin":false},"created_at":"2015-01-04T19:39:03Z","updated_at":"2015-01-04T19:39:03Z","body":"Wouldn't `greedy` be confusing regarding its meaning when talking about regexps?"}}