[API] Rename LambdaFunc to Closure

The term "closure" is more commonly used in PHP, even if the function doesn't use() any variables.
This commit is contained in:
nikic 2011-10-26 18:34:12 +02:00
parent 734dbecbc9
commit 25f37ccc28
6 changed files with 41 additions and 41 deletions

View File

@ -522,7 +522,7 @@ expr:
| '`' backticks_expr '`' { $$ = Expr_ShellExec[$2]; }
| T_PRINT expr { $$ = Expr_Print[$2]; }
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
{ $$ = Expr_LambdaFunc[$8, $4, $6, $2]; }
{ $$ = Expr_Closure[$8, $4, $6, $2]; }
;
lexical_vars:
@ -532,9 +532,9 @@ lexical_vars:
lexical_var_list:
lexical_var_list ',' optional_ref T_VARIABLE
{ push($1, Expr_LambdaFuncUse[parseVar($4), $3]); }
{ push($1, Expr_ClosureUse[parseVar($4), $3]); }
| optional_ref T_VARIABLE
{ init(Expr_LambdaFuncUse[parseVar($2), $1]); }
{ init(Expr_ClosureUse[parseVar($2), $1]); }
;
function_call:

View File

@ -0,0 +1,32 @@
<?php
/**
* @property PHPParser_Node[] $stmts Statements
* @property PHPParser_Node_Stmt_FuncParam[] $params Parameters
* @property PHPParser_Node_Expr_ClosureUse[] $uses use()s
* @property bool $byRef Whether to return by reference
*/
class PHPParser_Node_Expr_Closure extends PHPParser_Node_Expr
{
/**
* Constructs a lambda function node.
*
* @param PHPParser_Node[] $stmts Statements
* @param PHPParser_Node_Stmt_FuncParam[] $params Parameters
* @param PHPParser_Node_Expr_ClosureUse[] $uses use()s
* @param bool $byRef Whether to return by reference
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $stmts, array $params = array(), array $uses = array(), $byRef = false, $line = -1, $docComment = null) {
parent::__construct(
array(
'stmts' => $stmts,
'params' => $params,
'uses' => $uses,
'byRef' => $byRef
),
$line, $docComment
);
}
}

View File

@ -4,7 +4,7 @@
* @property string $var Name of variable
* @property bool $byRef Whether to use by reference
*/
class PHPParser_Node_Expr_LambdaFuncUse extends PHPParser_Node_Expr
class PHPParser_Node_Expr_ClosureUse extends PHPParser_Node_Expr
{
/**
* Constructs a closure use node.

View File

@ -1,32 +0,0 @@
<?php
/**
* @property PHPParser_Node[] $stmts Statements
* @property PHPParser_Node_Stmt_FuncParam[] $params Parameters
* @property PHPParser_Node_Expr_LambdaFuncUse[] $uses use()s
* @property bool $byRef Whether to return by reference
*/
class PHPParser_Node_Expr_LambdaFunc extends PHPParser_Node_Expr
{
/**
* Constructs a lambda function node.
*
* @param PHPParser_Node[] $stmts Statements
* @param PHPParser_Node_Stmt_FuncParam[] $params Parameters
* @param PHPParser_Node_Expr_LambdaFuncUse[] $uses use()s
* @param bool $byRef Whether to return by reference
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $stmts, array $params = array(), array $uses = array(), $byRef = false, $line = -1, $docComment = null) {
parent::__construct(
array(
'stmts' => $stmts,
'params' => $params,
'uses' => $uses,
'byRef' => $byRef
),
$line, $docComment
);
}
}

View File

@ -1907,7 +1907,7 @@ class PHPParser_Parser
}
protected function yyn233($line, $docComment) {
$this->yyval = new PHPParser_Node_Expr_LambdaFunc($this->yyastk[$this->yysp-(9-8)], $this->yyastk[$this->yysp-(9-4)], $this->yyastk[$this->yysp-(9-6)], $this->yyastk[$this->yysp-(9-2)], $line, $docComment);
$this->yyval = new PHPParser_Node_Expr_Closure($this->yyastk[$this->yysp-(9-8)], $this->yyastk[$this->yysp-(9-4)], $this->yyastk[$this->yysp-(9-6)], $this->yyastk[$this->yysp-(9-2)], $line, $docComment);
}
protected function yyn234($line, $docComment) {
@ -1919,11 +1919,11 @@ class PHPParser_Parser
}
protected function yyn236($line, $docComment) {
$this->yyastk[$this->yysp-(4-1)][] = new PHPParser_Node_Expr_LambdaFuncUse(substr($this->yyastk[$this->yysp-(4-4)], 1), $this->yyastk[$this->yysp-(4-3)], $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(4-1)];
$this->yyastk[$this->yysp-(4-1)][] = new PHPParser_Node_Expr_ClosureUse(substr($this->yyastk[$this->yysp-(4-4)], 1), $this->yyastk[$this->yysp-(4-3)], $line, $docComment); $this->yyval = $this->yyastk[$this->yysp-(4-1)];
}
protected function yyn237($line, $docComment) {
$this->yyval = array(new PHPParser_Node_Expr_LambdaFuncUse(substr($this->yyastk[$this->yysp-(2-2)], 1), $this->yyastk[$this->yysp-(2-1)], $line, $docComment));
$this->yyval = array(new PHPParser_Node_Expr_ClosureUse(substr($this->yyastk[$this->yysp-(2-2)], 1), $this->yyastk[$this->yysp-(2-1)], $line, $docComment));
}
protected function yyn238($line, $docComment) {

View File

@ -404,14 +404,14 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
return '`' . $this->pEncapsList($node->parts, '`') . '`';
}
public function pExpr_LambdaFunc(PHPParser_Node_Expr_LambdaFunc $node) {
public function pExpr_Closure(PHPParser_Node_Expr_Closure $node) {
return 'function ' . ($node->byRef ? '&' : '')
. '(' . $this->pCommaSeparated($node->params) . ')'
. (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': '')
. ' {' . "\n" . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pExpr_LambdaFuncUse(PHPParser_Node_Expr_LambdaFuncUse $node) {
public function pExpr_ClosureUse(PHPParser_Node_Expr_ClosureUse $node) {
return ($node->byRef ? '&' : '') . '$' . $node->var;
}