blob: 26f4cac9dc49e7257deee983e303b1b576502359 (
plain) (
blame)
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
|
###############################################################################
# #
# Lout @HaskellSetup package for formatting Haskell programs #
# #
# Version 1.0 #
# Thorsten Seitz #
# 17 December 2001 #
# #
# Version 1.1 (bug fixes) #
# Gabor Greif #
# 29 June 2007 #
# #
# This package uses a filtered body parameter to convert program source #
# code into Lout source. The filter program is prg2lout, which is #
# distributed with Lout and should be compiled and installed wherever #
# Lout itself is. #
# #
###############################################################################
export @Haskell
def @HaskellSetup
named pipe { } # pipe through this first
named numbered { No } # want lines numbered?
named blanknumbered { Yes } # blank lines numbered?
named style
named @OrIfPlain left x right y
{ @BackEnd @Case { PlainText @Yield y else @Yield x } }
{ symbol @OrIfPlain fixed } # print style
# the following options apply when style is "fixed"
named fixedfont { Courier }# font family
named fixedsize { -1.0p } # font size
named fixedline { 1.0vx } # line-space
named fixedblanklinescale { 1.0 } # blank-line scale
named fixedspace { lout } # spacing mode
named fixedtabin { 4 } # tab interval
named fixedtabout { 4s } # tab width
named fixedbraces { Base } # braces face
named fixedidentifiers { Base } # identifier face
named fixedkeywords { Base } # keyword face
named fixedoperators { Base } # operator face
named fixednumbers { Base } # number face
named fixedstrings { Base } # string face
named fixedcomments { Base } # comment face
named fixedlinenumbers { Base } # line numbers face
named fixedleftbracesformat right @Body { @Body } # left braces format
named fixedrightbracesformat right @Body { @Body } # right braces format
named fixedidentifiersformat right @Body { @Body } # identifier format
named fixedkeywordsformat right @Body { @Body } # keyword format
named fixedoperatorsformat right @Body { @Body } # operators format
named fixednumbersformat right @Body { @Body } # number format
named fixedstringsformat right @Body { @Body } # string format
named fixedcommentsformat right @Body { @Body } # comment format
named fixedlinenumbersformat right @Body { @Body } # line nums format
# the following options apply when style is "varying"
named varyingfont { } # font family
named varyingsize { 1.0f } # font size
named varyingline { 1.0vx } # line-space
named varyingblanklinescale { 1.0 } # blank-line scale
named varyingspace { lout } # spacing mode
named varyingtabin { 4 } # tab interval
named varyingtabout { 1.5f } # tab width
named varyingbraces { Base } # braces face
named varyingidentifiers { Slope } # identifier face
named varyingkeywords { Bold } # keyword face
named varyingoperators { Base } # operator face
named varyingnumbers { Base } # number face
named varyingstrings { Slope } # string face
named varyingcomments { Base } # comment face
named varyinglinenumbers { Base } # line numbers face
named varyingleftbracesformat right @Body { @Body } # left braces format
named varyingrightbracesformat right @Body { @Body } # right braces format
named varyingidentifiersformat right @Body { @Body } # identifier format
named varyingkeywordsformat right @Body { @Body } # keyword format
named varyingoperatorsformat right @Body { @Body } # operators format
named varyingnumbersformat right @Body { @Body } # number format
named varyingstringsformat right @Body { @Body } # string format
named varyingcommentsformat right @Body { @Body } # comment format
named varyinglinenumbersformat right @Body { @Body } # line nums format
# the following options apply when style is "symbol"
named symbolfont { } # font family
named symbolsize { 1f } # font size
named symbolline { 1.0vx } # line-space
named symbolblanklinescale { 1.0 } # blank-line scale
named symbolspace { lout } # spacing mode
named symboltabin { 4 } # tab interval
named symboltabout { 1.7f } # tab width
named symbolbraces { Base } # braces face
named symbolidentifiers { Slope } # identifier face
named symbolkeywords { Bold } # keyword face
named symboloperators { Slope } # operator face
named symbolnumbers { Base } # number face
named symbolstrings { Slope } # string face
named symbolcomments { Base } # comment face
named symbollinenumbers { Base } # line numbers face
named symbolidentifiersformat right @Body { 0.3s @Space {"" @Body} } # identifier format (with italic correction)
named symbolkeywordsformat right @Body { @Body } # keyword format
named symboloperatorsformat right @Body { 0.5s @Space {"" @Body ""}} # operators format
named symbolnumbersformat right @Body { @Body } # number format
named symbolstringsformat right @Body { @Body } # string format
named symbolcommentsformat right @Body { @Body } # comment format
named symbollinenumbersformat right @Body { @Body } # line nums format
@Begin
export
@PI @PK @PO @PN @PS @PC @PCL @PL @PA @PM @PD
@PLAMBDA @PCIRC @PPLUSPLUS @PCOLON @PDOUBLECOLON
@A "$>"
def @Haskell
named style { style } # style
named numbered { numbered } # want numbered lines?
named blanknumbered { blanknumbered } # numbered blank lines?
named pipe { pipe } # pipe through this first
named font { dft } # font family
named size { dft } # font size
named line { dft } # line-space
named blanklinescale { dft } # blank-line scale
named space { dft } # spacing mode
named tabin { dft } # tab interval
named tabout { dft } # tab width
named braces { dft } # braces font
named identifiers { dft } # ident. font
named keywords { dft } # keyword font
named operators { dft } # operator font
named numbers { dft } # number font
named strings { dft } # string font
named comments { dft } # comment font
named linenumbers { dft } # line numbers font
body @Body # filtered, see below
@Begin
def @Test # returns x unless x is dft
left x
named iffixed {}
named ifvarying {}
named ifsymbol {}
{
x @Case {
dft @Yield {
style @Case {
fixed @Yield { iffixed }
varying @Yield { ifvarying }
symbol @Yield { ifsymbol }
}
}
else @Yield x
}
}
def @Else # returns x, or y if x is dft
left x
right y
{
x @Case {
dft @Yield y
else @Yield x
}
}
def @InitTab
{
tabin @Test
iffixed { fixedtabin }
ifvarying { varyingtabin }
ifsymbol { symboltabin }
}
def @InitTabWidth
{
tabout @Test
iffixed { fixedtabout }
ifvarying { varyingtabout }
ifsymbol { symboltabout }
}
def @Filter
{
def wantnumbered
{
numbered @Case {
{ No no } @Yield ""
{ Yes yes } @Yield "-L"
else @Yield { "-L"numbered }
}
}
def wantblanknumbered
{
blanknumbered @Case {
{ No no } @Yield "-M"
{ NoPrint noprint } @Yield "-N"
{ Yes yes } @Yield ""
}
}
pipe @Case {
"" @Yield {
"prg2lout -r -lHaskell" wantblanknumbered wantnumbered
-i{@FilterIn} -o{@FilterOut} -e{@FilterErr}
-t{@InitTab} -T{@InitTabWidth}
}
else @Yield {
"cat" @FilterIn "|" pipe "|"
"prg2lout -r -lHaskell" wantblanknumbered wantnumbered
-o{@FilterOut} -e{@FilterErr}
-t{@InitTab} -T{@InitTabWidth}
}
}
}
def @InitFontFamily
{
font @Test
iffixed { fixedfont }
ifvarying { varyingfont }
ifsymbol { symbolfont }
}
def @InitSize
{
size @Test
iffixed { fixedsize }
ifvarying { varyingsize }
ifsymbol { symbolsize }
}
def @InitLine
{
line @Test
iffixed { fixedline }
ifvarying { varyingline }
ifsymbol { symbolline }
}
def @InitBLS
{
blanklinescale @Test
iffixed { fixedblanklinescale }
ifvarying { varyingblanklinescale }
ifsymbol { symbolblanklinescale }
}
def @InitSpace
{
space @Test
iffixed { fixedspace }
ifvarying { varyingspace }
ifsymbol { symbolspace }
}
def @PO # for formatting operators
right x
{
style @Case {
fixed @Yield fixedoperatorsformat {
{ operators @Else fixedoperators } @Font x
}
varying @Yield varyingoperatorsformat {
{ operators @Else varyingoperators } @Font x
}
symbol @Yield symboloperatorsformat {
{ operators @Else symboloperators } @Font x
}
}
}
def @A # get characters from the Adobe Symbol font
named sym {}
right x
{
style @Case {
symbol @Yield { { Symbol Base } @Font @Char sym }
else @Yield { x }
}
}
# deleted by JeffK here and in prg2lout.c, who could not see the point
#def @APO
# left sym
# right x
#{
# @PO sym @A x
#}
def @PI # for formatting identifiers
right x
{
style @Case {
fixed @Yield fixedidentifiersformat {
{ identifiers @Else fixedidentifiers } @Font x
}
varying @Yield varyingidentifiersformat {
{ identifiers @Else varyingidentifiers } @Font x
}
symbol @Yield symbolidentifiersformat {
{ identifiers @Else symbolidentifiers } @Font x
}
}
}
def @PK # for formatting keywords
right x
{
style @Case {
fixed @Yield fixedkeywordsformat {
{ keywords @Else fixedkeywords } @Font x
}
varying @Yield varyingkeywordsformat {
{ keywords @Else varyingkeywords } @Font x
}
symbol @Yield symbolkeywordsformat {
{ keywords @Else symbolkeywords } @Font x
}
}
}
def @PN # for formatting numbers
right x
{
style @Case {
fixed @Yield fixednumbersformat {
{ numbers @Else fixednumbers } @Font x
}
varying @Yield varyingnumbersformat {
{ numbers @Else varyingnumbers } @Font x
}
symbol @Yield symbolnumbersformat {
{ numbers @Else symbolnumbers } @Font x
}
}
}
def @PS # for formatting strings
right x
{
style @Case {
fixed @Yield fixedstringsformat {
{ strings @Else fixedstrings } @Font x
}
varying @Yield varyingstringsformat {
{ strings @Else varyingstrings } @Font x
}
symbol @Yield symbolstringsformat {
{ strings @Else symbolstrings } @Font x
}
}
}
def @PCnoDelim
right x
{
style @Case {
fixed @Yield fixedcommentsformat {
{ comments @Else fixedcomments } @Font x
}
varying @Yield varyingcommentsformat {
{ comments @Else varyingcomments } @Font x
}
symbol @Yield symbolcommentsformat {
{ comments @Else symbolcomments } @Font x
}
}
}
def @Symb right x { { Symbol Base } @Font @Char x }
def @PC # for formatting comments
right x
{
@PCnoDelim { "{"{@Symb minus}x{@Symb minus}"}" }
}
def @PCL # for formatting line comments
right x
{
@PCnoDelim { {@Symb minus} &0.5s {@Symb minus}{x} }
}
def @PL # for formatting line numbers
right x
{
style @Case {
fixed @Yield fixedlinenumbersformat {
{ linenumbers @Else fixedlinenumbers } @Font x
}
varying @Yield varyinglinenumbersformat {
{ linenumbers @Else varyinglinenumbers } @Font x
}
symbol @Yield symbollinenumbersformat {
{ linenumbers @Else symbollinenumbers } @Font x
}
}
}
def @PA # for formatting asterisks
{
@PO @BackEnd @Case {
PlainText @Yield "*"
else @Yield { @Symb asteriskmath }
}
}
def @PM # for formatting minus signs
{
@PO @BackEnd @Case {
PlainText @Yield "-"
else @Yield style @Case {
fixed @Yield "-"
else @Yield { { Symbol Base } @Font @Char "minus" }
}
}
}
def @PD # for formatting dots, if wanted larger
{
@PO @BackEnd @Case {
PlainText @Yield "."
else @Yield { "1.4f" @Font "." &"0.05f" }
}
}
def @PLAMBDA
right x
{
style @Case {
symbol @Yield { { Symbol Base } @Font @Char lambda |0.5s }
else @Yield { x }
}
}
def @PCIRC
right x
{
style @Case {
symbol @Yield { @PO {/0.3fo 0i @Space {"" @Symb degree } } }
else @Yield { @PO x }
}
}
def @PPLUSPLUS
right x
{
style @Case {
symbol @Yield { @PO {@Symb plus |0.3fo @Symb plus} }
else @Yield { @PO x }
}
}
def @PCOLON
{
@PO ":"
}
def @PDOUBLECOLON
right x
{
style @Case {
symbol @Yield { @PO {: |0.8s :} }
else @Yield { @PO x }
}
}
macro "$>" { {} & }
{ @InitFontFamily Base @InitSize } @Font @InitSpace @Space
{ @InitLine lines nohyphen "blanklinescale" @InitBLS } @Break @Body
@End @Haskell
@End @HaskellSetup
|