@@ -12,10 +12,13 @@ Category: common
1212 * */
1313export default function ( hljs ) {
1414 const regex = hljs . regex ;
15- const IDENT_RE = '([a-zA-Z_\x7f-\xff] [a-zA-Z0-9_\x7f-\xff]*' +
15+ const IDENT_RE_CORE = '[a-zA-Z0-9_\x7f-\xff]*' +
1616 // negative look-ahead tries to avoid matching patterns that are not
1717 // Perl at all like $ident$, @ident@, etc.
1818 '(?![A-Za-z0-9])(?![$]))' ;
19+ const IDENT_RE = regex . concat ( "([a-zA-Z_\\x7f-\\xff]" , IDENT_RE_CORE ) ;
20+ // Will not detect camelCase classes
21+ const PASCAL_CASE_CLASS_NAME_RE = regex . concat ( "([A-Z]" , IDENT_RE_CORE ) ;
1922 const VARIABLE = {
2023 scope : 'variable' ,
2124 match : '\\$+' + IDENT_RE ,
@@ -47,7 +50,7 @@ export default function(hljs) {
4750 end : / [ \t ] * ( \w + ) \b / ,
4851 contains : hljs . QUOTE_STRING_MODE . contains . concat ( SUBST ) ,
4952 } ) ;
50- // list of valid whitespaces because non-breaking space might be part of a name
53+ // list of valid whitespaces because non-breaking space might be part of a IDENT_RE
5154 const WHITESPACE = '[ \t\n]' ;
5255 const STRING = {
5356 scope : 'string' ,
@@ -331,7 +334,7 @@ export default function(hljs) {
331334 / \b / ,
332335 // to prevent keywords from being confused as the function title
333336 regex . concat ( "(?!fn\\b|function\\b|" , normalizeKeywords ( KWS ) . join ( "\\b|" ) , "|" , normalizeKeywords ( BUILT_INS ) . join ( "\\b|" ) , "\\b)" ) ,
334- regex . concat ( IDENT_RE , "+" ) ,
337+ IDENT_RE ,
335338 regex . concat ( WHITESPACE , "*" ) ,
336339 regex . lookahead ( / (? = \( ) / )
337340 ] ,
@@ -340,6 +343,57 @@ export default function(hljs) {
340343 }
341344 } ;
342345
346+ const CONSTANT_REFERENCE = regex . concat ( IDENT_RE , "\\b(?!\\()" ) ;
347+
348+ const LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON = {
349+ variants : [
350+ {
351+ match : [
352+ regex . concat (
353+ / : : / ,
354+ regex . lookahead ( / (? ! c l a s s \b ) / )
355+ ) ,
356+ CONSTANT_REFERENCE ,
357+ ] ,
358+ scope : {
359+ 2 : "variable.constant" ,
360+ } ,
361+ } ,
362+ {
363+ match : [
364+ / : : / ,
365+ / c l a s s / ,
366+ ] ,
367+ scope : {
368+ 2 : "variable.language" ,
369+ } ,
370+ } ,
371+ {
372+ match : [
373+ PASCAL_CASE_CLASS_NAME_RE ,
374+ regex . concat (
375+ "::" ,
376+ regex . lookahead ( / (? ! c l a s s \b ) / )
377+ ) ,
378+ ] ,
379+ scope : {
380+ 1 : "title.class" ,
381+ } ,
382+ } ,
383+ {
384+ match : [
385+ PASCAL_CASE_CLASS_NAME_RE ,
386+ / : : / ,
387+ / c l a s s / ,
388+ ] ,
389+ scope : {
390+ 1 : "title.class" ,
391+ 3 : "variable.language" ,
392+ } ,
393+ }
394+ ]
395+ } ;
396+
343397 return {
344398 case_insensitive : false ,
345399 keywords : KEYWORDS ,
@@ -380,16 +434,17 @@ export default function(hljs) {
380434 } ,
381435 VARIABLE ,
382436 FUNCTION_INVOKE ,
437+ LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON ,
383438 {
384439 match : [
385440 / c o n s t / ,
386- regex . concat ( WHITESPACE , "+" ) ,
441+ / \s / ,
387442 IDENT_RE ,
388- regex . concat ( WHITESPACE , "*=" ) ,
443+ / \s * = / ,
389444 ] ,
390445 scope : {
391446 1 : "keyword" ,
392- 3 : "variable" ,
447+ 3 : "variable.constant " ,
393448 } ,
394449 } ,
395450 {
@@ -425,6 +480,7 @@ export default function(hljs) {
425480 contains : [
426481 'self' ,
427482 VARIABLE ,
483+ LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON ,
428484 hljs . C_BLOCK_COMMENT_MODE ,
429485 STRING ,
430486 NUMBER
0 commit comments