From 414adfb1468ec842f37451c6e4599ec7fcfbd1f8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 20 Jan 2017 22:29:41 +0100 Subject: [PATCH] Drop useNopStatements option --- grammar/rebuildParsers.php | 2 +- lib/PhpParser/Parser/Php5.php | 6 +++--- lib/PhpParser/Parser/Php7.php | 6 +++--- lib/PhpParser/ParserAbstract.php | 6 ------ 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/grammar/rebuildParsers.php b/grammar/rebuildParsers.php index 0b5a1d21..0c90ca3f 100644 --- a/grammar/rebuildParsers.php +++ b/grammar/rebuildParsers.php @@ -179,7 +179,7 @@ function resolveMacros($code) { assertArgs(3, $args, $name); return '$startAttributes = ' . $args[1] . ';' - . ' if ($this->useNopStatements && isset($startAttributes[\'comments\']))' + . ' if (isset($startAttributes[\'comments\']))' . ' { ' . $args[0] . ' = new Stmt\Nop($startAttributes + ' . $args[2] . '); }' . ' else { ' . $args[0] . ' = null; }'; } diff --git a/lib/PhpParser/Parser/Php5.php b/lib/PhpParser/Parser/Php5.php index 3f08f97b..c69982bc 100644 --- a/lib/PhpParser/Parser/Php5.php +++ b/lib/PhpParser/Parser/Php5.php @@ -928,7 +928,7 @@ class Php5 extends \PhpParser\ParserAbstract } protected function reduceRule4() { - $startAttributes = $this->lookaheadStartAttributes; if ($this->useNopStatements && isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; + $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; if ($nop !== null) { $this->semStack[$this->stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$this->stackPos-(1-1)]; } @@ -1409,7 +1409,7 @@ class Php5 extends \PhpParser\ParserAbstract } protected function reduceRule124() { - $startAttributes = $this->lookaheadStartAttributes; if ($this->useNopStatements && isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; + $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; if ($nop !== null) { $this->semStack[$this->stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$this->stackPos-(1-1)]; } @@ -1550,7 +1550,7 @@ class Php5 extends \PhpParser\ParserAbstract } protected function reduceRule159() { - $startAttributes = $this->startAttributeStack[$this->stackPos-(1-1)]; if ($this->useNopStatements && isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; + $startAttributes = $this->startAttributeStack[$this->stackPos-(1-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; if ($this->semValue === null) $this->semValue = array(); /* means: no statement */ } diff --git a/lib/PhpParser/Parser/Php7.php b/lib/PhpParser/Parser/Php7.php index 44312032..f180ab3c 100644 --- a/lib/PhpParser/Parser/Php7.php +++ b/lib/PhpParser/Parser/Php7.php @@ -829,7 +829,7 @@ class Php7 extends \PhpParser\ParserAbstract } protected function reduceRule4() { - $startAttributes = $this->lookaheadStartAttributes; if ($this->useNopStatements && isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; + $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; if ($nop !== null) { $this->semStack[$this->stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$this->stackPos-(1-1)]; } @@ -1310,7 +1310,7 @@ class Php7 extends \PhpParser\ParserAbstract } protected function reduceRule124() { - $startAttributes = $this->lookaheadStartAttributes; if ($this->useNopStatements && isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; + $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $nop = null; }; if ($nop !== null) { $this->semStack[$this->stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$this->stackPos-(1-1)]; } @@ -1435,7 +1435,7 @@ class Php7 extends \PhpParser\ParserAbstract } protected function reduceRule155() { - $startAttributes = $this->startAttributeStack[$this->stackPos-(1-1)]; if ($this->useNopStatements && isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; + $startAttributes = $this->startAttributeStack[$this->stackPos-(1-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; if ($this->semValue === null) $this->semValue = array(); /* means: no statement */ } diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index f4d6dd5e..f02caa13 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -114,8 +114,6 @@ abstract class ParserAbstract implements Parser /** @var bool Whether to create Identifier nodes for non-namespaced names */ protected $useIdentifierNodes; - /** @var bool Whether to use Stmt\Nop nodes */ - protected $useNopStatements; /** * Creates a parser instance. @@ -123,8 +121,6 @@ abstract class ParserAbstract implements Parser * Options: * * useIdentifierNodes (default false): Create Identifier nodes for non-namespaced names. * Otherwise plain strings will be used. - * * useNopStatements (default true): Create Stmt\Nop nodes for dangling comments at the end of - * statement lists. * * @param Lexer $lexer A lexer * @param array $options Options array. @@ -133,8 +129,6 @@ abstract class ParserAbstract implements Parser $this->lexer = $lexer; $this->errors = array(); $this->useIdentifierNodes = !empty($options['useIdentifierNodes']); - $this->useNopStatements = - isset($options['useNopStatements']) ? $options['useNopStatements'] : true; if (isset($options['throwOnError'])) { throw new \LogicException(