Skip to content

Commit 8847ae4

Browse files
author
Kirill Nesmeyanov
committed
Rename callable "arguments" to "parameters" and make type optional
1 parent 3774757 commit 8847ae4

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

resources/grammar.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,18 @@
249249
48 => function (\Phplrt\Parser\Context $ctx, $children) {
250250
$name = \array_shift($children);
251251

252-
$arguments = isset($children[0]) && $children[0] instanceof Node\Stmt\Callable\ArgumentsListNode
252+
$parameters = isset($children[0]) && $children[0] instanceof Node\Stmt\Callable\ParametersListNode
253253
? \array_shift($children)
254-
: new Node\Stmt\Callable\ArgumentsListNode();
254+
: new Node\Stmt\Callable\ParametersListNode();
255255

256256
return new Node\Stmt\CallableTypeNode(
257257
name: $name,
258-
arguments: $arguments,
258+
parameters: $parameters,
259259
type: isset($children[0]) ? $children[0] : null,
260260
);
261261
},
262262
42 => function (\Phplrt\Parser\Context $ctx, $children) {
263-
return new Node\Stmt\Callable\ArgumentsListNode($children);
263+
return new Node\Stmt\Callable\ParametersListNode($children);
264264
},
265265
49 => function (\Phplrt\Parser\Context $ctx, $children) {
266266
$token = $ctx->getToken();
@@ -293,7 +293,7 @@
293293
return $children[0];
294294
}
295295

296-
if ($children[0] instanceof Node\Stmt\Callable\ArgumentNode) {
296+
if ($children[0] instanceof Node\Stmt\Callable\ParameterNode) {
297297
$children[0]->variadic = true;
298298
return $children[0];
299299
}
@@ -302,7 +302,7 @@
302302
return $children[1];
303303
},
304304
60 => function (\Phplrt\Parser\Context $ctx, $children) {
305-
$argument = new Node\Stmt\Callable\ArgumentNode($children[0]);
305+
$argument = new Node\Stmt\Callable\ParameterNode($children[0]);
306306

307307
if (\count($children) !== 1) {
308308
$argument->output = true;

resources/grammar/callable.pp2

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
CallableType -> {
33
$name = \array_shift($children);
44

5-
$arguments = isset($children[0]) && $children[0] instanceof Node\Stmt\Callable\ArgumentsListNode
5+
$parameters = isset($children[0]) && $children[0] instanceof Node\Stmt\Callable\ParametersListNode
66
? \array_shift($children)
7-
: new Node\Stmt\Callable\ArgumentsListNode();
7+
: new Node\Stmt\Callable\ParametersListNode();
88

99
return new Node\Stmt\CallableTypeNode(
1010
name: $name,
11-
arguments: $arguments,
11+
parameters: $parameters,
1212
type: isset($children[0]) ? $children[0] : null,
1313
);
1414
}
1515
: Name()
1616
::T_PARENTHESIS_OPEN::
17-
CallableArguments()?
17+
CallableParameters()?
1818
::T_PARENTHESIS_CLOSE::
1919
CallableReturnType()?
2020
;
2121

22-
CallableArguments -> {
23-
return new Node\Stmt\Callable\ArgumentsListNode($children);
22+
CallableParameters -> {
23+
return new Node\Stmt\Callable\ParametersListNode($children);
2424
}
25-
: OptionalCallableArgument() (::T_COMMA:: OptionalCallableArgument())* ::T_COMMA::?
25+
: OptionalCallableParameter() (::T_COMMA:: OptionalCallableParameter())* ::T_COMMA::?
2626
;
2727

28-
OptionalCallableArgument -> {
28+
OptionalCallableParameter -> {
2929
if (!isset($children[1])) {
3030
return $children[0];
3131
}
@@ -41,39 +41,39 @@ OptionalCallableArgument -> {
4141
$children[0]->optional = true;
4242
return $children[0];
4343
}
44-
: NamedCallableArgument() <T_ASSIGN>?
44+
: NamedCallableParameter() <T_ASSIGN>?
4545
;
4646

47-
NamedCallableArgument -> {
47+
NamedCallableParameter -> {
4848
if (\count($children) === 1) {
4949
return $children[0];
5050
}
5151

5252
$children[0]->name = $children[1];
5353
return $children[0];
5454
}
55-
: VariadicCallableArgument() VariableLiteral()?
55+
: VariadicCallableParameter() VariableLiteral()?
5656
;
5757

58-
VariadicCallableArgument -> {
58+
VariadicCallableParameter -> {
5959
if (!isset($children[1])) {
6060
return $children[0];
6161
}
6262

63-
if ($children[0] instanceof Node\Stmt\Callable\ArgumentNode) {
63+
if ($children[0] instanceof Node\Stmt\Callable\ParameterNode) {
6464
$children[0]->variadic = true;
6565
return $children[0];
6666
}
6767

6868
$children[1]->variadic = true;
6969
return $children[1];
7070
}
71-
: <T_ELLIPSIS> OutputCallableArgument() // Prefixed variadic argument (Psalm format)
72-
| OutputCallableArgument() <T_ELLIPSIS>? // Suffixed variadic argument (PhpStan + Psalm)
71+
: <T_ELLIPSIS> OutputCallableParameter() // Prefixed variadic argument (Psalm format)
72+
| OutputCallableParameter() <T_ELLIPSIS>? // Suffixed variadic argument (PhpStan + Psalm)
7373
;
7474

75-
OutputCallableArgument -> {
76-
$argument = new Node\Stmt\Callable\ArgumentNode($children[0]);
75+
OutputCallableParameter -> {
76+
$argument = new Node\Stmt\Callable\ParameterNode($children[0]);
7777

7878
if (\count($children) !== 1) {
7979
$argument->output = true;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
use TypeLang\Parser\Node\Node;
99
use TypeLang\Parser\Node\Stmt\TypeStatement;
1010

11-
final class ArgumentNode extends Node implements \Stringable
11+
final class ParameterNode extends Node implements \Stringable
1212
{
1313
public function __construct(
14-
public readonly TypeStatement $type,
14+
public ?TypeStatement $type = null,
1515
public ?VariableLiteralNode $name = null,
1616
public bool $output = false,
1717
public bool $variadic = false,
@@ -23,7 +23,7 @@ public function is(string $class): bool
2323
return $this instanceof $class;
2424
}
2525

26-
public function getType(): TypeStatement
26+
public function getType(): ?TypeStatement
2727
{
2828
return $this->type;
2929
}

src/Node/Stmt/Callable/ArgumentsListNode.php renamed to src/Node/Stmt/Callable/ParametersListNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use TypeLang\Parser\Node\NodeList;
88

99
/**
10-
* @template-extends NodeList<ArgumentNode>
10+
* @template-extends NodeList<ParameterNode>
1111
*/
12-
class ArgumentsListNode extends NodeList {}
12+
class ParametersListNode extends NodeList {}

src/Node/Stmt/CallableTypeNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace TypeLang\Parser\Node\Stmt;
66

77
use TypeLang\Parser\Node\Name;
8-
use TypeLang\Parser\Node\Stmt\Callable\ArgumentsListNode;
8+
use TypeLang\Parser\Node\Stmt\Callable\ParametersListNode;
99

1010
class CallableTypeNode extends TypeStatement
1111
{
1212
public function __construct(
1313
public readonly Name $name,
14-
public readonly ArgumentsListNode $arguments = new ArgumentsListNode(),
14+
public readonly ParametersListNode $parameters = new ParametersListNode(),
1515
public readonly ?TypeStatement $type = null,
1616
) {}
1717
}

0 commit comments

Comments
 (0)