Skip to content

Commit 4cb8dd6

Browse files
committed
Improve AST nodes (add "is" prefix for boolean flags)
1 parent 7ab222a commit 4cb8dd6

20 files changed

Lines changed: 77 additions & 77 deletions

libs/parser/resources/grammar.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@
461461
return $children[0];
462462
}
463463

464-
if ($children[0]->variadic) {
464+
if ($children[0]->isVariadic) {
465465
throw SemanticException::fromVariadicWithDefault($offset);
466466
}
467467

468-
$children[0]->optional = true;
468+
$children[0]->isOptional = true;
469469

470470
return $children[0];
471471
},
@@ -477,11 +477,11 @@
477477
return $children[0];
478478
}
479479

480-
if ($children[1]->variadic) {
480+
if ($children[1]->isVariadic) {
481481
throw SemanticException::fromVariadicRedefinition($offset);
482482
}
483483

484-
$children[1]->variadic = true;
484+
$children[1]->isVariadic = true;
485485

486486
return $children[1];
487487
},
@@ -499,13 +499,13 @@
499499
if ($modifier instanceof Phplrt\Contracts\Lexer\TokenInterface) {
500500
switch ($modifier->getName()) {
501501
case 'T_AMP':
502-
$result->output = true;
502+
$result->isOutput = true;
503503
break;
504504
case 'T_ELLIPSIS':
505-
if ($result->variadic) {
505+
if ($result->isVariadic) {
506506
throw SemanticException::fromVariadicRedefinition($offset);
507507
}
508-
$result->variadic = true;
508+
$result->isVariadic = true;
509509
break;
510510
}
511511
}
@@ -535,13 +535,13 @@
535535
if ($modifier instanceof Phplrt\Contracts\Lexer\TokenInterface) {
536536
switch ($modifier->getName()) {
537537
case 'T_AMP':
538-
$result->output = true;
538+
$result->isOutput = true;
539539
break;
540540
case 'T_ELLIPSIS':
541-
if ($result->variadic) {
541+
if ($result->isVariadic) {
542542
throw SemanticException::fromVariadicRedefinition($offset);
543543
}
544-
$result->variadic = true;
544+
$result->isVariadic = true;
545545
break;
546546
}
547547
}

libs/parser/resources/grammar/callable.pp2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ MaybeDefaultCallableParameter -> {
5858
return $children[0];
5959
}
6060

61-
if ($children[0]->variadic) {
61+
if ($children[0]->isVariadic) {
6262
throw SemanticException::fromVariadicWithDefault($offset);
6363
}
6464

65-
$children[0]->optional = true;
65+
$children[0]->isOptional = true;
6666
return $children[0];
6767
}
6868
: ( MaybePrefixedVariadicTypedNamedCallableParameter()
@@ -87,13 +87,13 @@ MaybeModifiersNamedCallableParameter -> {
8787
if ($modifier instanceof \Phplrt\Contracts\Lexer\TokenInterface) {
8888
switch ($modifier->getName()) {
8989
case 'T_AMP':
90-
$result->output = true;
90+
$result->isOutput = true;
9191
break;
9292
case 'T_ELLIPSIS':
93-
if ($result->variadic) {
93+
if ($result->isVariadic) {
9494
throw SemanticException::fromVariadicRedefinition($offset);
9595
}
96-
$result->variadic = true;
96+
$result->isVariadic = true;
9797
break;
9898
}
9999
}
@@ -121,11 +121,11 @@ MaybePrefixedVariadicTypedNamedCallableParameter -> {
121121
return $children[0];
122122
}
123123

124-
if ($children[1]->variadic) {
124+
if ($children[1]->isVariadic) {
125125
throw SemanticException::fromVariadicRedefinition($offset);
126126
}
127127

128-
$children[1]->variadic = true;
128+
$children[1]->isVariadic = true;
129129
return $children[1];
130130
}
131131
: <T_ELLIPSIS>? MaybeTypedNamedCallableParameter()
@@ -159,13 +159,13 @@ MaybeModifiersTypedCallableParameter -> {
159159
if ($modifier instanceof \Phplrt\Contracts\Lexer\TokenInterface) {
160160
switch ($modifier->getName()) {
161161
case 'T_AMP':
162-
$result->output = true;
162+
$result->isOutput = true;
163163
break;
164164
case 'T_ELLIPSIS':
165-
if ($result->variadic) {
165+
if ($result->isVariadic) {
166166
throw SemanticException::fromVariadicRedefinition($offset);
167167
}
168-
$result->variadic = true;
168+
$result->isVariadic = true;
169169
break;
170170
}
171171
}

libs/printer/src/PrettyPrinter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected function printShapeFieldNode(FieldNode $field): string
260260
$name = $this->printShapeFieldName($field);
261261

262262
if ($name !== '') {
263-
if ($field->optional) {
263+
if ($field->isOptional) {
264264
$name .= '?';
265265
}
266266

@@ -448,11 +448,11 @@ protected function printCallableArgumentNode(CallableParameterNode $node): strin
448448
$result .= ' ';
449449
}
450450

451-
if ($node->output) {
451+
if ($node->isOutput) {
452452
$result .= '&';
453453
}
454454

455-
if ($node->variadic) {
455+
if ($node->isVariadic) {
456456
$result .= '...';
457457
}
458458

@@ -461,7 +461,7 @@ protected function printCallableArgumentNode(CallableParameterNode $node): strin
461461
$result .= $this->printLiteralNode($node->name);
462462
}
463463

464-
if ($node->optional) {
464+
if ($node->isOptional) {
465465
$result .= '=';
466466
}
467467

libs/types/src/Callable/CallableParameterNode.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ final class CallableParameterNode extends Node implements \Stringable
1414
public function __construct(
1515
public ?TypeNode $type = null,
1616
public ?VariableLiteralNode $name = null,
17-
public bool $output = false,
18-
public bool $variadic = false,
19-
public bool $optional = false,
17+
public bool $isOutput = false,
18+
public bool $isVariadic = false,
19+
public bool $isOptional = false,
2020
public ?AttributeGroupListNode $attributes = null,
2121
) {
2222
assert($type !== null || $name !== null, new \TypeError(
2323
'Required indication of the type or name of the parameter (one of)',
2424
));
2525

26-
assert($variadic === false || $optional === false, new \TypeError(
26+
assert($isVariadic === false || $isOptional === false, new \TypeError(
2727
'Parameter cannot be both variable and optional (variadic parameter is already optional)',
2828
));
2929
}
@@ -32,15 +32,15 @@ public function __toString(): string
3232
{
3333
$result = [];
3434

35-
if ($this->output) {
35+
if ($this->isOutput) {
3636
$result[] = 'output';
3737
}
3838

39-
if ($this->variadic) {
39+
if ($this->isVariadic) {
4040
$result[] = 'variadic';
4141
}
4242

43-
if ($this->optional) {
43+
if ($this->isOptional) {
4444
$result[] = 'optional';
4545
}
4646

libs/types/src/Shape/ClassConstFieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ final class ClassConstFieldNode extends ExplicitFieldNode
2323
public function __construct(
2424
ClassConstNode $key,
2525
TypeNode $type,
26-
bool $optional = false,
26+
bool $isOptional = false,
2727
?AttributeGroupListNode $attributes = null,
2828
) {
2929
parent::__construct(
3030
key: $key,
3131
type: $type,
32-
optional: $optional,
32+
isOptional: $isOptional,
3333
attributes: $attributes,
3434
);
3535
}

libs/types/src/Shape/ClassConstMaskFieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ final class ClassConstMaskFieldNode extends ExplicitFieldNode
2323
public function __construct(
2424
ClassConstMaskNode $key,
2525
TypeNode $type,
26-
bool $optional = false,
26+
bool $isOptional = false,
2727
?AttributeGroupListNode $attributes = null,
2828
) {
2929
parent::__construct(
3030
key: $key,
3131
type: $type,
32-
optional: $optional,
32+
isOptional: $isOptional,
3333
attributes: $attributes,
3434
);
3535
}

libs/types/src/Shape/ConstMaskFieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ final class ConstMaskFieldNode extends ExplicitFieldNode
2020
public function __construct(
2121
ConstMaskNode $key,
2222
TypeNode $type,
23-
bool $optional = false,
23+
bool $isOptional = false,
2424
?AttributeGroupListNode $attributes = null,
2525
) {
2626
parent::__construct(
2727
key: $key,
2828
type: $type,
29-
optional: $optional,
29+
isOptional: $isOptional,
3030
attributes: $attributes,
3131
);
3232
}

libs/types/src/Shape/ExplicitFieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public function __construct(
2525
*/
2626
public mixed $key,
2727
TypeNode $type,
28-
bool $optional = false,
28+
bool $isOptional = false,
2929
?AttributeGroupListNode $attributes = null,
3030
) {
3131
parent::__construct(
3232
type: $type,
33-
optional: $optional,
33+
isOptional: $isOptional,
3434
attributes: $attributes,
3535
);
3636
}

libs/types/src/Shape/FieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ abstract class FieldNode extends Node implements \Stringable
1212
{
1313
public function __construct(
1414
public TypeNode $type,
15-
public bool $optional = false,
15+
public bool $isOptional = false,
1616
public ?AttributeGroupListNode $attributes = null,
1717
) {}
1818

1919
public function __toString(): string
2020
{
21-
return $this->optional ? 'optional' : 'required';
21+
return $this->isOptional ? 'optional' : 'required';
2222
}
2323
}

libs/types/src/Shape/NamedFieldNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ final class NamedFieldNode extends ExplicitFieldNode
2020
public function __construct(
2121
Identifier $key,
2222
TypeNode $type,
23-
bool $optional = false,
23+
bool $isOptional = false,
2424
?AttributeGroupListNode $attributes = null,
2525
) {
2626
parent::__construct(
2727
key: $key,
2828
type: $type,
29-
optional: $optional,
29+
isOptional: $isOptional,
3030
attributes: $attributes,
3131
);
3232
}

0 commit comments

Comments
 (0)