@@ -292,7 +292,8 @@ static function t_canonical($token)
292
292
293
293
return $ token ;
294
294
}
295
- else if (is_numeric ($ token ))
295
+
296
+ if (is_numeric ($ token ))
296
297
{
297
298
$ token = substr (Parser::tokenName ($ token ), 3 );
298
299
}
@@ -316,7 +317,7 @@ function __construct($code, $options)
316
317
$ code = "\n{$ code }" ;
317
318
}
318
319
319
- $ code = preg_replace ( self :: $ TRAILING_SPACES , '' , str_replace ("\r" , '' , $ code ));
320
+ $ code = rtrim ( str_replace ("\r" , '' , $ code ));
320
321
321
322
$ options = array_merge (array (
322
323
'indent ' => 0 ,
@@ -357,7 +358,7 @@ function balanced_string($str, $end)
357
358
continue ;
358
359
}
359
360
360
- switch ($ letter = $ str{ $ i } )
361
+ switch ($ letter = $ str[ $ i ] )
361
362
{
362
363
case '\\' :
363
364
++$ continue_count ;
@@ -443,7 +444,7 @@ function heredoc_token()
443
444
}
444
445
445
446
$ heredoc = $ match [0 ];
446
- $ quote = $ heredoc{ 0 } ;
447
+ $ quote = $ heredoc[ 0 ] ;
447
448
$ doc = $ this ->sanitize_heredoc ($ match [2 ], array ('quote ' => $ quote , 'indent ' => NULL ));
448
449
449
450
if ($ quote === '" ' && strpos ($ doc , '#{ ' ) !== FALSE )
@@ -469,7 +470,7 @@ function heregex_token($match)
469
470
$ re = preg_replace (self ::$ HEREGEX_OMIT , '' , $ body );
470
471
$ re = preg_replace ('/\// ' , '\\/ ' , $ re );
471
472
472
- if (preg_match ( ' /^\*/ ' , $ re) )
473
+ if (strpos ( $ re, " * " ) === 0 )
473
474
{
474
475
$ this ->error ('regular expressions cannot begin with `*` ' );
475
476
}
@@ -731,8 +732,7 @@ function interpolate_string($str, array $options = array()) // #{0}
731
732
$ this ->token ('( ' , '( ' );
732
733
}
733
734
734
- for ($ i = 0 ; $ i < count ($ tokens ); $ i ++)
735
- {
735
+ foreach ($ tokens as $ i => $ iValue ) {
736
736
list ($ tag , $ value ) = $ tokens [$ i ];
737
737
738
738
if ($ i )
@@ -760,7 +760,7 @@ function interpolate_string($str, array $options = array()) // #{0}
760
760
761
761
function js_token ()
762
762
{
763
- if ( ! ($ this ->chunk { 0 } === '` ' && preg_match (self ::$ JSTOKEN , $ this ->chunk , $ match )))
763
+ if ( ! ($ this ->chunk [ 0 ] === '` ' && preg_match (self ::$ JSTOKEN , $ this ->chunk , $ match )))
764
764
{
765
765
return 0 ;
766
766
}
@@ -841,7 +841,7 @@ function literal_token()
841
841
}
842
842
else
843
843
{
844
- $ value = $ this ->chunk { 0 } ;
844
+ $ value = $ this ->chunk [ 0 ] ;
845
845
}
846
846
847
847
$ tag = t ($ value );
@@ -888,7 +888,7 @@ function literal_token()
888
888
{
889
889
$ tag = t ('SHIFT ' );
890
890
}
891
- else if (in_array ($ value , self ::$ LOGIC ) || $ value === '? ' && (isset ($ prev ['spaced ' ]) && $ prev ['spaced ' ]))
891
+ else if (in_array ($ value , self ::$ LOGIC ) || ( $ value === '? ' && (isset ($ prev ['spaced ' ]) && $ prev ['spaced ' ]) ))
892
892
{
893
893
$ tag = t ('LOGIC ' );
894
894
}
@@ -979,7 +979,7 @@ function number_token()
979
979
{
980
980
$ this ->error ("radix prefix ' $ number' must be lowercase " );
981
981
}
982
- else if (preg_match ( ' /E/ ' , $ number) && ! preg_match ( ' /^0x/ ' , $ number) )
982
+ else if (strpos ( $ number, " E " ) !== false && strpos ( $ number, " 0x " ) !== 0 )
983
983
{
984
984
$ this ->error ("exponential notation ' $ number' must be indicated with a lowercase 'e' " );
985
985
}
@@ -1077,7 +1077,7 @@ function pair($tag)
1077
1077
1078
1078
function regex_token ()
1079
1079
{
1080
- if ($ this ->chunk { 0 } !== '/ ' )
1080
+ if ($ this ->chunk [ 0 ] !== '/ ' )
1081
1081
{
1082
1082
return 0 ;
1083
1083
}
@@ -1094,7 +1094,7 @@ function regex_token()
1094
1094
1095
1095
if ($ prev )
1096
1096
{
1097
- if (in_array ($ prev [0 ], t ((isset ($ prev ['spaced ' ]) && $ prev ['spaced ' ]) ?
1097
+ if (in_array ($ prev [0 ], t ((isset ($ prev ['spaced ' ]) && $ prev ['spaced ' ]) ?
1098
1098
self ::$ NOT_REGEX : self ::$ NOT_SPACED_REGEX )))
1099
1099
{
1100
1100
return 0 ;
@@ -1168,7 +1168,7 @@ function sanitize_heredoc($doc, array $options)
1168
1168
1169
1169
function string_token ()
1170
1170
{
1171
- switch ($ this ->chunk { 0 } )
1171
+ switch ($ this ->chunk [ 0 ] )
1172
1172
{
1173
1173
case "' " :
1174
1174
if ( ! preg_match (self ::$ SIMPLESTR , $ this ->chunk , $ match ))
@@ -1222,6 +1222,8 @@ function tag($index = 0, $tag = NULL)
1222
1222
{
1223
1223
$ token = & last ($ this ->tokens , $ index );
1224
1224
1225
+ if (!$ token ) $ token = [];
1226
+
1225
1227
if ( ! is_null ($ tag ))
1226
1228
{
1227
1229
$ token [0 ] = $ tag ;
@@ -1286,7 +1288,7 @@ function tokenize()
1286
1288
{
1287
1289
while ( ($ this ->chunk = substr ($ this ->code , $ this ->index )) != FALSE )
1288
1290
{
1289
- $ types = array ('identifier ' , 'comment ' , 'whitespace ' , 'line ' , 'heredoc ' ,
1291
+ $ types = array ('identifier ' , 'comment ' , 'whitespace ' , 'line ' , 'heredoc ' ,
1290
1292
'string ' , 'number ' , 'regex ' , 'js ' , 'literal ' );
1291
1293
1292
1294
foreach ($ types as $ type )
@@ -1319,12 +1321,14 @@ function value($index = 0, $value = NULL)
1319
1321
{
1320
1322
$ token = & last ($ this ->tokens , $ index );
1321
1323
1324
+ if (!$ token ) $ token = [];
1325
+
1322
1326
if ( ! is_null ($ value ))
1323
1327
{
1324
1328
$ token [1 ] = $ value ;
1325
1329
}
1326
1330
1327
- return $ token [1 ];
1331
+ return $ token [1 ] ?? null ;
1328
1332
}
1329
1333
1330
1334
function unfinished ()
@@ -1337,7 +1341,7 @@ function unfinished()
1337
1341
1338
1342
function whitespace_token ()
1339
1343
{
1340
- if ( ! (preg_match (self ::$ WHITESPACE , $ this ->chunk , $ match ) || ($ nline = ($ this ->chunk { 0 } === "\n" ))))
1344
+ if ( ! (preg_match (self ::$ WHITESPACE , $ this ->chunk , $ match ) || ($ nline = ($ this ->chunk [ 0 ] === "\n" ))))
1341
1345
{
1342
1346
return 0 ;
1343
1347
}
0 commit comments