@@ -429,13 +429,22 @@ protected function reset($modifiers = 0)
429
429
$ this ->modifiers = $ modifiers ;
430
430
}
431
431
432
+ /**
433
+ * Tests if the given token type is a reserved keyword in the supported PHP
434
+ * version.
435
+ *
436
+ * @param $tokenType
437
+ * @return boolean
438
+ * @since 1.1.1
439
+ */
440
+ abstract protected function isKeyword ($ tokenType );
441
+
432
442
/**
433
443
* Will return <b>true</b> if the given <b>$tokenType</b> is a valid class
434
444
* name part.
435
445
*
436
446
* @param integer $tokenType The type of a parsed token.
437
- *
438
- * @return string
447
+ * @return boolean
439
448
* @since 0.10.6
440
449
*/
441
450
protected abstract function isClassName ($ tokenType );
@@ -4818,13 +4827,14 @@ protected abstract function parseIntegerNumber();
4818
4827
* @return PHP_Depend_Code_ASTArray
4819
4828
* @since 1.0.0
4820
4829
*/
4821
- private function doParseArray ()
4830
+ private function doParseArray ($ static = false )
4822
4831
{
4823
4832
$ this ->tokenStack ->push ();
4824
4833
4825
4834
return $ this ->setNodePositionsAndReturn (
4826
4835
$ this ->parseArray (
4827
- $ this ->builder ->buildAstArray ()
4836
+ $ this ->builder ->buildAstArray (),
4837
+ $ static
4828
4838
)
4829
4839
);
4830
4840
}
@@ -4841,29 +4851,32 @@ protected abstract function isArrayStartDelimiter();
4841
4851
/**
4842
4852
* Parses a php array declaration.
4843
4853
*
4844
- * @param PHP_Depend_Code_ASTArray $array The context array node.
4854
+ * @param PHP_Depend_Code_ASTArray $array
4855
+ * @param boolean $static
4845
4856
*
4846
4857
* @return PHP_Depend_Code_ASTArray
4847
4858
* @since 1.0.0
4848
4859
*/
4849
- protected abstract function parseArray (PHP_Depend_Code_ASTArray $ array );
4860
+ protected abstract function parseArray (PHP_Depend_Code_ASTArray $ array, $ static = false );
4850
4861
4851
4862
/**
4852
4863
* Parses all elements in an array.
4853
4864
*
4854
- * @param PHP_Depend_Code_ASTArray $array The context array node.
4855
- * @param integer $endDelimiter The version specific delimiter.
4865
+ * @param PHP_Depend_Code_ASTArray $array
4866
+ * @param integer $endDelimiter
4867
+ * @param boolean $static
4856
4868
*
4857
4869
* @return PHP_Depend_Code_ASTArray
4858
4870
* @since 1.0.0
4859
4871
*/
4860
4872
protected function parseArrayElements (
4861
4873
PHP_Depend_Code_ASTArray $ array ,
4862
- $ endDelimiter
4874
+ $ endDelimiter ,
4875
+ $ static = false
4863
4876
) {
4864
4877
$ this ->consumeComments ();
4865
4878
while ($ endDelimiter !== $ this ->tokenizer ->peek ()) {
4866
- $ array ->addChild ($ this ->parseArrayElement ());
4879
+ $ array ->addChild ($ this ->parseArrayElement ($ static ));
4867
4880
4868
4881
$ this ->consumeComments ();
4869
4882
if (self ::T_COMMA === $ this ->tokenizer ->peek ()) {
@@ -4880,19 +4893,39 @@ protected function parseArrayElements(
4880
4893
* An array element can have a simple value, a key/value pair, a value by
4881
4894
* reference or a key/value pair with a referenced value.
4882
4895
*
4896
+ * @param boolean $static
4883
4897
* @return PHP_Depend_Code_ASTArrayElement
4884
4898
* @since 1.0.0
4885
4899
*/
4886
- protected function parseArrayElement ()
4900
+ protected function parseArrayElement ($ static = false )
4887
4901
{
4888
4902
$ this ->consumeComments ();
4889
4903
4890
4904
$ this ->tokenStack ->push ();
4891
4905
4892
4906
$ element = $ this ->builder ->buildAstArrayElement ();
4893
4907
if ($ this ->parseOptionalByReference ()) {
4908
+
4909
+ if ($ static ) {
4910
+ $ tokens = $ this ->tokenStack ->pop ();
4911
+
4912
+ throw new PHP_Depend_Parser_UnexpectedTokenException (
4913
+ end ($ tokens ),
4914
+ $ this ->sourceFile ->getFileName ()
4915
+ );
4916
+ }
4917
+
4894
4918
$ element ->setByReference ();
4895
4919
}
4920
+
4921
+ $ this ->consumeComments ();
4922
+ if ($ this ->isKeyword ($ this ->tokenizer ->peek ())) {
4923
+ throw new PHP_Depend_Parser_UnexpectedTokenException (
4924
+ $ this ->tokenizer ->next (),
4925
+ $ this ->sourceFile ->getFileName ()
4926
+ );
4927
+ }
4928
+
4896
4929
$ element ->addChild ($ this ->parseExpression ());
4897
4930
4898
4931
$ this ->consumeComments ();
@@ -6182,8 +6215,14 @@ private function parseVariableDeclarator()
6182
6215
private function parseStaticValueOrStaticArray ()
6183
6216
{
6184
6217
$ this ->consumeComments ();
6185
- if ($ this ->tokenizer ->peek () === self ::T_ARRAY ) {
6186
- return $ this ->parseStaticArray ();
6218
+ if ($ this ->isArrayStartDelimiter ()) {
6219
+ // TODO: Use default value as value!
6220
+ $ defaultValue = $ this ->doParseArray (true );
6221
+
6222
+ $ value = new PHP_Depend_Code_Value ();
6223
+ $ value ->setValue (array ());
6224
+
6225
+ return $ value ;
6187
6226
}
6188
6227
return $ this ->parseStaticValue ();
6189
6228
}
@@ -6304,95 +6343,6 @@ private function parseStaticValue()
6304
6343
throw new PHP_Depend_Parser_TokenStreamEndException ($ this ->tokenizer );
6305
6344
}
6306
6345
6307
- /**
6308
- * This method parses an array as it is used for for parameter or property
6309
- * default values.
6310
- *
6311
- * Note: At the moment the implementation of this method only returns an
6312
- * empty array, but consumes all tokens that belong to the array
6313
- * declaration.
6314
- *
6315
- * TODO: Implement array content/value handling, but how should we handle
6316
- * constant values like array(self::FOO, FOOBAR)?
6317
- *
6318
- * @return array
6319
- * @since 0.9.5
6320
- */
6321
- private function parseStaticArray ()
6322
- {
6323
- $ staticValue = array ();
6324
-
6325
- // Fetch all tokens that belong to this array
6326
- $ this ->consumeToken (self ::T_ARRAY );
6327
- $ this ->consumeComments ();
6328
- $ this ->consumeToken (self ::T_PARENTHESIS_OPEN );
6329
-
6330
- $ parenthesis = 1 ;
6331
-
6332
- $ tokenType = $ this ->tokenizer ->peek ();
6333
- while ($ tokenType !== self ::T_EOF ) {
6334
-
6335
- switch ($ tokenType ) {
6336
-
6337
- case self ::T_PARENTHESIS_CLOSE :
6338
- if (--$ parenthesis === 0 ) {
6339
- break 2 ;
6340
- }
6341
- $ this ->consumeToken (self ::T_PARENTHESIS_CLOSE );
6342
- break ;
6343
-
6344
- case self ::T_PARENTHESIS_OPEN :
6345
- $ this ->consumeToken (self ::T_PARENTHESIS_OPEN );
6346
- ++$ parenthesis ;
6347
- break ;
6348
-
6349
- case self ::T_DIR :
6350
- case self ::T_NULL :
6351
- case self ::T_TRUE :
6352
- case self ::T_FILE :
6353
- case self ::T_LINE :
6354
- case self ::T_NS_C :
6355
- case self ::T_PLUS :
6356
- case self ::T_SELF :
6357
- case self ::T_ARRAY :
6358
- case self ::T_FALSE :
6359
- case self ::T_EQUAL :
6360
- case self ::T_COMMA :
6361
- case self ::T_MINUS :
6362
- case self ::T_COMMENT :
6363
- case self ::T_DOC_COMMENT :
6364
- case self ::T_DOUBLE_COLON :
6365
- case self ::T_STRING :
6366
- case self ::T_BACKSLASH :
6367
- case self ::T_DNUMBER :
6368
- case self ::T_LNUMBER :
6369
- case self ::T_FUNC_C :
6370
- case self ::T_CLASS_C :
6371
- case self ::T_METHOD_C :
6372
- case self ::T_STATIC :
6373
- case self ::T_PARENT :
6374
- case self ::T_NUM_STRING :
6375
- case self ::T_DOUBLE_ARROW :
6376
- case self ::T_CONSTANT_ENCAPSED_STRING :
6377
- $ this ->consumeToken ($ tokenType );
6378
- break ;
6379
-
6380
- default :
6381
- break 2 ;
6382
- }
6383
-
6384
- $ tokenType = $ this ->tokenizer ->peek ();
6385
- }
6386
-
6387
- // Read closing parenthesis
6388
- $ this ->consumeToken (self ::T_PARENTHESIS_CLOSE );
6389
-
6390
- $ defaultValue = new PHP_Depend_Code_Value ();
6391
- $ defaultValue ->setValue ($ staticValue );
6392
-
6393
- return $ defaultValue ;
6394
- }
6395
-
6396
6346
/**
6397
6347
* Checks if the given expression is a read/write variable as defined in
6398
6348
* the PHP zend_language_parser.y definition.
0 commit comments