From a75164c77e66496238608bbe17296f13e92ded6a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 12 Nov 2017 15:58:24 +0100 Subject: [PATCH] Rename YYNLSTATES to numNonLeafStates --- grammar/parser.template | 4 ++-- lib/PhpParser/Parser/Php5.php | 4 ++-- lib/PhpParser/Parser/Php7.php | 4 ++-- lib/PhpParser/ParserAbstract.php | 23 ++++++++++++----------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/grammar/parser.template b/grammar/parser.template index 0237863..6166607 100644 --- a/grammar/parser.template +++ b/grammar/parser.template @@ -32,8 +32,8 @@ class #(-p) extends \PhpParser\ParserAbstract protected $defaultAction = #(YYDEFAULT); protected $unexpectedTokenRule = #(YYUNEXPECTED); - protected $YY2TBLSTATE = #(YY2TBLSTATE); - protected $YYNLSTATES = #(YYNLSTATES); + protected $YY2TBLSTATE = #(YY2TBLSTATE); + protected $numNonLeafStates = #(YYNLSTATES); protected $symbolToName = array( #listvar terminals diff --git a/lib/PhpParser/Parser/Php5.php b/lib/PhpParser/Parser/Php5.php index 0ce8549..63ebe31 100644 --- a/lib/PhpParser/Parser/Php5.php +++ b/lib/PhpParser/Parser/Php5.php @@ -26,8 +26,8 @@ class Php5 extends \PhpParser\ParserAbstract protected $defaultAction = -32766; protected $unexpectedTokenRule = 32767; - protected $YY2TBLSTATE = 404; - protected $YYNLSTATES = 669; + protected $YY2TBLSTATE = 404; + protected $numNonLeafStates = 669; protected $symbolToName = array( "EOF", diff --git a/lib/PhpParser/Parser/Php7.php b/lib/PhpParser/Parser/Php7.php index 33b4301..9bbc4fa 100644 --- a/lib/PhpParser/Parser/Php7.php +++ b/lib/PhpParser/Parser/Php7.php @@ -26,8 +26,8 @@ class Php7 extends \PhpParser\ParserAbstract protected $defaultAction = -32766; protected $unexpectedTokenRule = 32767; - protected $YY2TBLSTATE = 328; - protected $YYNLSTATES = 578; + protected $YY2TBLSTATE = 328; + protected $numNonLeafStates = 578; protected $symbolToName = array( "EOF", diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index c9bcd0d..53c43f5 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -46,7 +46,8 @@ abstract class ParserAbstract implements Parser protected $unexpectedTokenRule; protected $YY2TBLSTATE; - protected $YYNLSTATES; + /** @var int Number of non-leaf states */ + protected $numNonLeafStates; /** @var int[] Map of lexer tokens to internal symbols */ protected $tokenToSymbol; @@ -231,11 +232,11 @@ abstract class ParserAbstract implements Parser $idx = $this->actionBase[$state] + $symbol; if ((($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol) || ($state < $this->YY2TBLSTATE - && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $symbol) >= 0 + && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $symbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol)) && ($action = $this->action[$idx]) !== $this->defaultAction) { /* - * >= YYNLSTATES: shift and reduce + * >= numNonLeafStates: shift and reduce * > 0: shift * = 0: accept * < 0: reduce @@ -257,12 +258,12 @@ abstract class ParserAbstract implements Parser --$this->errorState; } - if ($action < $this->YYNLSTATES) { + if ($action < $this->numNonLeafStates) { continue; } - /* $yyn >= YYNLSTATES means shift-and-reduce */ - $rule = $action - $this->YYNLSTATES; + /* $yyn >= numNonLeafStates means shift-and-reduce */ + $rule = $action - $this->numNonLeafStates; } else { $rule = -$action; } @@ -323,7 +324,7 @@ abstract class ParserAbstract implements Parser (($idx = $this->actionBase[$state] + $this->errorSymbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $this->errorSymbol) || ($state < $this->YY2TBLSTATE - && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $this->errorSymbol) >= 0 + && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $this->errorSymbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $this->errorSymbol) ) || ($action = $this->action[$idx]) === $this->defaultAction) { // Not totally sure about this if ($stackPos <= 0) { @@ -356,12 +357,12 @@ abstract class ParserAbstract implements Parser } } - if ($state < $this->YYNLSTATES) { + if ($state < $this->numNonLeafStates) { break; } - /* >= YYNLSTATES means shift-and-reduce */ - $rule = $state - $this->YYNLSTATES; + /* >= numNonLeafStates means shift-and-reduce */ + $rule = $state - $this->numNonLeafStates; } } @@ -404,7 +405,7 @@ abstract class ParserAbstract implements Parser $idx = $base + $symbol; if ($idx >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol || $state < $this->YY2TBLSTATE - && ($idx = $this->actionBase[$state + $this->YYNLSTATES] + $symbol) >= 0 + && ($idx = $this->actionBase[$state + $this->numNonLeafStates] + $symbol) >= 0 && $idx < $this->actionTableSize && $this->actionCheck[$idx] === $symbol ) { if ($this->action[$idx] !== $this->unexpectedTokenRule