Ivan Sagalaev
unread,Dec 3, 2013, 4:19:50 AM12/3/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to highl...@googlegroups.com
Hello everyone!
I invented a new syntax feature that should both improve readability of
language files and reduce size of the compressed file. Right now I'm in
the middle of converting language files and it's going to take a while
before I could publish it without breaking everything so I thought of
just describing it here.
We currently have a lot of things like this:
var STRINGS = [
{
className: 'string',
contains: [hljs.BACKSLASH_ESCAPE]
//...
},
{
className: 'string',
contains: [hljs.BACKSLASH_ESCAPE]
// ...
},
// repeat 5 more times
];
And then when you want to reuse those STRINGS you should use very ugly
`concat` call, sometimes even chaining them:
{
contains: STRINGS.concat(NUMBERS.concat([
// other submodes
]))
}
Now this will look much more streamlined:
var STRING = {
className: 'string',
contains: [hljs.BACKSLASH_ESCAPE]
variants: [
{ ... }, // only the relevant bits that actually differ
{ ... },
]
}
And it can be used right inside the `contains`:
{
contains: [
STRING,
NUMBER,
// other submodes
]
}
And the implementation turns out to be surprisingly easy, constrained to
a single spot in mode compilation.