@@ -24,6 +24,7 @@ CodeMirror.defineMode("groovy", function(config) {
2424 "short static strictfp super switch synchronized threadsafe throw throws transient " +
2525 "try void volatile while" ) ;
2626 var blockKeywords = words ( "catch class do else finally for if switch try while enum interface def" ) ;
27+ var standaloneKeywords = words ( "return break continue" ) ;
2728 var atoms = words ( "null true false this" ) ;
2829
2930 var curPunc ;
@@ -50,7 +51,7 @@ CodeMirror.defineMode("groovy", function(config) {
5051 stream . skipToEnd ( ) ;
5152 return "comment" ;
5253 }
53- if ( expectExpression ( state . lastToken ) ) {
54+ if ( expectExpression ( state . lastToken , false ) ) {
5455 return startString ( ch , stream , state ) ;
5556 }
5657 }
@@ -70,6 +71,7 @@ CodeMirror.defineMode("groovy", function(config) {
7071 if ( atoms . propertyIsEnumerable ( cur ) ) { return "atom" ; }
7172 if ( keywords . propertyIsEnumerable ( cur ) ) {
7273 if ( blockKeywords . propertyIsEnumerable ( cur ) ) curPunc = "newstatement" ;
74+ else if ( standaloneKeywords . propertyIsEnumerable ( cur ) ) curPunc = "standalone" ;
7375 return "keyword" ;
7476 }
7577 return "variable" ;
@@ -132,9 +134,10 @@ CodeMirror.defineMode("groovy", function(config) {
132134 return "comment" ;
133135 }
134136
135- function expectExpression ( last ) {
137+ function expectExpression ( last , newline ) {
136138 return ! last || last == "operator" || last == "->" || / [ \. \[ \{ \( , ; : ] / . test ( last ) ||
137- last == "newstatement" || last == "keyword" || last == "proplabel" ;
139+ last == "newstatement" || last == "keyword" || last == "proplabel" ||
140+ ( last == "standalone" && ! newline ) ;
138141 }
139142
140143 function Context ( indented , column , type , align , prev ) {
@@ -174,7 +177,7 @@ CodeMirror.defineMode("groovy", function(config) {
174177 state . indented = stream . indentation ( ) ;
175178 state . startOfLine = true ;
176179 // Automatic semicolon insertion
177- if ( ctx . type == "statement" && ! expectExpression ( state . lastToken ) ) {
180+ if ( ctx . type == "statement" && ! expectExpression ( state . lastToken , true ) ) {
178181 popContext ( state ) ; ctx = state . context ;
179182 }
180183 }
@@ -209,7 +212,7 @@ CodeMirror.defineMode("groovy", function(config) {
209212 indent : function ( state , textAfter ) {
210213 if ( ! state . tokenize [ state . tokenize . length - 1 ] . isBase ) return 0 ;
211214 var firstChar = textAfter && textAfter . charAt ( 0 ) , ctx = state . context ;
212- if ( ctx . type == "statement" && ! expectExpression ( state . lastToken ) ) ctx = ctx . prev ;
215+ if ( ctx . type == "statement" && ! expectExpression ( state . lastToken , true ) ) ctx = ctx . prev ;
213216 var closing = firstChar == ctx . type ;
214217 if ( ctx . type == "statement" ) return ctx . indented + ( firstChar == "{" ? 0 : config . indentUnit ) ;
215218 else if ( ctx . align ) return ctx . column + ( closing ? 0 : 1 ) ;
0 commit comments