Exemple #1
0
 /**
  * [type] $name [= default]
  *
  * @return array
  * @throws Exception
  */
 public function parse_args()
 {
     $token = $this->scanner->next();
     if ($token['code'] === T_RPARENTHESIS) {
         // No arguments
         $this->scanner->back();
         return [];
     }
     $arg = ['type' => 'mixed', 'name' => NULL, 'value' => [FALSE, NULL]];
     if ($token['code'] === T_ARRAY || $token['code'] === T_STRING) {
         // type
         $arg['type'] = $token['value'];
         $token = $this->scanner->next();
     }
     if ($token['code'] === T_VARIABLE) {
         $arg['name'] = $token['value'];
         $token = $this->scanner->next();
     }
     if ($token['code'] === T_ASSIGN) {
         $token = $this->scanner->next();
         $arg['value'] = [TRUE, $token['value']];
         if ($token['value'] == '[') {
             // TODO: allow initialization with non-empty arrays
             $this->check(T_ARRAY_CLOSE);
         }
         $token = $this->scanner->next();
     }
     if ($token['code'] === T_RPARENTHESIS) {
         $this->scanner->back();
         if (is_null($arg['name'])) {
             return [];
         }
         return [$arg];
     } elseif ($token['code'] == T_COMMA) {
         return array_merge([$arg], $this->parse_args());
     }
 }