-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Is your request related to a specific problem you're having?
Yes, illegal can become hard to read when it includes multiple items.
Any alternative solutions you considered...
I saw this in routeros which brought this to my attention (again).
{ // illegal constructs
variants: [
{ begin: /^@/, end: /$/ }, // dns
{ begin: /\/\*/, end: /\*\// }, // -- comment
{ begin: /%%/, end: /$/ }, // -- comment
{ begin: /^'/, end: /$/ }, // Monkey one line comment
{ begin: /^\s*\/[\w-]+=/, end: /$/ }, // jboss-cli
{ begin: /\/\//, end: /$/ }, // Stan comment
{ begin: /^\[</, end: />\]$/ }, // F# class declaration?
{ begin: /<\//, end: />/ }, // HTML tags
{ begin: /^facet /, end: /\}/ }, // roboconf - лютый костыль )))
{ begin: '^1\\.\\.(\\d+)$', end: /$/ } // tap
],
illegal: /./
},
But this is very verbose and you have to think about it for a minute to realize what it's doing.
Note: Do not focus on if this is a GOOD idea for routeros to have such a long list (it may not be)... that's not a concern here... there are definitely cases where a list of 2-3 illegals makes very good sense. I only show this as one example of how you'd do this today (get a more readable illegal list) without any core library changes.
The solution you'd prefer / feature you'd like to see added...
Instead I'd like to formalize that as:
{
illegal: [
/^@/, // dns
/\/\*/, // C style multi-line comment
/%%/, // some other comment...
// ...
],
}
And these would be auto-joined with regex.either... The older single regex or string format would still be supported. But if we saw an array here when we're call regex.either
on it...