diff --git a/grammar/zend_language_parser.phpy b/grammar/zend_language_parser.phpy index 346d83a..5be5fda 100644 --- a/grammar/zend_language_parser.phpy +++ b/grammar/zend_language_parser.phpy @@ -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)]; } ; diff --git a/lib/PHPParser/Node/Scalar/String.php b/lib/PHPParser/Node/Scalar/String.php index 88dead5..d9dcffe 100644 --- a/lib/PHPParser/Node/Scalar/String.php +++ b/lib/PHPParser/Node/Scalar/String.php @@ -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 ); diff --git a/lib/PHPParser/Parser.php b/lib/PHPParser/Parser.php index 57f72a2..ba2ac98 100644 --- a/lib/PHPParser/Parser.php +++ b/lib/PHPParser/Parser.php @@ -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) { diff --git a/lib/PHPParser/ParserDebug.php b/lib/PHPParser/ParserDebug.php index 7b52286..d977c41 100644 --- a/lib/PHPParser/ParserDebug.php +++ b/lib/PHPParser/ParserDebug.php @@ -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) { diff --git a/lib/PHPParser/PrettyPrinter/Zend.php b/lib/PHPParser/PrettyPrinter/Zend.php index 659824d..bc395a3 100644 --- a/lib/PHPParser/PrettyPrinter/Zend.php +++ b/lib/PHPParser/PrettyPrinter/Zend.php @@ -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) { diff --git a/test/Unit/NodeTraverserTest.php b/test/Unit/NodeTraverserTest.php index 539f572..d2c0f95 100644 --- a/test/Unit/NodeTraverserTest.php +++ b/test/Unit/NodeTraverserTest.php @@ -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 )) ) )),