mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 15:18:17 +01:00
Scalar_String::create() -> Scalar_String::parse()
Directly creating the node isn't necessary anymore, the token only needs to be parsed. This makes it consistent with the other scalar parsing methods and removes the need to pass $arguments around.
This commit is contained in:
parent
9d8e13b4a9
commit
9e43acee2c
@ -611,7 +611,7 @@ array_expr:
|
||||
scalar_dereference:
|
||||
array_expr '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
|
||||
{ $$ = Expr_ArrayDimFetch[Scalar_String::create($1, $attributes), $3]; }
|
||||
{ $$ = Expr_ArrayDimFetch[Scalar_String[Scalar_String::parse($1)], $3]; }
|
||||
| scalar_dereference '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; }
|
||||
/* alternative array syntax missing intentionally */
|
||||
;
|
||||
@ -716,7 +716,7 @@ ctor_arguments:
|
||||
common_scalar:
|
||||
T_LNUMBER { $$ = Scalar_LNumber[Scalar_LNumber::parse($1)]; }
|
||||
| T_DNUMBER { $$ = Scalar_DNumber[Scalar_DNumber::parse($1)]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar_String::create($1, $attributes); }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar_String[Scalar_String::parse($1)]; }
|
||||
| T_LINE { $$ = Scalar_LineConst[]; }
|
||||
| T_FILE { $$ = Scalar_FileConst[]; }
|
||||
| T_DIR { $$ = Scalar_DirConst[]; }
|
||||
|
@ -32,30 +32,27 @@ class PHPParser_Node_Scalar_String extends PHPParser_Node_Scalar
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a String node from a string token (parses escape sequences).
|
||||
* Parses a string token.
|
||||
*
|
||||
* @param string $str String
|
||||
* @param array $attributes Additional attributes
|
||||
* @param string $str String token content
|
||||
*
|
||||
* @return PHPParser_Node_Scalar_String String Node
|
||||
* @return string The parsed string
|
||||
*/
|
||||
public static function create($str, array $attributes = array()) {
|
||||
public static function parse($str) {
|
||||
$bLength = 0;
|
||||
if ('b' === $str[0]) {
|
||||
$bLength = 1;
|
||||
}
|
||||
|
||||
if ('\'' === $str[$bLength]) {
|
||||
$str = str_replace(
|
||||
return str_replace(
|
||||
array('\\\\', '\\\''),
|
||||
array( '\\', '\''),
|
||||
substr($str, $bLength + 1, -1)
|
||||
);
|
||||
} else {
|
||||
$str = self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
|
||||
return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
|
||||
}
|
||||
|
||||
return new self($str, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2147,7 +2147,7 @@ class PHPParser_Parser
|
||||
}
|
||||
|
||||
protected function yyn267($attributes) {
|
||||
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(PHPParser_Node_Scalar_String::create($this->yyastk[$this->stackPos-(4-1)], $attributes), $this->yyastk[$this->stackPos-(4-3)], $attributes);
|
||||
$this->yyval = new PHPParser_Node_Expr_ArrayDimFetch(new PHPParser_Node_Scalar_String(PHPParser_Node_Scalar_String::parse($this->yyastk[$this->stackPos-(4-1)]), $attributes), $this->yyastk[$this->stackPos-(4-3)], $attributes);
|
||||
}
|
||||
|
||||
protected function yyn268($attributes) {
|
||||
@ -2321,7 +2321,7 @@ class PHPParser_Parser
|
||||
}
|
||||
|
||||
protected function yyn307($attributes) {
|
||||
$this->yyval = PHPParser_Node_Scalar_String::create($this->yyastk[$this->stackPos-(1-1)], $attributes);
|
||||
$this->yyval = new PHPParser_Node_Scalar_String(PHPParser_Node_Scalar_String::parse($this->yyastk[$this->stackPos-(1-1)]), $attributes);
|
||||
}
|
||||
|
||||
protected function yyn308($attributes) {
|
||||
|
@ -13,12 +13,12 @@ class PHPParser_Tests_Node_Scalar_StringTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestCreate
|
||||
* @dataProvider provideTestParse
|
||||
*/
|
||||
public function testCreate($expected, $string) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
PHPParser_Node_Scalar_String::create($string)->value
|
||||
PHPParser_Node_Scalar_String::parse($string)
|
||||
);
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ class PHPParser_Tests_Node_Scalar_StringTest extends PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function provideTestCreate() {
|
||||
public function provideTestParse() {
|
||||
$tests = array(
|
||||
array('A', '\'A\''),
|
||||
array('A', 'b\'A\''),
|
||||
|
Loading…
x
Reference in New Issue
Block a user