aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc_src/fish_lexicon_filter.in
blob: 60cde9bec5a944bd9b78730fc02aeb410a5d2ed1 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#! @sed@ -f
#.
# A Doxygen filter for building Fish's lexicon, for documentation bling.
#.
# Written specially for Fish, the shell for the 90's, in sed, the state of the
# art text processor from the 70's. Who's sed? sed's dead, baby, sed's dead.*
# by Mark Griffiths <mark@thebespokepixel.com>             *but quite portable
#.
# Finds /fish../endfish blocks in documentation source files and enhances
# markup. Requires that the short tags declared here are added to Doxyfiles as
# aliases i.e.:
#.
# Enhance for HTML Help pages (Doxyfile.user)…
# ALIASES   = "fish=\htmlonly[block] \n<pre class=\"fish\">"
# ALIASES  += "fish{1}=\htmlonly[block] \n<pre class=\"fish \1\">"
# ALIASES  += "endfish=</pre>\endhtmlonly \n"
#.
# ALIASES  += "blah{1}=<span class=\"comment\">\1</span>"
# ALIASES  += "cmnd{1}=<span class=\"command\">\1</span>" and so on...
#.
# And simplify for man pages (Doxyfile.help)…
# ALIASES   = "fish=<pre>"
# ALIASES  += "fish{1}=<pre>"
# ALIASES  += "endfish=</pre>"
#.
# ALIASES  += "blah{1}=\1"
# ALIASES  += "cmnd{1}=<em>\1</em>"...
#.
# Licensed under whatever terms are most compatible with Fish's GPLv2 license,
# bascially free to use/reuse/redistribute/laugh at/be inspired by. Don't
# pretend it's your code unless you've spent more late nights on it than me but
# if it saves you a late night, do what you can to help rebalance karma. If it
# doesn't work or breaks something, it's your fault for using it: if it seems
# to work it's more likely a hallucination than anything based in reality.
#.
# Pattern flow control for scanning doc.h
/\\fish/,/\\endfish/ {
    # Open \fish block
    /^\\fish$/b
    /^\\fish{[^}]*}$/b
    /^\\fish.*$/ {
        s/^\\fish//
        s/\\endfish//
        b process
    }
    # Output blank lines
    /^$/b
    # Inside \fish block. Process...
    /\\endfish/!{
        # Preprocess HTML and HTML-like formatting
        /<[^>]*>/ {
            b html
        }
        # Process the rest
        b process
    }
    # End block
    /\\endfish/b
}
/style/b styles
#.
# This is not the pattern we're looking for
b
#.
# Sets CSS styles according to fish defaults.
#.
# Used for building the documentation's CSS file
#.
:processstyle
#. Make Hex uniform
s/0x//g
/[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]*/ {
    y/ABCDEF/abcdef/
    s/^[0-9a-f]/#&/
}
#.
# Set simple styles
#.
s/bold/font-weight:bold;/
#.
# Replace named colours (taken from color.cpp)
#.
s/black/#000/
s/red/#f00/
s/green/#0f0/
s/brown/#725000/
s/yellow/#ff0/
s/blue/#00f/
s/magenta/#f0f/
s/purple/#f0f/
s/cyan/#0ff/
s/white/#fff/
s/normal/#fff text-decoration:none; border-bottom:none; font-weight:normal;/
#.
/background/ {
    s/background=\(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f]*\)/background-color: \1;/
}
/underline/ {
    s/^\(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f]*\).*$/\1 border-bottom: 2px solid \1;/
    s/^underline$/text-decoration: underline;/
}
# If we start with just a colour, make it explicit.
s/^#[0-9a-f][0-9a-f]*/color: &;/
#.
# All done, return CSS style content
b
# Process any HTML tags.
# Structured to reduce sed's greediness.
:html
# Spans
s|<span style=['"]\([^'"][^'"]*\)">|@span{\1,|
s|<span class=['"]\([^'"][^'"]*\)">|@spcl{\1,|
s|</span>|}|
t html
#.
# Bold
s|<b>|@bold{|
s|<b [^>]*>|@bold{|
s|</b>|}|
#.
# Strong
s|<strong>|@bold{|
s|<strong [^>]*>|@bold{|
s|</strong>|}|
#.
# Italic
s|<i>|@emph{|
s|<i [^>]*>|@emph{|
s|</i>|}|
#.
# Emphasis
s|<em>|@emph{|
s|<em [^>]*>|@emph{|
s|</em>|}|
#.
# Underline
s|<u>|@undr{|
s|<u [^>]*>|@undr{|
s|</u>|}|
t html
#.
# Some handy non-standard extensions
# Autosuggestion
s|<s>|@sgst{|
s|<s [^>]*>|@sgst{|
s|</s>|}|
#.
# Error
s|<error>|@eror{|
s|<error [^>]*>|@eror{|
s|</error>|}|
#.
# File declaration
s|<file>|@fsfo{|
s|<file [^>]*>|@fsfo{|
s|</file>|}|
#.
# AsIs - protect from auto-formatting
s|<asis>|@asis{|
s|</asis>|}|
t html
#.
# Clean other unhandled html
s|<\([A-Za-z][A-Za-z]*\)[^>]*>\([^<]*\)</\1>|\2|
t html
#.
# Start processing entities
:process
#.
# Comments:
# Capture full line comments
/^#.*$/ {
    # Assume any line starting with a # is complete
    s//@blah{&}/
    t
}
# Match sub-line comments
/#[^0-9A-Za-z][ ]*.*$/ {
    # Assume comment finishes a line
    s//@blah{&}/
    t
}
#.
# Protected entities These shouldn't allow nested structure, so we move them
# to a marked, new line for a future extract/process/insert action.
#.
# AsIs block - resists formatting.
s/@asis{\(.*\)}/\\\
<@asis{\1}\
/g
#.
# String Literals
s/"\([^"]*\)"/\\\
<@dblq{\1}\
/g
s/'\([^']*\)'/\\\
<@sglq{\1}\
/g
#.
# Command/Function options
# Short options
s/-\([A-Za-z]\)\([^A-Za-z}]\)/\\\
<@opts{-\1}\
\2/g
#.
# Long options
s/--\([A-Za-z][A-Za-z0-9=_-]*\)\([^A-Za-z0-9]\)/\\\
<@opts{--\1}\
\2/g
#.
# Paths
# Normal Directory
s|\([^/~A-Za-z0-9]\)\([~/][/]*\)\([A-Za-z_0-9./-]*\)|\1\\\
<@path{\2\3}\
|g
#.
b protect
# Tidy up. Merge back 'pure' entities from hold space.
:tidy
#.
# Uncomment the following 2 lines (ss) to log the pattern buffer.
# s/^.*$/PATT: &/w debug-lexicon.log
# s/^PATT: //
#.
# Uncomment the following 4 lines (xssx) to log the hold buffer.
# x
# s/^.*$/HOLD: &/w debug-lexicon.log
# s/^HOLD: //
# x
#.
# Tack the hold space to the end of the pattern buffer.
G
#.
# Uncomment the folowing two lines (ss) to log the buffer join.
s/^.*$/JOIN: &/w debug-lexicon.log
s/^JOIN: //
#.
# Iterate over alternate lines, matching '<' to '\'
:join
s,\([^\\ ]*\)\\\n\([^<]*\)<\(@[^}]*[}\\]\)[\n]*,\1\3\2,
t join
# Clean up stray new lines
s/\n//g
#.
# Clean up special cases
#.
/@redr/{
    :cleanredr
    s/\(redr{[^@]*\)@cmnd{\([^}]*\)}/\1\2/
    s/\(redr{[^@]*\)@func{\([^}]*\)}/\1\2/
    s/\(redr{[^@]*\)@sbin{\([^}]*\)}/\1\2/
    s/\(redr{[^@]*\)@fsfo{\([^}]*\)}/\1\2/
    t cleanredr
}
/@fsfo/{
    :cleanfsfo
    s/\(fsfo{[^@]*\)@cmnd{\([^}]*\)}/\1\2/
    s/\(fsfo{[^@]*\)@func{\([^}]*\)}/\1\2/
    s/\(fsfo{[^@]*\)@sbin{\([^}]*\)}/\1\2/
    t cleanfsfo
}
# Character Entities
#.
# Mark up a few sesitive characters.
#.
s/</\&lt;/g
s/>/\&gt;/g
#.
# Uncomment the folowing two lines (ss) to log the final output, sent to Doxygen.
# s/^.*$/OUT : &/w debug-lexicon.log
# s/^OUT : //
#.
# Lines are reassembled, so branch to end
b
#.
# Move protected content to hold space and mark up other entities.
:protect
h
# Clear out any content that has already been marked up, to prevent futher
# markup on words that should be left alone.
#.
:patternflush
s/\n<@[^}]*}//
s/\n[}]//
t patternflush
s/\n$//
#.
# Swap the pattern and hold buffers and remove unmarked lines and extra
# characters. Basically the inverse of the 'patternflush' action, with
# additional trailing characters stripped.
x
s/^[ ]*[^<][^@][^}]*$//
s/^[ ]*[^<][^@][^\\]*[\\ ()]*\n//
:holdflush
s/}[)(\\ ][)(\\ ]*/}/
s/\n[];)|* ][^\\]*[\\]*//
t holdflush
s/\n$//
#.
# Swap the buffers back.
x
#.
# A special case. Tidy up after commands.
# Redirectors
s/\([^{|] *\)|/\1@redr{|}/g
s/\([^{<>^] *\)\([0-9]* *[<>^][<>^]*[a-zA-z0-9._-]*\)/\1@redr{\2}/g
s/\\}/}\\/g
#.
# Now we can add in 'unsafe' entities that would be too greedy.
# Declared Variables
#:vars
s/\([$%][$%]*\)\([A-Za-z_0-9][A-Za-z_0-9]*\)/@vars{@optr{\1}\2}/g
#.
# Files
s/\([A-Za-z*][A-Za-z]*\.[a-z0-9][a-z0-9]*\)/@fsfo{\1}/g
#.
# Operators
# s/\([^^=|+*&%<>{-]\)\([=|+*&%<>^-][|+*&%<>^-]*\)\([^0-9A-Za-z]\)/\1@optr{\2}\3/g
#.
:commands
#.
# Manually add a few commands not harvested from source.
#.
s,[[:<:]]in[[:>:]],@cmnd{in},g
s,[[:<:]]whoami[[:>:]],@sbin{whoami},g
s,[[:<:]]fishd[[:>:]],@sbin{fishd},g
#.
#### This section is built in the Makefile. Just some formatting examples. #####
#.
#   fish commands (cmnd) <- 4 character code that has a Doxygen alias counterpart
#   template : s/[[:<:]]function[[:>:]]/@cmnd{&}/
#.
#   s,[[:<:]]function[[:>:]],@cmnd{function},g
#   s,[[:<:]]begin[[:>:]],@cmnd{begin},g
#   ...
#.
#   fish functions (func)
#   Populated by 'public' functions' filename.
#.
#   s,[[:<:]]fish_pwd[[:>:]],@func{fish_pwd},g
#   s,[[:<:]]fish_prompt[[:>:]],@func{fish_prompt},g
#   ...
#.
#   Shell Binary (sbin)
#   Populated from completion filenames
#.
#   s,[[:<:]]seq[[:>:]],@sbin{seq},g
#   s,[[:<:]]rm[[:>:]],@sbin{rm},g
#   ...
#.
#   Color Variable (clrv)
#   Populated from __fish_config_interactive.fish
#   Allows fish's 'special' color variables to be identified
#.
#   s,[[:<:]]fish_color_normal[[:>:]],@clrv{fish_color_normal},g
#   s,[[:<:]]fish_color_command[[:>:]],@clrv{fish_color_command},g
#.
# Once all of the commands/functions/variables/special's have been marked up,
# branch back to tidy up and collapse the pattern/hold buffers back to a
# single line.
#.
# b tidy
#.
# Colour lookup functions
#.
# The Makefile will add a table of colour names and values, possibly with
# extra style information, that are used to set defaults in the CSS file.