@@ -170,34 +170,39 @@ function() {
170
170
return ;
171
171
mode . compiled = true ;
172
172
173
- mode . keywords = mode . keywords || mode . beginKeywords ;
174
- if ( mode . keywords ) {
175
- var compiled_keywords = { } ;
173
+ function compileKeywords ( keywords ) {
174
+ var result = { } ;
176
175
177
176
function flatten ( className , str ) {
178
177
if ( language . case_insensitive ) {
179
178
str = str . toLowerCase ( ) ;
180
179
}
181
180
str . split ( ' ' ) . forEach ( function ( kw ) {
182
181
var pair = kw . split ( '|' ) ;
183
- compiled_keywords [ pair [ 0 ] ] = [ className , pair [ 1 ] ? Number ( pair [ 1 ] ) : 1 ] ;
182
+ result [ pair [ 0 ] ] = [ className , pair [ 1 ] ? Number ( pair [ 1 ] ) : 1 ] ;
184
183
} ) ;
185
184
}
186
185
187
- mode . lexemesRe = langRe ( mode . lexemes || / [ A - Z a - z 0 - 9 _ \. ] + / , true ) ;
188
- if ( typeof mode . keywords == 'string' ) { // string
189
- flatten ( 'keyword' , mode . keywords ) ;
186
+ if ( typeof keywords == 'string' ) { // string
187
+ flatten ( 'keyword' , keywords ) ;
190
188
} else {
191
- Object . keys ( mode . keywords ) . forEach ( function ( className ) {
192
- flatten ( className , mode . keywords [ className ] ) ;
189
+ Object . keys ( keywords ) . forEach ( function ( className ) {
190
+ flatten ( className , keywords [ className ] ) ;
193
191
} ) ;
194
192
}
195
- mode . keywords = compiled_keywords ;
193
+ return result ;
194
+ }
195
+
196
+ mode . lexemesRe = langRe ( mode . lexemes || / [ A - Z a - z 0 - 9 _ \. ] + / , true ) ;
197
+ mode . keywords = mode . keywords || mode . beginKeywords ;
198
+ if ( mode . keywords ) {
199
+ mode . keywords = compileKeywords ( mode . keywords ) ;
196
200
}
197
201
198
202
if ( parent ) {
199
203
if ( mode . beginKeywords ) {
200
- mode . begin = '\\b(' + mode . beginKeywords . split ( / \s + / ) . join ( '|' ) + ')\\b(?!\\.)\\s*' ;
204
+ mode . beginKeywords = compileKeywords ( mode . beginKeywords ) ;
205
+ mode . begin = mode . lexemes || / [ A - Z a - z 0 - 9 _ \. ] + / ;
201
206
}
202
207
mode . beginRe = langRe ( mode . begin ? mode . begin : '\\B|\\b' ) ;
203
208
if ( ! mode . end && ! mode . endsWithParent )
@@ -231,9 +236,9 @@ function() {
231
236
}
232
237
233
238
var terminators = [ ] ;
234
- for ( var i = 0 ; i < mode . contains . length ; i ++ ) {
235
- terminators . push ( reStr ( mode . contains [ i ] . begin ) ) ;
236
- }
239
+ mode . contains . forEach ( function ( c ) {
240
+ terminators . push ( reStr ( c . begin ) ) ;
241
+ } ) ;
237
242
if ( mode . terminator_end ) {
238
243
terminators . push ( reStr ( mode . terminator_end ) ) ;
239
244
}
@@ -261,7 +266,7 @@ function() {
261
266
262
267
function subMode ( lexeme , mode ) {
263
268
for ( var i = 0 ; i < mode . contains . length ; i ++ ) {
264
- if ( testRe ( mode . contains [ i ] . beginRe , lexeme ) ) {
269
+ if ( testRe ( mode . contains [ i ] . beginRe , lexeme ) && ( ! mode . contains [ i ] . beginKeywords || mode . contains [ i ] . beginKeywords . hasOwnProperty ( lexeme ) ) ) {
265
270
return mode . contains [ i ] ;
266
271
}
267
272
}
@@ -356,6 +361,7 @@ function() {
356
361
}
357
362
358
363
function processLexeme ( buffer , lexeme ) {
364
+
359
365
mode_buffer += buffer ;
360
366
if ( lexeme === undefined ) {
361
367
result += processBuffer ( ) ;
0 commit comments