Skip to content

Commit a3e9c53

Browse files
committed
[groovy mode] Highlight interpolated variables without braces
Closes #6899
1 parent 7f70233 commit a3e9c53

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

mode/groovy/groovy.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ CodeMirror.defineMode("groovy", function(config) {
9191
if (!tripleQuoted) { break; }
9292
if (stream.match(quote + quote)) { end = true; break; }
9393
}
94-
if (quote == '"' && next == "$" && !escaped && stream.eat("{")) {
95-
state.tokenize.push(tokenBaseUntilBrace());
96-
return "string";
94+
if (quote == '"' && next == "$" && !escaped) {
95+
if (stream.eat("{")) {
96+
state.tokenize.push(tokenBaseUntilBrace());
97+
return "string";
98+
} else if (stream.match(/^\w/, false)) {
99+
state.tokenize.push(tokenVariableDeref);
100+
return "string";
101+
}
97102
}
98103
escaped = !escaped && next == "\\";
99104
}
@@ -122,6 +127,15 @@ CodeMirror.defineMode("groovy", function(config) {
122127
return t;
123128
}
124129

130+
function tokenVariableDeref(stream, state) {
131+
var next = stream.match(/^(\.|[\w\$_]+)/)
132+
if (!next) {
133+
state.tokenize.pop()
134+
return state.tokenize[state.tokenize.length-1](stream, state)
135+
}
136+
return next[0] == "." ? null : "variable"
137+
}
138+
125139
function tokenComment(stream, state) {
126140
var maybeEnd = false, ch;
127141
while (ch = stream.next()) {

0 commit comments

Comments
 (0)