mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Add shared Node_Const
Node_Const is shared between Node_Stmt_ClassConst and Node_Stmt_Const. Maybe one could generalize it to a Node_NameToValue to share it with Node_Stmt_Declare too.
This commit is contained in:
parent
8bd8e815c9
commit
858545732c
@ -131,7 +131,7 @@ top_statement:
|
||||
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = Stmt_Namespace[name: $2, stmts: $4]; }
|
||||
| T_NAMESPACE '{' top_statement_list '}' { $$ = Stmt_Namespace[name: null, stmts: $3]; }
|
||||
| T_USE use_declarations ';' { $$ = Stmt_Use[$2]; }
|
||||
| constant_declaration ';' { $$ = Stmt_Const[$1]; }
|
||||
| T_CONST constant_declaration_list ';' { $$ = Stmt_Const[$2]; }
|
||||
;
|
||||
|
||||
use_declarations:
|
||||
@ -146,9 +146,13 @@ use_declaration:
|
||||
| T_NS_SEPARATOR namespace_name T_AS T_STRING { $$ = Stmt_UseUse[name: $2, alias: $4]; }
|
||||
;
|
||||
|
||||
constant_declaration_list:
|
||||
constant_declaration_list ',' constant_declaration { push($1, $3); }
|
||||
| constant_declaration { init($1); }
|
||||
;
|
||||
|
||||
constant_declaration:
|
||||
constant_declaration ',' T_STRING '=' static_scalar { push($1, Stmt_ConstConst[name: $3, value: $5]); }
|
||||
| T_CONST T_STRING '=' static_scalar { init(Stmt_ConstConst[name: $2, value: $4]); }
|
||||
T_STRING '=' static_scalar { $$ = Const[$1, $3]; }
|
||||
;
|
||||
|
||||
inner_statement_list:
|
||||
@ -384,7 +388,7 @@ class_statement_list:
|
||||
|
||||
class_statement:
|
||||
variable_modifiers class_variable_declaration ';' { $$ = Stmt_Property[type: $1, props: $2]; }
|
||||
| class_constant_declaration ';' { $$ = Stmt_ClassConst[$1]; }
|
||||
| T_CONST constant_declaration_list ';' { $$ = Stmt_ClassConst[$2]; }
|
||||
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
|
||||
{ $$ = Stmt_ClassMethod[type: $1, byRef: $3, name: $4, params: $6, stmts: $8]; }
|
||||
;
|
||||
@ -429,12 +433,6 @@ class_variable_declaration:
|
||||
{ init(Stmt_PropertyProperty[name: parseVar($1), default: $3]); }
|
||||
;
|
||||
|
||||
class_constant_declaration:
|
||||
class_constant_declaration ',' T_STRING '=' static_scalar
|
||||
{ push($1, Stmt_ClassConstConst[name: $3, value: $5]); }
|
||||
| T_CONST T_STRING '=' static_scalar { init(Stmt_ClassConstConst[name: $2, value: $4]); }
|
||||
;
|
||||
|
||||
expr_list:
|
||||
expr_list ',' expr { push($1, $3); }
|
||||
| expr { init($1); }
|
||||
|
26
lib/PHPParser/Node/Const.php
Normal file
26
lib/PHPParser/Node/Const.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property string $name Name
|
||||
* @property PHPParser_Node_Expr $value Value
|
||||
*/
|
||||
class PHPParser_Node_Const extends PHPParser_NodeAbstract
|
||||
{
|
||||
/**
|
||||
* Constructs a const node for use in class const and const statements.
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param PHPParser_Node_Expr $value Value
|
||||
* @param int $line Line
|
||||
* @param null|string $docComment Nearest doc comment
|
||||
*/
|
||||
public function __construct($name, PHPParser_Node_Expr $value, $line = -1, $docComment = null) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
),
|
||||
$line, $docComment
|
||||
);
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property PHPParser_Node_Stmt_ClassConstConst[] $consts Constant declarations
|
||||
* @property PHPParser_Node_Const[] $consts Constant declarations
|
||||
*/
|
||||
class PHPParser_Node_Stmt_ClassConst extends PHPParser_Node_Stmt
|
||||
{
|
||||
/**
|
||||
* Constructs a class const list node.
|
||||
*
|
||||
* @param PHPParser_Node_Stmt_ClassConstConst[] $consts Constant declarations
|
||||
* @param int $line Line
|
||||
* @param null|string $docComment Nearest doc comment
|
||||
* @param PHPParser_Node_Const[] $consts Constant declarations
|
||||
* @param int $line Line
|
||||
* @param null|string $docComment Nearest doc comment
|
||||
*/
|
||||
public function __construct(array $consts, $line = -1, $docComment = null) {
|
||||
parent::__construct(
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property string $name Name
|
||||
* @property PHPParser_Node_Expr $value Value
|
||||
*/
|
||||
class PHPParser_Node_Stmt_ClassConstConst extends PHPParser_Node_Stmt
|
||||
{
|
||||
}
|
@ -1,8 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property array $consts Constant declarations
|
||||
* @property PHPParser_Node_Const[] $consts Constant declarations
|
||||
*/
|
||||
class PHPParser_Node_Stmt_Const extends PHPParser_Node_Stmt
|
||||
{
|
||||
/**
|
||||
* Constructs a const list node.
|
||||
*
|
||||
* @param PHPParser_Node_Const[] $consts Constant declarations
|
||||
* @param int $line Line
|
||||
* @param null|string $docComment Nearest doc comment
|
||||
*/
|
||||
public function __construct(array $consts, $line = -1, $docComment = null) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'consts' => $consts,
|
||||
),
|
||||
$line, $docComment
|
||||
);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property string $name Name
|
||||
* @property PHPParser_Node_Expr $value Value
|
||||
*/
|
||||
class PHPParser_Node_Stmt_ConstConst extends PHPParser_Node_Stmt
|
||||
{
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -22,15 +22,16 @@ class PHPParser_Parser_Debug extends PHPParser_Parser
|
||||
"top_statement : T_NAMESPACE namespace_name '{' top_statement_list '}'",
|
||||
"top_statement : T_NAMESPACE '{' top_statement_list '}'",
|
||||
"top_statement : T_USE use_declarations ';'",
|
||||
"top_statement : constant_declaration ';'",
|
||||
"top_statement : T_CONST constant_declaration_list ';'",
|
||||
"use_declarations : use_declarations ',' use_declaration",
|
||||
"use_declarations : use_declaration",
|
||||
"use_declaration : namespace_name",
|
||||
"use_declaration : namespace_name T_AS T_STRING",
|
||||
"use_declaration : T_NS_SEPARATOR namespace_name",
|
||||
"use_declaration : T_NS_SEPARATOR namespace_name T_AS T_STRING",
|
||||
"constant_declaration : constant_declaration ',' T_STRING '=' static_scalar",
|
||||
"constant_declaration : T_CONST T_STRING '=' static_scalar",
|
||||
"constant_declaration_list : constant_declaration_list ',' constant_declaration",
|
||||
"constant_declaration_list : constant_declaration",
|
||||
"constant_declaration : T_STRING '=' static_scalar",
|
||||
"inner_statement_list : inner_statement_list inner_statement",
|
||||
"inner_statement_list : /* empty */",
|
||||
"inner_statement : statement",
|
||||
@ -140,7 +141,7 @@ class PHPParser_Parser_Debug extends PHPParser_Parser
|
||||
"class_statement_list : class_statement_list class_statement",
|
||||
"class_statement_list : /* empty */",
|
||||
"class_statement : variable_modifiers class_variable_declaration ';'",
|
||||
"class_statement : class_constant_declaration ';'",
|
||||
"class_statement : T_CONST constant_declaration_list ';'",
|
||||
"class_statement : method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body",
|
||||
"method_body : ';'",
|
||||
"method_body : '{' inner_statement_list '}'",
|
||||
@ -160,8 +161,6 @@ class PHPParser_Parser_Debug extends PHPParser_Parser
|
||||
"class_variable_declaration : class_variable_declaration ',' T_VARIABLE '=' static_scalar",
|
||||
"class_variable_declaration : T_VARIABLE",
|
||||
"class_variable_declaration : T_VARIABLE '=' static_scalar",
|
||||
"class_constant_declaration : class_constant_declaration ',' T_STRING '=' static_scalar",
|
||||
"class_constant_declaration : T_CONST T_STRING '=' static_scalar",
|
||||
"expr_list : expr_list ',' expr",
|
||||
"expr_list : expr",
|
||||
"for_expr : /* empty */",
|
||||
|
@ -20,6 +20,10 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
|
||||
return ($node->byRef ? '&' : '') . $this->p($node->value);
|
||||
}
|
||||
|
||||
public function pConst(PHPParser_Node_Const $node) {
|
||||
return $node->name . ' = ' . $this->p($node->value);
|
||||
}
|
||||
|
||||
// Magic Constants
|
||||
|
||||
public function pScalar_ClassConst(PHPParser_Node_Scalar_ClassConst $node) {
|
||||
@ -477,10 +481,6 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
|
||||
return 'const ' . $this->pCommaSeparated($node->consts) . ';';
|
||||
}
|
||||
|
||||
public function pStmt_ClassConstConst(PHPParser_Node_Stmt_ClassConstConst $node) {
|
||||
return $node->name . ' = ' . $this->p($node->value);
|
||||
}
|
||||
|
||||
public function pStmt_Func(PHPParser_Node_Stmt_Func $node) {
|
||||
return 'function ' . ($node->byRef ? '&' : '') . $node->name
|
||||
. '(' . $this->pCommaSeparated($node->params) . ')'
|
||||
@ -491,10 +491,6 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
|
||||
return 'const ' . $this->pCommaSeparated($node->consts) . ';';
|
||||
}
|
||||
|
||||
public function pStmt_ConstConst(PHPParser_Node_Stmt_ConstConst $node) {
|
||||
return $node->name . ' = ' . $this->p($node->value);
|
||||
}
|
||||
|
||||
public function pStmt_Declare(PHPParser_Node_Stmt_Declare $node) {
|
||||
return 'declare (' . $this->pCommaSeparated($node->declares) . ') {'
|
||||
. "\n" . $this->pStmts($node->stmts) . "\n" . '}';
|
||||
|
Loading…
Reference in New Issue
Block a user