-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparse_drupal_api.pl
More file actions
executable file
·129 lines (117 loc) · 4.05 KB
/
parse_drupal_api.pl
File metadata and controls
executable file
·129 lines (117 loc) · 4.05 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl
# Copyright (C) 2011 Jeremie Le Hen <jeremie@le-hen.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# How to run this script:
# $ cd /path/to/drupal
# $ find . -name \*.php | xargs grep -l '^function hook_' | \
# xargs /path/to/parse_drupal_api.pl > ~/.WebIde10/config/templates/user.xml
use strict;
use warnings;
my @comment;
my @function;
my $DEFAULT = 0;
my $IN_COMMENT = 1;
my $IN_FUNCTION = 2;
my $state = $DEFAULT;
print <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<templateSet group="user">
EOF
while (<>) {
chomp;
if (m,^\/\*\*,) {
@comment = ();
push @comment, $_;
$state = $IN_COMMENT;
next;
}
if (m,^function hook_,) {
@function = ();
push @function, $_;
$state = $IN_FUNCTION;
next;
}
if ($state == $IN_COMMENT) {
push @comment, $_;
if (m,^ \*\/,) { $state = $DEFAULT }
next;
}
if ($state != $IN_FUNCTION) { next }
# $state == $IN_FUNCTION
push @function, $_;
if (not m,^\}$,) { next }
# $_ eq "}"
my $end;
$function[0] =~ m/function hook_(\w+)/;
my $xml_longname = "hook_".$1;
my $xml_shortname = "h_".$1;
$function[0] =~ s/function hook_/function \$MODULE_NAME\$_/;
$end = pop @function;
push @function, ' $END$', $end;
pop @comment;
shift @comment;
push @comment, ' *';
my @comment_begin = ('/**', " * Implements $xml_longname().", " *");
my @comment_end = (' * $COMMENT$', ' */');
# From now on, build XML
my $xml_longvalue = join ("\n", @comment_begin, @comment, @comment_end, @function);
my $xml_shortvalue = join ("\n", @comment_begin, @comment_end, @function);
foreach (\$xml_longvalue, \$xml_shortvalue) {
$$_ =~ s/&/&/g;
$$_ =~ s/"/"/g;
$$_ =~ s/'/'/g;
$$_ =~ s/</</g;
$$_ =~ s/>/>/g;
$$_ =~ s/\n/ /g;
}
print <<EOF;
<template name="$xml_longname" value="$xml_longvalue" description="$xml_longname" toReformat="false" toShortenFQNames="true">
<variable name="COMMENT" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="MODULE_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="CSS" value="false" />
<option name="JAVA_SCRIPT" value="false" />
<option name="JSP" value="false" />
<option name="SQL" value="false" />
<option name="PHP" value="true" />
<option name="OTHER" value="false" />
</context>
</template>
<template name="$xml_shortname" value="$xml_shortvalue" description="$xml_longname" toReformat="false" toShortenFQNames="true">
<variable name="COMMENT" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="MODULE_NAME" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="HTML_TEXT" value="false" />
<option name="HTML" value="false" />
<option name="XSL_TEXT" value="false" />
<option name="XML" value="false" />
<option name="CSS" value="false" />
<option name="JAVA_SCRIPT" value="false" />
<option name="JSP" value="false" />
<option name="SQL" value="false" />
<option name="PHP" value="true" />
<option name="OTHER" value="false" />
</context>
</template>
EOF
}
print <<EOF;
</templateSet>
EOF