Skip to content

Commit c0ba191

Browse files
committed
leafo#542 : be able to parse bracket enclosed keyword as part of a property value
1 parent 2c25b8b commit c0ba191

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Parser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,10 @@ protected function expression(&$out)
12701270
}
12711271

12721272
if ($this->matchChar('[')) {
1273-
if ($this->parenExpression($out, $s, "]")) {
1273+
if ($this->parenExpression($out, $s, "]", [Type::T_LIST, Type::T_KEYWORD])) {
1274+
if ($out[0] !== Type::T_LIST && $out[0] !== Type::T_MAP) {
1275+
$out = [Type::T_STRING, '', [ '[', $out, ']' ]];
1276+
}
12741277
return true;
12751278
}
12761279

@@ -1292,24 +1295,25 @@ protected function expression(&$out)
12921295
* @param array $out
12931296
* @param integer $s
12941297
* @param string $closingParen
1298+
* @param array $allowedTypes
12951299
*
12961300
* @return boolean
12971301
*/
1298-
protected function parenExpression(&$out, $s, $closingParen = ")")
1302+
protected function parenExpression(&$out, $s, $closingParen = ")", $allowedTypes = [Type::T_LIST, Type::T_MAP])
12991303
{
13001304
if ($this->matchChar($closingParen)) {
13011305
$out = [Type::T_LIST, '', []];
13021306

13031307
return true;
13041308
}
13051309

1306-
if ($this->valueList($out) && $this->matchChar($closingParen) && $out[0] === Type::T_LIST) {
1310+
if ($this->valueList($out) && $this->matchChar($closingParen) && in_array($out[0], $allowedTypes)) {
13071311
return true;
13081312
}
13091313

13101314
$this->seek($s);
13111315

1312-
if ($this->map($out)) {
1316+
if (in_array(Type::T_MAP, $allowedTypes) && $this->map($out)) {
13131317
return true;
13141318
}
13151319

0 commit comments

Comments
 (0)