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[] */
30 /** @var string|array */
34 * @var PPDStackElement|false
38 public $elementClass = PPDStackElement
::class;
40 public static $false = false;
42 public function __construct() {
45 $this->rootAccum
= '';
46 $this->accum
=& $this->rootAccum
;
52 public function count() {
53 return count( $this->stack
);
56 public function &getAccum() {
61 * @return bool|PPDPart
63 public function getCurrentPart() {
64 if ( $this->top
=== false ) {
67 return $this->top
->getCurrentPart();
71 public function push( $data ) {
72 if ( $data instanceof $this->elementClass
) {
73 $this->stack
[] = $data;
75 $class = $this->elementClass
;
76 $this->stack
[] = new $class( $data );
78 $this->top
= $this->stack
[count( $this->stack
) - 1];
79 $this->accum
=& $this->top
->getAccum();
82 public function pop() {
83 if ( $this->stack
=== [] ) {
84 throw new MWException( __METHOD__
. ': no elements remaining' );
86 $temp = array_pop( $this->stack
);
88 if ( count( $this->stack
) ) {
89 $this->top
= $this->stack
[count( $this->stack
) - 1];
90 $this->accum
=& $this->top
->getAccum();
92 $this->top
= self
::$false;
93 $this->accum
=& $this->rootAccum
;
98 public function addPart( $s = '' ) {
99 $this->top
->addPart( $s );
100 $this->accum
=& $this->top
->getAccum();
106 public function getFlags() {
107 if ( $this->stack
=== [] ) {
109 'findEquals' => false,
111 'inHeading' => false,
114 return $this->top
->getFlags();