NBash
169 строк · 4.0 Кб
1#!/bin/sed -nf
2##
3## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
4## Version 2, December 2004
5##
6## Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
7##
8## Everyone is permitted to copy and distribute verbatim or modified
9## copies of this license document, and changing it is allowed as long
10## as the name is changed.
11##
12## DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
13## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
14##
15## 0. You just DO WHAT THE FUCK YOU WANT TO.
16##
17##
18## Project Home Page: http://github.com/Anvil/bash-doxygen/
19## Project Author: Damien Nadé <github@livna.org>
20##
21
22/^## \+@fn/{
23:step
24/@param [^ ]\+ .*$/{
25# Groups are
26# \1: @fn <funcname>
27# \2: already identified params
28# \3: previous doc string
29# \4: @param<space>
30# \5: newly identified param name plus optional dot-dot-dot string
31# \6: optional dot-dot-dot string
32# \7: everything after \5 to end of line
33# Here, we-reinsert param names into the <funcname>()
34s/\(@fn [^(\n]\+\)(\([^(]*\))\(.*\)\(@param \)\([^ \n]\+\(\.\.\.\)\?\)\([^\n]*\)$/\1(\2, \5)\3\4\5\7/
35}
36/ *\(function \+\)\?[a-z:.A-Z0-9_]\+ *() *{ *$/!{
37N
38b step
39}
40# Remove optional 'function' keyword (and some extra spaces).
41s/ *\(function \+\)\?\([a-z:.A-Z0-9_]\+ *() *{\) *$/\2/
42# Here, we should have @fn (, param1, param2, param3), we remove
43# the first extra ", ".
44s/\(@fn[^(]\+\)(, /\1(/
45# Remove the function body to avoid interference, and re-introduce
46# list of parameters in the funcname(<here>).
47s/\(@fn \([^(]\+\)(\)\([^)]*\)\().*\)\n\2() *{/\1\3\4\n\2(\3) { }/
48# Replace all '## ' by '//! ' at beginning-of-line.
49s/\(^\|\n\)##\n/\1\/\/!\n/g
50s/\(^\|\n\)## /\1\/\/! /g
51p
52b end
53}
54
55/^declare /{
56# The principle is quite easy. For every declare option, we add a
57# keyword into the sed exchange buffer. Once everything is parsed,
58# we add the variable identifier and maybe the variable default
59# value, add that to the exchange buffer and print the result.
60
61# Reset exchange buffer
62x
63s/.*//
64x
65# Remove declare keyword, we wont need it anymore
66s/^declare \+//
67# Simple declaration case.
68/^[^-]/{
69x
70s/.*/&String /
71x
72b declareprint
73}
74# Concat options. Some of them are ignored, such as -f.
75:declare
76s/^-\([aAilrtux]\+\) \+-\([aAilrtux]\+\) \+/-\1\2 /
77t declare
78
79# Prepend Exported and ReadOnly attributes
80/^-[aAiltur]*x/{
81x
82s/.*/&Exported /
83x
84}
85/^-[aAiltux]*r/{
86x
87s/.*/&ReadOnly /
88x
89}
90
91# Integer type, exclusive with default 'String' type.
92/^-[aAlturx]*i/{
93x
94s/.*/&Integer /
95x
96b array
97}
98
99# String type. handling.
100/^-[aAtrx]*l/{
101x
102s/.*/&LowerCase /
103x
104}
105/^-[aAtrx]*u/{
106x
107s/.*/&UpperCase /
108x
109}
110x
111s/.*/&String /
112x
113
114: array
115# For arrays, we remove the initialisation since I dont know yet
116# how to print it for doxygen to understand.
117/^-[Ailturx]*a/{
118x
119s/.*/&Array /
120x
121b deletevalue
122}
123/^-[ailturx]*A/{
124x
125s/.*/&AssociativeArray /
126x
127b deletevalue
128}
129
130:declareprint
131# Remove the declare option, x, then G will concat the exchange
132# buffer (the 'type' string) and the regular buffer (the var
133# possibly followed by an init value). The rest is quite easy to
134# understand.
135s/-[^ ]\+ \+//
136x
137G
138s/\n//
139s/=/ = /
140s/$/;/
141p
142x
143b end
144}
145
146/^ *export \+[_a-zA-Z]/{
147s/=/ = /
148s/\([^;]\) *$/\1;/
149s/^ *export \+/Exported String /
150p
151b end
152}
153
154
155# Delete non doxygen-related lines content, but not the line
156# themselves.
157/^## \|^##$/!{
158s/^.*$//p
159}
160b end
161
162# For arrays, to avoid duplication.
163: deletevalue
164s/\(-[^ ]\+ \+[^=]\+\)=.*/\1/
165b declareprint
166
167:end
168# Make all ## lines doxygen-able.
169s/^##\( \|$\)/\/\/!\1/p
170