-
Notifications
You must be signed in to change notification settings - Fork 8
/
doxygen-bash.sed
executable file
·156 lines (143 loc) · 3.56 KB
/
doxygen-bash.sed
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sed -nf
##
## Licensed under Apache-2.0
##
## Project Home Page: http://github.com/Anvil/bash-doxygen/
## Project Author: Damien Nadé <[email protected]>
##
/^## \+@fn/{
:step
/@param [^ ]\+ .*$/{
# Groups are
# \1: @fn <funcname>
# \2: already identified params
# \3: previous doc string
# \4: @param<space>
# \5: newly identified param name plus optional dot-dot-dot string
# \6: optional dot-dot-dot string
# \7: everything after \5 to end of line
# Here, we-reinsert param names into the <funcname>()
s/\(@fn [^(\n]\+\)(\([^(]*\))\(.*\)\(@param \)\([^ \n]\+\(\.\.\.\)\?\)\([^\n]*\)$/\1(\2, \5)\3\4\5\7/
}
/ *\(function \+\)\?[a-z:.A-Z0-9_]\+ *() *{ *$/!{
N
b step
}
# Remove optional 'function' keyword (and some extra spaces).
s/ *\(function \+\)\?\([a-z:.A-Z0-9_]\+ *() *{\) *$/\2/
# Here, we should have @fn (, param1, param2, param3), we remove
# the first extra ", ".
s/\(@fn[^(]\+\)(, /\1(/
# Remove the function body to avoid interference, and re-introduce
# list of parameters in the funcname(<here>).
s/\(@fn \([^(]\+\)(\)\([^)]*\)\().*\)\n\2() *{/\1\3\4\n\2(\3) { }/
# Replace all '## ' by '//! ' at beginning-of-line.
s/\(^\|\n\)##\n/\1\/\/!\n/g
s/\(^\|\n\)## /\1\/\/! /g
p
b end
}
/^declare /{
# The principle is quite easy. For every declare option, we add a
# keyword into the sed exchange buffer. Once everything is parsed,
# we add the variable identifier and maybe the variable default
# value, add that to the exchange buffer and print the result.
# Reset exchange buffer
x
s/.*//
x
# Remove declare keyword, we wont need it anymore
s/^declare \+//
# Simple declaration case.
/^[^-]/{
x
s/.*/&String /
x
b declareprint
}
# Concat options. Some of them are ignored, such as -f.
:declare
s/^-\([aAilrtux]\+\) \+-\([aAilrtux]\+\) \+/-\1\2 /
t declare
# Prepend Exported and ReadOnly attributes
/^-[aAiltur]*x/{
x
s/.*/&Exported /
x
}
/^-[aAiltux]*r/{
x
s/.*/&ReadOnly /
x
}
# Integer type, exclusive with default 'String' type.
/^-[aAlturx]*i/{
x
s/.*/&Integer /
x
b array
}
# String type. handling.
/^-[aAtrx]*l/{
x
s/.*/&LowerCase /
x
}
/^-[aAtrx]*u/{
x
s/.*/&UpperCase /
x
}
x
s/.*/&String /
x
: array
# For arrays, we remove the initialisation since I dont know yet
# how to print it for doxygen to understand.
/^-[Ailturx]*a/{
x
s/.*/&Array /
x
b deletevalue
}
/^-[ailturx]*A/{
x
s/.*/&AssociativeArray /
x
b deletevalue
}
:declareprint
# Remove the declare option, x, then G will concat the exchange
# buffer (the 'type' string) and the regular buffer (the var
# possibly followed by an init value). The rest is quite easy to
# understand.
s/-[^ ]\+ \+//
x
G
s/\n//
s/=/ = /
s/$/;/
p
x
b end
}
/^ *export \+[_a-zA-Z]/{
s/=/ = /
s/\([^;]\) *$/\1;/
s/^ *export \+/Exported String /
p
b end
}
# Delete non doxygen-related lines content, but not the line
# themselves.
/^\(\s*\)## \|^\1##$/!{
s/^.*$//p
}
b end
# For arrays, to avoid duplication.
: deletevalue
s/\(-[^ ]\+ \+[^=]\+\)=.*/\1/
b declareprint
:end
# Make all ## lines doxygen-able.
s/^\s*##\( \|$\)/\/\/!\1/p