1 <?php
3 define("SIEVE_INDENT_TAB"," ");
5 /* This class is inherited from the original 'Parser'
6 * class written by Heiko Hund
7 */
8 class My_Parser extends Parser
9 {
10 var $parent = NULL;
12 var $registeredExtensions_ =array();
14 function My_Parser($parent)
15 {
16 $this->registeredExtensions_ = array();
17 $this->parent = $parent;
18 }
20 function execute()
21 {
22 $ret = $this->dumpParseTree();
23 return($ret);
24 }
27 /* Check if there are errors, collect them and return them */
28 function check()
29 {
30 return($this->tree_->check());
31 }
34 /* Initiate parser, but use some other
35 * classes, that are rewritten.
36 */
37 function parse($script)
38 {
39 $this->registeredExtensions_ = array();
40 $this->status_text = "incomplete";
41 $this->script_ = $script;
42 $this->tree_ = new My_Tree(@Scanner::scriptStart(),$this);
43 $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
44 $this->scanner_ = new My_Scanner($this->script_);
45 $this->scanner_->setCommentFunc(array($this, 'comment_'));
47 if ($this->commands_($this->tree_->getRoot()) &&
48 $this->scanner_->nextTokenIs('script-end'))
49 {
50 $this->scanner_->nextToken();
51 return $this->success_('success');
52 }
54 return $this->status_;
55 }
58 function get_sieve_script()
59 {
60 return($this->tree_->get_sieve_script());
61 }
64 function save_object()
65 {
66 $this->tree_->save_object();
67 }
70 /* Should be obsolete in the end. */
71 function dumpToken_(&$token)
72 {
73 if (is_array($token))
74 {
75 $str = "<" . $token['text'] . "> ";
76 foreach ($token as $k => $v)
77 {
78 $str .= " $k:$v";
79 }
80 return $str;
81 }
82 return strval($token);
83 }
86 function dumpParseTree()
87 {
88 return $this->tree_->execute();
89 }
90 }
91 ?>