Skip to content

Commit e74e00c

Browse files
committed
Groovy: Regexp optimisation + don't use captures if not needed
1 parent 2474f06 commit e74e00c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

components/prism-groovy.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
Prism.languages.groovy = Prism.languages.extend('clike', {
2-
'keyword': /\b(as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
2+
'keyword': /\b(?:as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
33
'string': [
44
{
5-
pattern: /("""|''')[\s\S]*?\1|(\$\/)(\$\/\$|[\s\S])*?\/\$/,
5+
pattern: /("""|''')[\s\S]*?\1|(?:\$\/)(?:\$\/\$|[\s\S])*?\/\$/,
66
greedy: true
77
},
88
{
9-
pattern: /("|'|\/)(?:\\?.)*?\1/,
9+
pattern: /(["'\/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
1010
greedy: true
1111
}
1212
],
1313
'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?[\d]+)?)[glidf]?\b/i,
1414
'operator': {
15-
pattern: /(^|[^.])(~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.{1,2}(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
15+
pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.{1,2}(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
1616
lookbehind: true
1717
},
1818
'punctuation': /\.+|[{}[\];(),:$]/
@@ -26,7 +26,7 @@ Prism.languages.insertBefore('groovy', 'string', {
2626
});
2727

2828
Prism.languages.insertBefore('groovy', 'punctuation', {
29-
'spock-block': /\b(setup|given|when|then|and|cleanup|expect|where):/
29+
'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
3030
});
3131

3232
Prism.languages.insertBefore('groovy', 'function', {
@@ -43,9 +43,9 @@ Prism.hooks.add('wrap', function(env) {
4343
var delimiter = env.content[0];
4444

4545
if (delimiter != "'") {
46-
var pattern = /([^\\])(\$(\{.*?\}|[\w\.]+))/;
46+
var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
4747
if (delimiter === '$') {
48-
pattern = /([^\$])(\$(\{.*?\}|[\w\.]+))/;
48+
pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
4949
}
5050

5151
// To prevent double HTML-encoding we have to decode env.content first

components/prism-groovy.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)