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 function My_Parser($parent)
13 {
14 $this->parent = $parent;
15 }
17 function execute()
18 {
19 $ret = $this->dumpParseTree();
20 return($ret);
21 }
24 /* Check if there are errors, collect them and return them */
25 function check()
26 {
27 return($this->tree_->check());
28 }
31 /* Initiate parser, but use some other
32 * classes, that are rewritten.
33 */
34 function parse($script)
35 {
36 $this->status_text = "incomplete";
37 $this->script_ = $script;
38 $this->tree_ = new My_Tree(@Scanner::scriptStart(),$this);
39 $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
40 $this->scanner_ = new Scanner($this->script_);
41 $this->scanner_->setCommentFunc(array($this, 'comment_'));
43 if ($this->commands_($this->tree_->getRoot()) &&
44 $this->scanner_->nextTokenIs('script-end'))
45 {
46 return $this->success_('success');
47 }
49 return $this->status_;
50 }
53 function get_sieve_script()
54 {
55 return($this->tree_->get_sieve_script());
56 }
59 function save_object()
60 {
61 $this->tree_->save_object();
62 }
65 /* Should be obsolete in the end. */
66 function dumpToken_(&$token)
67 {
68 if (is_array($token))
69 {
70 $str = "<" . $token['text'] . "> ";
71 foreach ($token as $k => $v)
72 {
73 $str .= " $k:$v";
74 }
75 return $str;
76 }
77 return strval($token);
78 }
81 function dumpParseTree()
82 {
83 return $this->tree_->execute();
84 }
85 }
86 ?>