@@ -18,6 +18,7 @@ const funcDeco = Decoration.mark({ class: 'cm-php-func' });
1818const thisDeco = Decoration . mark ( { class : 'cm-php-this' } ) ;
1919const selfStaticDeco = Decoration . mark ( { class : 'cm-php-self-static' } ) ;
2020const propertyDeco = Decoration . mark ( { class : 'cm-php-property' } ) ;
21+ const keywordDeco = Decoration . mark ( { class : 'cm-php-keyword' } ) ;
2122
2223interface LineToken {
2324 from : number ;
@@ -45,7 +46,8 @@ const PHP_KEYWORDS = new Set([
4546 'continue' , 'return' , 'throw' , 'try' , 'catch' , 'finally' , 'declare' , 'function' , 'fn' ,
4647 'class' , 'interface' , 'trait' , 'enum' , 'extends' , 'implements' , 'use' , 'new' , 'clone' ,
4748 'echo' , 'print' , 'include' , 'include_once' , 'require' , 'require_once' , 'isset' , 'empty' ,
48- 'unset' , 'eval' , 'exit' , 'die' , 'match' , 'yield' , 'array' , 'list'
49+ 'unset' , 'eval' , 'exit' , 'die' , 'match' , 'yield' , 'array' , 'list' ,
50+ 'public' , 'protected' , 'private' , 'readonly' ,
4951] ) ;
5052
5153function getIgnoredCodeRanges ( text : string ) : Array < { from : number ; to : number } > {
@@ -298,6 +300,54 @@ function tokenizePhpCode(lineFrom: number, text: string, lineTokens: LineToken[]
298300 }
299301 }
300302
303+ const classConstKeywordRegex = / : : \s * ( c l a s s ) \b / g;
304+ while ( ( match = classConstKeywordRegex . exec ( text ) ) !== null ) {
305+ const from = lineFrom + match . index + match [ 0 ] . indexOf ( 'class' ) ;
306+ const to = from + 5 ;
307+ if ( ! isInsideIgnored ( from - lineFrom , to - lineFrom , ignored ) ) {
308+ lineTokens . push ( { from, to, deco : keywordDeco } ) ;
309+ }
310+ }
311+
312+ const readonlyRegex =
313+ / \b ( r e a d o n l y ) \b (? = \s + (?: c l a s s | f i n a l | a b s t r a c t | p u b l i c | p r o t e c t e d | p r i v a t e | s t a t i c | v a r | [ ? \\ a - z A - Z _ $ ] ) ) / g;
314+ while ( ( match = readonlyRegex . exec ( text ) ) !== null ) {
315+ const startPos = match . index ;
316+ if ( isInsideIgnored ( startPos , startPos + 8 , ignored ) ) continue ;
317+ const prevChar = startPos > 0 ? text [ startPos - 1 ] : '' ;
318+ const twoBefore = startPos > 1 ? text . slice ( startPos - 2 , startPos ) : '' ;
319+ const beforeLine = text . slice ( 0 , startPos ) ;
320+ if (
321+ prevChar === '$' ||
322+ twoBefore === '->' ||
323+ twoBefore === '::' ||
324+ / \b f u n c t i o n \s + & ? $ / . test ( beforeLine )
325+ ) {
326+ continue ;
327+ }
328+ lineTokens . push ( { from : lineFrom + startPos , to : lineFrom + startPos + 8 , deco : keywordDeco } ) ;
329+ }
330+
331+ const enumDeclMatch = / ^ \s * ( e n u m ) \s + [ A - Z a - z _ ] / . exec ( text ) ;
332+ if ( enumDeclMatch ) {
333+ const startPos = text . indexOf ( 'enum' ) ;
334+ if ( ! isInsideIgnored ( startPos , startPos + 4 , ignored ) ) {
335+ lineTokens . push ( { from : lineFrom + startPos , to : lineFrom + startPos + 4 , deco : keywordDeco } ) ;
336+ }
337+ }
338+
339+ const asymVisRegex = / \b ( p u b l i c | p r o t e c t e d | p r i v a t e ) \s * \( \s * ( s e t ) \s * \) / g;
340+ while ( ( match = asymVisRegex . exec ( text ) ) !== null ) {
341+ const visStart = match . index ;
342+ const visEnd = visStart + match [ 1 ] . length ;
343+ const setStart = match . index + match [ 0 ] . lastIndexOf ( 'set' ) ;
344+ const setEnd = setStart + 3 ;
345+ if ( ! isInsideIgnored ( visStart , setEnd , ignored ) ) {
346+ lineTokens . push ( { from : lineFrom + visStart , to : lineFrom + visEnd , deco : keywordDeco } ) ;
347+ lineTokens . push ( { from : lineFrom + setStart , to : lineFrom + setEnd , deco : keywordDeco } ) ;
348+ }
349+ }
350+
301351 const propertyAccessRegex = / (?: - > | \? - > ) \s * ( [ a - z A - Z _ \x80 - \xff ] [ a - z A - Z 0 - 9 _ \x80 - \xff ] * ) \b (? ! \s * ( \( | \. \. \. ) ) / g;
302352 while ( ( match = propertyAccessRegex . exec ( text ) ) !== null ) {
303353 const propName = match [ 1 ] ;
0 commit comments