@@ -65,7 +65,10 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
6565 numberStart = parserConfig . numberStart || / [ \d \. ] / ,
6666 number = parserConfig . number || / ^ (?: 0 x [ a - f \d ] + | 0 b [ 0 1 ] + | (?: \d + \. ? \d * | \. \d + ) (?: e [ - + ] ? \d + ) ? ) ( u | l l ? | l | f ) ? / i,
6767 isOperatorChar = parserConfig . isOperatorChar || / [ + \- * & % = < > ! ? | \/ ] / ,
68- isIdentifierChar = parserConfig . isIdentifierChar || / [ \w \$ _ \xa1 - \uffff ] / ;
68+ isIdentifierChar = parserConfig . isIdentifierChar || / [ \w \$ _ \xa1 - \uffff ] / ,
69+ // An optional function that takes a {string} token and returns true if it
70+ // should be treated as a builtin.
71+ isReservedIdentifier = parserConfig . isReservedIdentifier || false ;
6972
7073 var curPunc , isDefKeyword ;
7174
@@ -113,7 +116,8 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
113116 return "keyword" ;
114117 }
115118 if ( contains ( types , cur ) ) return "type" ;
116- if ( contains ( builtin , cur ) ) {
119+ if ( contains ( builtin , cur )
120+ || ( isReservedIdentifier && isReservedIdentifier ( cur ) ) ) {
117121 if ( contains ( blockKeywords , cur ) ) curPunc = "newstatement" ;
118122 return "builtin" ;
119123 }
@@ -286,6 +290,14 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
286290 return false ;
287291 }
288292
293+ // For C and C++ (and ObjC): identifiers starting with __
294+ // or _ followed by a capital letter are reserved for the compiler.
295+ function cIsReservedIdentifier ( token ) {
296+ if ( ! token || token . length < 2 ) return false ;
297+ if ( token [ 0 ] != '_' ) return false ;
298+ return ( token [ 1 ] == '_' ) || ( token [ 1 ] !== token [ 1 ] . toLowerCase ( ) ) ;
299+ }
300+
289301 function cpp14Literal ( stream ) {
290302 stream . eatWhile ( / [ \w \. ' ] / ) ;
291303 return "number" ;
@@ -368,14 +380,17 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
368380 def ( [ "text/x-csrc" , "text/x-c" , "text/x-chdr" ] , {
369381 name : "clike" ,
370382 keywords : words ( cKeywords ) ,
371- types : words ( cTypes + " bool _Complex _Bool float_t double_t intptr_t intmax_t " +
372- "int8_t int16_t int32_t int64_t uintptr_t uintmax_t uint8_t uint16_t " +
373- "uint32_t uint64_t" ) ,
383+ types : words ( cTypes + " bool float_t double_t intptr_t intmax_t int8_t int16_t " +
384+ "int32_t int64_t uintptr_t uintmax_t uint8_t uint16_t uint32_t uint64_t" ) ,
374385 blockKeywords : words ( "case do else for if switch while struct" ) ,
375386 defKeywords : words ( "struct" ) ,
376387 typeFirstDefinitions : true ,
377388 atoms : words ( "NULL true false" ) ,
378- hooks : { "#" : cppHook , "*" : pointerHook } ,
389+ isReservedIdentifier : cIsReservedIdentifier ,
390+ hooks : {
391+ "#" : cppHook ,
392+ "*" : pointerHook ,
393+ } ,
379394 modeProps : { fold : [ "brace" , "include" ] }
380395 } ) ;
381396
@@ -393,6 +408,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
393408 atoms : words ( "true false NULL" ) ,
394409 dontIndentStatements : / ^ t e m p l a t e $ / ,
395410 isIdentifierChar : / [ \w \$ _ ~ \xa1 - \uffff ] / ,
411+ isReservedIdentifier : cIsReservedIdentifier ,
396412 hooks : {
397413 "#" : cppHook ,
398414 "*" : pointerHook ,
@@ -720,10 +736,11 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
720736
721737 def ( "text/x-objectivec" , {
722738 name : "clike" ,
723- keywords : words ( cKeywords + "inline restrict _Bool _Complex _Imaginary BOOL Class bycopy byref id IMP in " +
724- "inout nil oneway out Protocol SEL self super atomic nonatomic retain copy readwrite readonly" ) ,
739+ keywords : words ( cKeywords + "inline restrict BOOL Class bycopy byref id IMP in inout nil oneway out " +
740+ "Protocol SEL self super atomic nonatomic retain copy readwrite readonly" ) ,
725741 types : words ( cTypes ) ,
726742 atoms : words ( "YES NO NULL NILL ON OFF true false" ) ,
743+ isReservedIdentifier : cIsReservedIdentifier ,
727744 hooks : {
728745 "@" : function ( stream ) {
729746 stream . eatWhile ( / [ \w \$ ] / ) ;
0 commit comments