Merge Node_Name and Node_Name_Normal

This commit is contained in:
nikic 2011-09-24 18:05:14 +02:00
parent df7cb44eed
commit d5f148b43f
6 changed files with 44 additions and 52 deletions

View File

@ -558,12 +558,12 @@ function_call:
;
class_name:
T_STATIC { $$ = Name_Normal['static']; }
T_STATIC { $$ = Name['static']; }
| name { $$ = $1; }
;
name:
namespace_name { $$ = Name_Normal[$1]; }
namespace_name { $$ = Name[$1]; }
| T_NS_SEPARATOR namespace_name { $$ = Name_FullyQualified[$2]; }
| T_NAMESPACE T_NS_SEPARATOR namespace_name { $$ = Name_Relative[$3]; }
;

View File

@ -43,6 +43,42 @@ class PHPParser_Node_Name extends PHPParser_NodeAbstract
return $this->parts[count($this->parts) - 1];
}
/**
* Checks whether the name is unqualified. (E.g. Name)
*
* @return bool Whether the name is unqualified
*/
public function isUnqualified() {
return 1 == count($this->parts);
}
/**
* Checks whether the name is qualified. (E.g. Name\Name)
*
* @return bool Whether the name is qualified
*/
public function isQualified() {
return 1 < count($this->parts);
}
/**
* Checks whether the name is fully qualified. (E.g. \Name)
*
* @return bool Whether the name is fully qualified
*/
public function isFullyQualified() {
return false;
}
/**
* Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
*
* @return bool Whether the name is relative
*/
public function isRelative() {
return false;
}
/**
* Returns a string representation of the name by imploding the namespace parts with a separator.
*

View File

@ -1,40 +0,0 @@
<?php
class PHPParser_Node_Name_Normal extends PHPParser_Node_Name
{
/**
* Checks whether the name is unqualified. (E.g. Name)
*
* @return bool Whether the name is unqualified
*/
public function isUnqualified() {
return 1 == count($this->parts);
}
/**
* Checks whether the name is qualified. (E.g. Name\Name)
*
* @return bool Whether the name is qualified
*/
public function isQualified() {
return 1 < count($this->parts);
}
/**
* Checks whether the name is fully qualified. (E.g. \Name)
*
* @return bool Whether the name is fully qualified
*/
public function isFullyQualified() {
return false;
}
/**
* Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
*
* @return bool Whether the name is relative
*/
public function isRelative() {
return false;
}
}

View File

@ -7,26 +7,26 @@ interface PHPParser_NodeVisitorInterface
*
* @param $node
*/
public function beforeTraverse(&$node);
public function beforeTraverse($node);
/**
* Called when entering a node.
*
* @param PHPParser_Node $node
*/
public function enterNode(PHPParser_Node &$node);
public function enterNode(PHPParser_Node $node);
/**
* Called when leaving a node.
*
* @param PHPParser_Node $node
*/
public function leaveNode(PHPParser_Node &$node);
public function leaveNode(PHPParser_Node $node);
/**
* Called once after traversal.
*
* @param $node
*/
public function afterTraverse(&$node);
public function afterTraverse($node);
}

View File

@ -1956,7 +1956,7 @@ class PHPParser_Parser
}
protected function yyn241($line, $docComment) {
$this->yyval = new PHPParser_Node_Name_Normal('static', $line, $docComment);
$this->yyval = new PHPParser_Node_Name('static', $line, $docComment);
}
protected function yyn242($line, $docComment) {
@ -1964,7 +1964,7 @@ class PHPParser_Parser
}
protected function yyn243($line, $docComment) {
$this->yyval = new PHPParser_Node_Name_Normal($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
$this->yyval = new PHPParser_Node_Name($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
}
protected function yyn244($line, $docComment) {

View File

@ -25,10 +25,6 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
return implode('\\', $node->parts);
}
public function pName_Normal(PHPParser_Node_Name_Normal $node) {
return implode('\\', $node->parts);
}
public function pName_FullyQualified(PHPParser_Node_Name_FullyQualified $node) {
return '\\' . implode('\\', $node->parts);
}