Don't save quote type for strings anymore (as it is irrelevant for script execution)

This commit is contained in:
nikic 2011-08-09 14:12:15 +02:00
parent 7d43c02c06
commit 197b8e6967
6 changed files with 18 additions and 32 deletions

View File

@ -622,9 +622,9 @@ common_scalar:
| T_FUNC_C { $$ = Scalar_FuncConst[]; }
| T_NS_C { $$ = Scalar_NSConst[]; }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2), isBinary: false, type: '\'' === $1[3] ? Scalar_String::SINGLE_QUOTED : Scalar_String::DOUBLE_QUOTED]; }
{ $$ = Scalar_String[value: Scalar_String::parseEscapeSequences($2), isBinary: 'b' === $1[0]]; }
| T_START_HEREDOC T_END_HEREDOC
{ $$ = Scalar_String[value: '', isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
{ $$ = Scalar_String[value: '', isBinary: 'b' === $1[0]]; }
;
static_scalar: /* compile-time evaluated scalars */
@ -637,7 +637,7 @@ static_scalar: /* compile-time evaluated scalars */
;
scalar:
T_STRING_VARNAME { $$ = Scalar_String[value: $1, isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
T_STRING_VARNAME { $$ = Scalar_String[value: $1, isBinary: false]; }
| class_constant { $$ = $1; }
| name { $$ = Expr_ConstFetch[name: $1]; }
| common_scalar { $$ = $1; }
@ -776,7 +776,7 @@ encaps_var:
;
encaps_var_offset:
T_STRING { $$ = Scalar_String[value: $1, isBinary: false, type: Scalar_String::SINGLE_QUOTED]; }
T_STRING { $$ = Scalar_String[value: $1, isBinary: false]; }
| T_NUM_STRING { $$ = Scalar_LNumber[value: parseLNumber($1)]; }
| T_VARIABLE { $$ = Variable[name: parseVar($1)]; }
;

View File

@ -3,13 +3,9 @@
/**
* @property string $value String value
* @property bool $isBinary Whether the string is binary (b'')
* @property int $type Whether SINGLE_QUOTED or DOUBLE_QUOTED
*/
class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
{
const SINGLE_QUOTED = 0;
const DOUBLE_QUOTED = 1;
/**
* Creates a String node from a string token (parses escape sequences).
*
@ -24,23 +20,19 @@ class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
$isBinary = true;
}
if ('\'' === $s[0]) {
$type = self::SINGLE_QUOTED;
if ('\'' === $s[$isBinary]) {
$s = str_replace(
array('\\\\', '\\\''),
array( '\\', '\''),
substr($s, $isBinary + 1, -1)
);
} else {
$type = self::DOUBLE_QUOTED;
$s = self::parseEscapeSequences(substr($s, $isBinary + 1, -1));
}
return new self(
array(
'value' => $s, 'isBinary' => $isBinary, 'type' => $type
'value' => $s, 'isBinary' => $isBinary
),
$line
);

View File

@ -2114,11 +2114,11 @@ class PHPParser_Parser
}
private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => false, 'type' => '\'' === $this->yyastk[$this->yysp-(3-1)][3] ? PHPParser_Node_Scalar_String::SINGLE_QUOTED : PHPParser_Node_Scalar_String::DOUBLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => 'b' === $this->yyastk[$this->yysp-(3-1)][0]), $line, $docComment);
}
private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => 'b' === $this->yyastk[$this->yysp-(2-1)][0]), $line, $docComment);
}
private function yyn277($line, $docComment) {
@ -2146,7 +2146,7 @@ class PHPParser_Parser
}
private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment);
}
private function yyn284($line, $docComment) {
@ -2422,7 +2422,7 @@ class PHPParser_Parser
}
private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment);
}
private function yyn353($line, $docComment) {

View File

@ -2513,11 +2513,11 @@ class PHPParser_ParserDebug
}
private function yyn275($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => false, 'type' => '\'' === $this->yyastk[$this->yysp-(3-1)][3] ? PHPParser_Node_Scalar_String::SINGLE_QUOTED : PHPParser_Node_Scalar_String::DOUBLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => PHPParser_Node_Scalar_String::parseEscapeSequences($this->yyastk[$this->yysp-(3-2)]), 'isBinary' => 'b' === $this->yyastk[$this->yysp-(3-1)][0]), $line, $docComment);
}
private function yyn276($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => '', 'isBinary' => 'b' === $this->yyastk[$this->yysp-(2-1)][0]), $line, $docComment);
}
private function yyn277($line, $docComment) {
@ -2545,7 +2545,7 @@ class PHPParser_ParserDebug
}
private function yyn283($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment);
}
private function yyn284($line, $docComment) {
@ -2821,7 +2821,7 @@ class PHPParser_ParserDebug
}
private function yyn352($line, $docComment) {
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false, 'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED), $line, $docComment);
$this->yyval = new PHPParser_Node_Scalar_String(array('value' => $this->yyastk[$this->yysp-(1-1)], 'isBinary' => false), $line, $docComment);
}
private function yyn353($line, $docComment) {

View File

@ -53,10 +53,7 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
public function pScalar_String(PHPParser_Node_Scalar_String $node) {
return ($node->isBinary ? 'b' : '')
. (PHPParser_Node_Scalar_String::SINGLE_QUOTED === $node->type
? '\'' . $this->pSafe(addcslashes($node->value, '\'\\')) . '\''
: '"' . addcslashes($node->value, "\n\r\t\f\v$\"\\") . '"'
);
. '\'' . $this->pSafe(addcslashes($node->value, '\'\\')) . '\'';
}
public function pScalar_Encapsed(PHPParser_Node_Scalar_Encapsed $node) {

View File

@ -13,16 +13,14 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
'exprs' => array(
new PHPParser_Node_Scalar_String(array(
'value' => 'Hallo World',
'isBinary' => false,
'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED
'isBinary' => false
))
)
)),
new PHPParser_Node_Expr_Print(array(
'expr' => new PHPParser_Node_Scalar_String(array(
'value' => 'Hallo World, again!',
'isBinary' => false,
'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED
'isBinary' => false
))
)),
)
@ -83,8 +81,7 @@ class Unit_NodeTraverserTest extends PHPUnit_Framework_TestCase
'exprs' => array(
new PHPParser_Node_Scalar_String(array(
'value' => 'Foo Bar',
'isBinary' => false,
'type' => PHPParser_Node_Scalar_String::SINGLE_QUOTED
'isBinary' => false
))
)
)),