Subversion Repositories Applications.papyrus

Rev

Rev 248 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
248 jpm 1
<?php
2
 
3
// $Id: Function.php,v 1.1 2005-01-20 19:43:20 jpm Exp $
4
 
5
class Text_Wiki_Parse_Function extends Text_Wiki_Parse {
6
 
7
    var $regex = '/^(\<function\>)\n(.+)\n(\<\/function\>)(\s|$)/Umsi';
8
 
9
    function process(&$matches)
10
    {
11
        // default options
12
        $opts = array(
13
            'name' => null,
14
            'access' => null,
15
            'return' => null,
16
            'params' => array(),
17
            'throws' => array()
18
        );
19
 
20
        // split apart the markup lines and loop through them
21
        $lines = explode("\n", $matches[2]);
22
        foreach ($lines as $line) {
23
 
24
            // skip blank lines
25
            if (trim($line) == '') {
26
                continue;
27
            }
28
 
29
            // find the first ':' on the line; the left part is the
30
            // type, the right part is the value. skip lines without
31
            // a ':' on them.
32
            $pos = strpos($line, ':');
33
            if ($pos === false) {
34
                continue;
35
            }
36
 
37
            // $type is the line type: name, access, return, param, throws
38
            // 012345678901234
39
            // name: something
40
            $type = trim(substr($line, 0, $pos));
41
            $val = trim(substr($line, $pos+1));
42
 
43
            switch($type) {
44
 
45
            case 'a':
46
            case 'access':
47
                $opts['access'] = $val;
48
                break;
49
 
50
            case 'n':
51
            case 'name':
52
                $opts['name'] = $val;
53
                break;
54
 
55
            case 'p':
56
            case 'param':
57
                $tmp = explode(',', $val);
58
                $k = count($tmp);
59
                if ($k == 1) {
60
                    $opts['params'][] = array(
61
                        'type' => $tmp[0],
62
                        'descr' => null,
63
                        'default' => null
64
                    );
65
                } elseif ($k == 2) {
66
                    $opts['params'][] = array(
67
                        'type' => $tmp[0],
68
                        'descr' => $tmp[1],
69
                        'default' => null
70
                    );
71
                } else {
72
                    $opts['params'][] = array(
73
                        'type' => $tmp[0],
74
                        'descr' => $tmp[1],
75
                        'default' => $tmp[2]
76
                    );
77
                }
78
                break;
79
 
80
            case 'r':
81
            case 'return':
82
            case 'returns':
83
                $opts['return'] = $val;
84
                break;
85
 
86
            case 't':
87
            case 'throws':
88
                $tmp = explode(',', $val);
89
                $k = count($tmp);
90
                if ($k == 1) {
91
                    $opts['throws'][] = array(
92
                        'type' => $tmp[0],
93
                        'descr' => null
94
                    );
95
                } else {
96
                    $opts['throws'][] = array(
97
                        'type' => $tmp[0],
98
                        'descr' => $tmp[1]
99
                    );
100
                }
101
                break;
102
 
103
            default:
104
                $opts[$type] = $val;
105
                break;
106
 
107
            }
108
        }
109
 
110
        // add the token back in place
111
        return $this->wiki->addToken($this->rule, $opts) . $matches[4];
112
    }
113
}
114
 
115
?>