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 public $stack, $rootAccum;
34 public $elementClass = PPDStackElement
::class;
36 public static $false = false;
38 public function __construct() {
41 $this->rootAccum
= '';
42 $this->accum
=& $this->rootAccum
;
48 public function count() {
49 return count( $this->stack
);
52 public function &getAccum() {
57 * @return bool|PPDPart
59 public function getCurrentPart() {
60 if ( $this->top
=== false ) {
63 return $this->top
->getCurrentPart();
67 public function push( $data ) {
68 if ( $data instanceof $this->elementClass
) {
69 $this->stack
[] = $data;
71 $class = $this->elementClass
;
72 $this->stack
[] = new $class( $data );
74 $this->top
= $this->stack
[count( $this->stack
) - 1];
75 $this->accum
=& $this->top
->getAccum();
78 public function pop() {
79 if ( $this->stack
=== [] ) {
80 throw new MWException( __METHOD__
. ': no elements remaining' );
82 $temp = array_pop( $this->stack
);
84 if ( count( $this->stack
) ) {
85 $this->top
= $this->stack
[count( $this->stack
) - 1];
86 $this->accum
=& $this->top
->getAccum();
88 $this->top
= self
::$false;
89 $this->accum
=& $this->rootAccum
;
94 public function addPart( $s = '' ) {
95 $this->top
->addPart( $s );
96 $this->accum
=& $this->top
->getAccum();
102 public function getFlags() {
103 if ( $this->stack
=== [] ) {
105 'findEquals' => false,
107 'inHeading' => false,
110 return $this->top
->getFlags();