[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Lexer adapted from Simple Test: http://sourceforge.net/projects/simpletest/ 4 * For an intro to the Lexer see: 5 * https://web.archive.org/web/20120125041816/http://www.phppatterns.com/docs/develop/simple_test_lexer_notes 6 * 7 * @author Marcus Baker http://www.lastcraft.com 8 */ 9 10 namespace dokuwiki\Parsing\Lexer; 11 12 /** 13 * States for a stack machine. 14 */ 15 class StateStack 16 { 17 protected $stack; 18 19 /** 20 * Constructor. Starts in named state. 21 * @param string $start Starting state name. 22 */ 23 public function __construct($start) 24 { 25 $this->stack = array($start); 26 } 27 28 /** 29 * Accessor for current state. 30 * @return string State. 31 */ 32 public function getCurrent() 33 { 34 return $this->stack[count($this->stack) - 1]; 35 } 36 37 /** 38 * Adds a state to the stack and sets it to be the current state. 39 * 40 * @param string $state New state. 41 */ 42 public function enter($state) 43 { 44 array_push($this->stack, $state); 45 } 46 47 /** 48 * Leaves the current state and reverts 49 * to the previous one. 50 * @return boolean false if we attempt to drop off the bottom of the list. 51 */ 52 public function leave() 53 { 54 if (count($this->stack) == 1) { 55 return false; 56 } 57 array_pop($this->stack); 58 return true; 59 } 60 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body