3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
23 * Stack class to help Preprocessor::preprocessToObj()
27 /** @var PPDStackElement[] */
32 * @var PPDStackElement|false
36 public $elementClass = PPDStackElement
::class;
38 public static $false = false;
40 public function __construct() {
43 $this->rootAccum
= '';
44 $this->accum
=& $this->rootAccum
;
50 public function count() {
51 return count( $this->stack
);
54 public function &getAccum() {
59 * @return bool|PPDPart
61 public function getCurrentPart() {
62 if ( $this->top
=== false ) {
65 return $this->top
->getCurrentPart();
69 public function push( $data ) {
70 if ( $data instanceof $this->elementClass
) {
71 $this->stack
[] = $data;
73 $class = $this->elementClass
;
74 $this->stack
[] = new $class( $data );
76 $this->top
= $this->stack
[count( $this->stack
) - 1];
77 $this->accum
=& $this->top
->getAccum();
80 public function pop() {
81 if ( $this->stack
=== [] ) {
82 throw new MWException( __METHOD__
. ': no elements remaining' );
84 $temp = array_pop( $this->stack
);
86 if ( count( $this->stack
) ) {
87 $this->top
= $this->stack
[count( $this->stack
) - 1];
88 $this->accum
=& $this->top
->getAccum();
90 $this->top
= self
::$false;
91 $this->accum
=& $this->rootAccum
;
96 public function addPart( $s = '' ) {
97 $this->top
->addPart( $s );
98 $this->accum
=& $this->top
->getAccum();
104 public function getFlags() {
105 if ( $this->stack
=== [] ) {
107 'findEquals' => false,
109 'inHeading' => false,
112 return $this->top
->getFlags();