mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-27 04:24:43 +01:00
Merge branch '1.x'
Conflicts: grammar/rebuildParsers.php lib/PhpParser/Parser.php
This commit is contained in:
commit
eecaf1e93b
@ -165,7 +165,7 @@ function resolveMacros($code) {
|
||||
|
||||
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) {'
|
||||
. ' $s = Node\Scalar\String_::parseEscapeSequences($s, null, ' . $args[1] . '); } }'
|
||||
. ' $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s);'
|
||||
. ' $s = preg_replace(\'~(\r\n|\n|\r)\z~\', \'\', $s);'
|
||||
. ' if (\'\' === $s) array_pop(' . $args[0] . ');';
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ class String_ extends Scalar
|
||||
*/
|
||||
public static function parseDocString($startToken, $str, $parseUnicodeEscape = true) {
|
||||
// strip last newline (thanks tokenizer for sticking it into the string!)
|
||||
$str = preg_replace('~(\r\n|\n|\r)$~', '', $str);
|
||||
$str = preg_replace('~(\r\n|\n|\r)\z~', '', $str);
|
||||
|
||||
// nowdoc string
|
||||
if (false !== strpos($startToken, '\'')) {
|
||||
|
@ -2818,7 +2818,7 @@ class Php5 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule463() {
|
||||
foreach ($this->semStack[$this->stackPos-(3-2)] as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null, false); } } $s = preg_replace('~(\r\n|\n|\r)$~', '', $s); if ('' === $s) array_pop($this->semStack[$this->stackPos-(3-2)]);; $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos-(3-2)], $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
foreach ($this->semStack[$this->stackPos-(3-2)] as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null, false); } } $s = preg_replace('~(\r\n|\n|\r)\z~', '', $s); if ('' === $s) array_pop($this->semStack[$this->stackPos-(3-2)]);; $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos-(3-2)], $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
}
|
||||
|
||||
protected function reduceRule464() {
|
||||
|
@ -2406,7 +2406,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule398() {
|
||||
foreach ($this->semStack[$this->stackPos-(3-2)] as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null, true); } } $s = preg_replace('~(\r\n|\n|\r)$~', '', $s); if ('' === $s) array_pop($this->semStack[$this->stackPos-(3-2)]);; $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos-(3-2)], $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
foreach ($this->semStack[$this->stackPos-(3-2)] as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null, true); } } $s = preg_replace('~(\r\n|\n|\r)\z~', '', $s); if ('' === $s) array_pop($this->semStack[$this->stackPos-(3-2)]);; $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos-(3-2)], $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes);
|
||||
}
|
||||
|
||||
protected function reduceRule399() {
|
||||
|
58
test/code/parser/scalar/docStringNewlines.test
Normal file
58
test/code/parser/scalar/docStringNewlines.test
Normal file
@ -0,0 +1,58 @@
|
||||
Trailing newlines in doc strings
|
||||
-----
|
||||
<?php
|
||||
|
||||
<<<'EOF'@@{ "\n\n" }@@EOF;
|
||||
<<<'EOF'@@{ "\n\n\n" }@@EOF;
|
||||
<<<'EOF'@@{ "\nFoo\n\n" }@@EOF;
|
||||
<<<EOF@@{ "\n\$var\n\n" }@@EOF;
|
||||
|
||||
<<<'EOF'@@{ "\r\n\r\n" }@@EOF;
|
||||
<<<'EOF'@@{ "\r\n\r\n\r\n" }@@EOF;
|
||||
<<<'EOF'@@{ "\r\nFoo\r\n\r\n" }@@EOF;
|
||||
<<<EOF@@{ "\r\n\$var\r\n\r\n" }@@EOF;
|
||||
|
||||
// comment to force line break before EOF
|
||||
-----
|
||||
array(
|
||||
0: Scalar_String(
|
||||
value:
|
||||
)
|
||||
1: Scalar_String(
|
||||
value:
|
||||
|
||||
)
|
||||
2: Scalar_String(
|
||||
value: Foo
|
||||
|
||||
)
|
||||
3: Scalar_Encapsed(
|
||||
parts: array(
|
||||
0: Expr_Variable(
|
||||
name: var
|
||||
)
|
||||
1:
|
||||
|
||||
)
|
||||
)
|
||||
4: Scalar_String(
|
||||
value:
|
||||
)
|
||||
5: Scalar_String(
|
||||
value:
|
||||
|
||||
)
|
||||
6: Scalar_String(
|
||||
value: Foo
|
||||
|
||||
)
|
||||
7: Scalar_Encapsed(
|
||||
parts: array(
|
||||
0: Expr_Variable(
|
||||
name: var
|
||||
)
|
||||
1:
|
||||
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user