-
Notifications
You must be signed in to change notification settings - Fork 0
/
doxygen-filter.php
executable file
·113 lines (102 loc) · 3.84 KB
/
doxygen-filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/php
<?php
/**
* Simple input filter for using Doxygen with PHP code
*
* It escapes backslashes in docblock comments, and appends variable names to
* \@var commands.
*
* @see http://www.doxygen.org/
* @see http://www.stack.nl/~dimitri/doxygen/config.html#cfg_input_filter
*
* Copyright (C) 2012 Tamas Imrei <[email protected]>
* http://virtualtee.blogspot.com/
*
* Modified by David Simon <[email protected]>.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
function process_php($source)
{
// TODO This will have terrible results if I want to do inline
// code examples that include "use" or "extends" or "implements"
$source = str_replace("AC\\FiendishBundle\\", "", $source);
$tokens = token_get_all($source);
$buffer = null;
foreach ($tokens as $token) {
if (is_string($token)) {
if ((! empty($buffer)) && ($token == ';')) {
echo $buffer;
unset($buffer);
}
echo $token;
} else {
list($id, $text) = $token;
switch ($id) {
case T_DOC_COMMENT :
$text = preg_replace('/@ORM[^\n\r]+(\n\r?)/', '\\1', $text);
$text = preg_replace(
'/([^\s.-]+)\\\\([^\s.-]+)/',
'[$1\\\\\\\\$2](@ref $1::$2)',
$text
);
if (preg_match('#@var\s+[^\$]*\*/#ms', $text)) {
$buffer = preg_replace('#(@var\s+[^\n\r]+)(\n\r?.*\*/)#ms',
'$1 \$\$\$$2', $text);
} else {
echo $text;
}
break;
case T_VARIABLE :
if ((! empty($buffer))) {
echo str_replace('$$$', $text, $buffer);
unset($buffer);
}
echo $text;
break;
default:
if ((! empty($buffer))) {
$buffer .= $text;
} else {
echo $text;
}
break;
}
}
}
}
function process_markdown($t)
{
// Replace the original leader section with a link to GitHub
$t = preg_replace("/^.+?##/s", "##", $t, 1);
$t = "(This file is also available as `README.md` in the repository)\n\n$t";
$t = "**Get downloads and source** at the [GitHub Project Page](http://github.com/AmericanCouncils/fiendish-bundle).\n\n$t";
// Convert from GitHub markdown to Doxygen markdown
$t = "\mainpage\n$t";
$t = str_replace("```", "~~~", $t);
// TODO Link references from AC\FiendishBundle\X to X
echo($t);
}
$path = $_SERVER['argv'][1];
$source = file_get_contents($path);
if (preg_match("/\\.php$/", $path)) {
process_php($source);
} else {
process_markdown($source);
}