LeaVerou/prism — pull request #321 by zeitgeist87 (2014-08-10 21:55:02+00:00)
Title: Allow multiple regex per token name by using arrays

Hi,

In response to the discussion on my previous pull request LeaVerou/prism#319, I implemented the same functionality with arrays. It is actually only a few lines of code, but because the indentation for the inner loop changed it looks like a huge change.

In most languages there are multiple different ways of declaring the
same constructs (e.g. comments, strings, ...) and sometimes it is
difficult or unpractical to match all of them with one single regular
expression. This patch adds the possibility to use an array of pattern
objects.

For example there is a minor bug in the current definition of the
`clike` language, that could be solved with this patch:

The character immediately in front of a single line comment is
highlighted as a comment as well.

```javascript
something// something
```

This is because both definitions for single and multiline comments
have to be matched with a single regex and the `lookbehind` parameter
can only be applied to the first captured string.

With this patch one could split the two definitions up and use
`lookbehind` for both, thereby eliminating the bug.

```javascript
'comment': [
{
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g,
lookbehind: true
},
{
pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g,
lookbehind: true
}
],
```