Index: trunk/tools/switch-master/ConfEditor.php |
— | — | @@ -286,7 +286,6 @@ |
287 | 287 | * @param $value mixed Value |
288 | 288 | */ |
289 | 289 | function setVar( &$array, $path, $key, $value ) { |
290 | | - echo "$path [$key] = $value\n"; |
291 | 290 | $pathArr = explode( '/', $path ); |
292 | 291 | $target =& $array; |
293 | 292 | if ( $path !== '' ) { |
— | — | @@ -305,11 +304,11 @@ |
306 | 305 | * @return mixed Parsed value |
307 | 306 | */ |
308 | 307 | function parseScalar( $str ) { |
309 | | - if ( @$str[0] == '\'' ) |
| 308 | + if ( $str !== '' && $str[0] == '\'' ) |
310 | 309 | // Single-quoted string |
311 | 310 | return strtr( substr( $str, 1, -1 ), |
312 | 311 | array( '\\\'' => '\'', '\\\\' => '\\' ) ); |
313 | | - if ( @$str[0] == '"' ) |
| 312 | + if ( $str !== '' && @$str[0] == '"' ) |
314 | 313 | // Double-quoted string |
315 | 314 | return strtr( stripcslashes( substr( $str, 1, -1 ) ), |
316 | 315 | array( '\'' => '\\\'' ) ); |
— | — | @@ -555,15 +554,43 @@ |
556 | 555 | $this->nextPath( $token->text ); |
557 | 556 | $this->expect( T_VARIABLE ); |
558 | 557 | $this->skipSpace(); |
| 558 | + $arrayAssign = false; |
| 559 | + if ( $this->currentToken()->type == '[' ) { |
| 560 | + $this->nextToken(); |
| 561 | + $token = $this->skipSpace(); |
| 562 | + if ( !$token->isScalar() ) { |
| 563 | + $this->error( "expected a string or number for the array key" ); |
| 564 | + } |
| 565 | + if ( $token->type == T_CONSTANT_ENCAPSED_STRING ) { |
| 566 | + $text = $this->parseScalar( $token->text ); |
| 567 | + } else { |
| 568 | + $text = $token->text; |
| 569 | + } |
| 570 | + if ( !$this->validatePath( $text ) ) { |
| 571 | + $this->error( "Invalid associative array name \"$text\"" ); |
| 572 | + } |
| 573 | + $this->pushPath( $text ); |
| 574 | + $this->nextToken(); |
| 575 | + $this->skipSpace(); |
| 576 | + $this->expect( ']' ); |
| 577 | + $this->skipSpace(); |
| 578 | + $arrayAssign = true; |
| 579 | + } |
559 | 580 | $this->expect( '=' ); |
560 | 581 | $this->skipSpace(); |
561 | 582 | $this->startPathValue(); |
562 | | - $this->pushState( 'expression', 'statement end' ); |
| 583 | + if ( $arrayAssign ) |
| 584 | + $this->pushState( 'expression', 'array assign end' ); |
| 585 | + else |
| 586 | + $this->pushState( 'expression', 'statement end' ); |
563 | 587 | break; |
| 588 | + case 'array assign end': |
564 | 589 | case 'statement end': |
| 590 | + $this->endPathValue(); |
| 591 | + if ( $state == 'array assign end' ) |
| 592 | + $this->popPath(); |
565 | 593 | $this->skipSpace(); |
566 | | - $this->endPathValue(); |
567 | | - $this->expect( ';'); |
| 594 | + $this->expect( ';' ); |
568 | 595 | $this->nextPath( '@extra-' . ($this->serial++) ); |
569 | 596 | break; |
570 | 597 | case 'expression': |