I have a custom mode which is defined like this (to colorize a script) :
EDIT : I fixed it (see solution below). I will not delete topic in case it would be useful for someone else. If there is a better solution, please let me know about it.
function tokenBase(stream, state)
{
if (stream.eat(...)) return ...; //punctuation, ...
if (stream.eat(...)) return ...;
...
if (stream.match(some_regex)) return ...; //constant, identifiers, ...
if (stream.match(some_regex)) return ...;
...
//take care of comments
...
//anything not matched so far is considered as an error (will be underlined)
return "error";
}
It works fine, the issue is for errors (usually not allowed characters) which get consumed one by one.
For example, a script containing $$$$$$
will result in something like this in the editor:
<span class="error">$</span><span class="error">$</span><span class="error">$</span>...
I would like to have those errors to be grouped together:
<span class="error">$$$$$$</span>
This is annoying because I also reuse that tokenizer for other things and I would like consecutive errors to be considered as a single token.
EDIT : here is solution:
if (stream.match([/^only_allowed_chars]+/))
return "error"; //try to consume several errors at once
return "error"; //all the other cases