Code

Updated String handling in My_Tree class. To avoid losing quotes an every editing...
[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 {
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         }
25         
27         /* Check if there are errors, collect them and return them */
28         function check()
29         {
30                 return($this->tree_->check());
31         }
32         
34         /* Initiate parser, but use some other 
35      *  classes, that are rewritten.
36      */
37         function parse($script) 
38         {
39                 $script = preg_replace("/^###GOSA/","",$script);
41                 $this->registeredExtensions_ = array();
42         $this->status_text = "incomplete";
43         $this->script_ = $script;
44         $this->tree_ = new My_Tree(@Scanner::scriptStart(),$this);
45         $this->tree_->setDumpFunc(array(&$this, 'dumpToken_'));
46         $this->scanner_ = new My_Scanner($this->script_);
47         $this->scanner_->setCommentFunc(array($this, 'comment_'));
49         if ($this->commands_($this->tree_->getRoot()) &&
50             $this->scanner_->nextTokenIs('script-end'))
51         {
52                         $this->scanner_->nextToken(); 
53             return $this->success_('success');
54         }
56         return $this->status_;
57         }
59         
60         function get_sieve_script()
61         {
62                 return("###GOSA\n".$this->tree_->get_sieve_script());
63         }               
65         
66         function save_object()
67         {
68                 $this->tree_->save_object();
69         }
72         /* Should be obsolete in the end. */
73         function dumpToken_(&$token)
74         {
75                 if (is_array($token))
76                 {
77                         $str = "<" . $token['text'] . "> ";
78                         foreach ($token as $k => $v)
79                         {
80                                 $str .= " $k:$v";
81                         }
82                         return $str;
83                 }
84                 return strval($token);
85         }
88         function dumpParseTree()
89         {
90                 return $this->tree_->execute();
91         }
92 }
93 ?>