NBash

Форк
0
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>()
34
        s/\(@fn [^(\n]\+\)(\([^(]*\))\(.*\)\(@param \)\([^ \n]\+\(\.\.\.\)\?\)\([^\n]*\)$/\1(\2, \5)\3\4\5\7/
35
    }
36
    / *\(function \+\)\?[a-z:.A-Z0-9_]\+ *() *{ *$/!{
37
        N
38
        b step
39
    }
40
    # Remove optional 'function' keyword (and some extra spaces).
41
    s/ *\(function \+\)\?\([a-z:.A-Z0-9_]\+ *() *{\) *$/\2/
42
    # Here, we should have @fn (, param1, param2, param3), we remove
43
    # the first extra ", ".
44
    s/\(@fn[^(]\+\)(, /\1(/
45
    # Remove the function body to avoid interference, and re-introduce
46
    # list of parameters in the funcname(<here>).
47
    s/\(@fn \([^(]\+\)(\)\([^)]*\)\().*\)\n\2() *{/\1\3\4\n\2(\3) { }/
48
    # Replace all '## ' by '//! ' at beginning-of-line.
49
    s/\(^\|\n\)##\n/\1\/\/!\n/g
50
    s/\(^\|\n\)## /\1\/\/! /g
51
    p
52
    b 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
62
    x
63
    s/.*//
64
    x
65
    # Remove declare keyword, we wont need it anymore
66
    s/^declare \+//
67
    # Simple declaration case.
68
    /^[^-]/{
69
        x
70
        s/.*/&String /
71
        x
72
        b declareprint
73
    }
74
    # Concat options. Some of them are ignored, such as -f.
75
    :declare
76
    s/^-\([aAilrtux]\+\) \+-\([aAilrtux]\+\) \+/-\1\2 /
77
    t declare
78

79
    # Prepend Exported and ReadOnly attributes
80
    /^-[aAiltur]*x/{
81
        x
82
        s/.*/&Exported /
83
        x
84
    }
85
    /^-[aAiltux]*r/{
86
        x
87
        s/.*/&ReadOnly /
88
        x
89
    }
90

91
    # Integer type, exclusive with default 'String' type.
92
    /^-[aAlturx]*i/{
93
        x
94
        s/.*/&Integer /
95
        x
96
        b array
97
    }
98

99
    # String type. handling.
100
    /^-[aAtrx]*l/{
101
        x
102
        s/.*/&LowerCase /
103
        x
104
    }
105
    /^-[aAtrx]*u/{
106
        x
107
        s/.*/&UpperCase /
108
        x
109
    }
110
    x
111
    s/.*/&String /
112
    x
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/{
118
        x
119
        s/.*/&Array /
120
        x
121
        b deletevalue
122
    }
123
    /^-[ailturx]*A/{
124
        x
125
        s/.*/&AssociativeArray /
126
        x
127
        b 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.
135
    s/-[^ ]\+ \+//
136
    x
137
    G
138
    s/\n//
139
    s/=/ = /
140
    s/$/;/
141
    p
142
    x
143
    b end
144
}
145

146
/^ *export \+[_a-zA-Z]/{
147
    s/=/ = /
148
    s/\([^;]\) *$/\1;/
149
    s/^ *export \+/Exported String /
150
    p
151
    b end
152
}
153

154

155
# Delete non doxygen-related lines content, but not the line
156
# themselves.
157
/^\(\s*\)##\( \|$\)/!{
158
     s/^.*$//p
159
}
160
b end
161

162
# For arrays, to avoid duplication.
163
: deletevalue
164
s/\(-[^ ]\+ \+[^=]\+\)=.*/\1/
165
b declareprint
166

167
:end
168
# Make all ## lines doxygen-able.
169
s/^\s*##\( \|$\)/\/\/!\1/p
170

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.