Code

Added some checks
[gosa.git] / include / sieve / class_My_Parser.inc
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 {
11         function execute()
12         {
13                 $ret = $this->dumpParseTree();
14                 return($ret);
15         }
16         
18         /* Check if there are errors, collect them and return them */
19         function check()
20         {
21                 return($this->tree_->check());
22         }
23         
25         /* Initiate parser, but use some other 
26      *  classes, that are rewritten.
27      */
28         function parse($script) 
29         {
30         $this->status_text = "incomplete";
31         $this->script_ = $script;
32         $this->tree_ = new My_Tree(@Scanner::scriptStart());
33         $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
34         $this->scanner_ = new Scanner($this->script_);
35         $this->scanner_->setCommentFunc(array($this, 'comment_'));
37         if ($this->commands_($this->tree_->getRoot()) &&
38             $this->scanner_->nextTokenIs('script-end'))
39         {
40             return $this->success_('success');
41         }
43         return $this->status_;
44         }
46         
47         function get_sieve_script()
48         {
49                 return($this->tree_->get_sieve_script());
50         }               
52         
53         function save_object()
54         {
55                 $this->tree_->save_object();
56         }
59         /* Should be obsolete in the end. */
60         function dumpToken_(&$token)
61         {
62                 if (is_array($token))
63                 {
64                         $str = "<" . $token['text'] . "> ";
65                         foreach ($token as $k => $v)
66                         {
67                                 $str .= " $k:$v";
68                         }
69                         return $str;
70                 }
71                 return strval($token);
72         }
75         function dumpParseTree()
76         {
77                 return $this->tree_->execute();
78         }
79 }
80 ?>