@@ -54,11 +54,13 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
5454 return inGenerator ( state , '[' )
5555 }
5656
57- function inGenerator ( state , bracket ) {
58- var curr = currentScope ( state ) ,
59- prev = currentScope ( state , 1 ) ;
57+ function inGenerator ( state , bracket , depth ) {
6058 if ( typeof ( bracket ) === "undefined" ) { bracket = '(' ; }
61- if ( curr === bracket || ( prev === bracket && curr === "for" ) ) {
59+ if ( typeof ( depth ) === "undefined" ) { depth = 0 ; }
60+ var scope = currentScope ( state , depth ) ;
61+ if ( ( depth == 0 && scope === "if" && inGenerator ( state , bracket , depth + 1 ) ) ||
62+ ( scope === "for" && inGenerator ( state , bracket , depth + 1 ) ) ||
63+ ( scope === bracket ) ) {
6264 return true ;
6365 }
6466 return false ;
@@ -119,16 +121,16 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
119121 state . scopes . push ( '(' ) ;
120122 }
121123
122- var scope = currentScope ( state ) ;
123-
124124 if ( inArray ( state ) && ch === ']' ) {
125- if ( scope === "for" ) { state . scopes . pop ( ) ; }
125+ if ( currentScope ( state ) === "if" ) { state . scopes . pop ( ) ; }
126+ while ( currentScope ( state ) === "for" ) { state . scopes . pop ( ) ; }
126127 state . scopes . pop ( ) ;
127128 state . leavingExpr = true ;
128129 }
129130
130131 if ( inGenerator ( state ) && ch === ')' ) {
131- if ( scope === "for" ) { state . scopes . pop ( ) ; }
132+ if ( currentScope ( state ) === "if" ) { state . scopes . pop ( ) ; }
133+ while ( currentScope ( state ) === "for" ) { state . scopes . pop ( ) ; }
132134 state . scopes . pop ( ) ;
133135 state . leavingExpr = true ;
134136 }
@@ -143,12 +145,14 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
143145 }
144146
145147 var match ;
146- if ( match = stream . match ( openers , false ) ) {
148+ if ( match = stream . match ( openers ) ) {
147149 state . scopes . push ( match [ 0 ] ) ;
150+ return "keyword" ;
148151 }
149152
150- if ( stream . match ( closers , false ) ) {
153+ if ( stream . match ( closers ) ) {
151154 state . scopes . pop ( ) ;
155+ return "keyword" ;
152156 }
153157
154158 // Handle type annotations
0 commit comments