summaryrefslogtreecommitdiff
path: root/tex/context/base/mkii/verb-pas.mkii
blob: 71c0b5a1252813d613895222c7644b7025099fba (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
%D \module
%D   [       file=verb-pas,
%D        version=1999.12.09,
%D          title=\CONTEXT\ Verbatim Macros,
%D       subtitle=Pretty \PASCAL\ and \MODULA\ Verbatim,
%D         author=Berend de Boer,
%D           date=\currentdate,
%D      copyright={Berend de Boer \& Hans Hagen}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% This module will be cleaned up a bit in the process of more
% flexible verbatim options.

\writestatus{loading}{ConTeXt Verbatim Macros / Pretty PASCAL Verbatim}

%D Typeset Pascal(-like) code:
%D
%D \startbuffer
%D \startPAS
%D program Hello;
%D
%D begin
%D   writeln('hello world.');
%D end.
%D \stopPAS
%D \stopbuffer
%D
%D Berend's preferences:
%D
%D \startbuffer[setup]
%D \setuptyping
%D   [DELPHI]
%D   [palet=,icommand=\bf,vcommand=,ccommand=\it]
%D \stopbuffer

\ifdefined\setupprettyPLtype \else \loadmarkfile{verb-pl} \fi

\unprotect

\doglobal\newif\ifinPASbracketcomment
\doglobal\newif\ifinPASslashstarcomment
\doglobal\newif\ifinPASslashslashcomment


\gdef\PASsetspecials%
  {\PLsetspecials
   \setpretty`\#=32
   \setpretty`\%=41
   \setpretty`\:=41
   \setpretty`\/=43
   \setpretty`\*=44
   \setpretty`\{=45 \setpretty`\}=46 }

\gdef\PASsethandlers%
  {\PLsethandlers
   \installprettyhandler 43 \PAStypefourthree
   \installprettyhandler 44 \PAStypefourfour
   \installprettyhandler 45 \PAStypefourfive
   \installprettyhandler 46 \PAStypefoursix }

\gdef\PASsetcontrols%
  {\PLsetcontrols
   \def\flushrestofverbatimline%
     {\endPLtypesix
      \ifinPASslashslashcomment
        \PASstopslashslashcomment
      \fi
      \PLverbosefalse
      \PLverboseskipped=0}}

\gdef\PASsetvariables
  {\PLsetvariables
   \global\inPASbracketcommentfalse
   \global\inPASslashstarcommentfalse
   \global\inPASslashslashcommentfalse}

\gdef\setupprettyPAStype%
  {\def\prettyidentifier{PAS}%
   \let\PLidentifiers=\PASidentifiers
   \let\PLvariables=\PASvariables
   \PASsetvariables
   \PASsetcontrols
   \PASsethandlers
   \PASsetspecials
   \PLsetdiagnostics}

% the // and /* comments

\gdef\PAStypefourthree%
  {\handlenextnextpretty\doPAStypefourthree\PLtypefourtwo}

\gdef\doPAStypefourthree#1#2%
  {\endPLtypesix
   \ifinPLcomment
     \let\next=\PLtypefourtwo
   \else
     \ifinPLsingle
       \let\next=\PLtypefourtwo
     \else
       \getprettydata{#2}%
       \ifnum\prettytype=43
         \PLverbosecorrection
         \let\next=\PASstartslashslashcomment
       \else\ifnum\prettytype=44
         \PLverbosecorrection
         \let\next=\PASstartslashstarcomment
       \else
         \let\next=\PLtypefourtwo
       \fi\fi
     \fi
   \fi
   \next{#1}#2}

\gdef\PASstartslashstarcomment#1#2%
  {\global\inPLcommenttrue
   \global\inPASslashstarcommenttrue
   \prettynaturalfont
   \beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty}

\gdef\PASstopslashstarcomment#1#2%
  {\beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty
   \verbatimfont
   \global\inPLcommentfalse
   \global\inPASslashstarcommentfalse}

\gdef\PASstartslashslashcomment#1#2%
  {\global\inPLcommenttrue
   \global\inPASslashslashcommenttrue
   \prettynaturalfont
   \beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty}

\gdef\PASstopslashslashcomment%
  {\verbatimfont
   \inPLcommentfalse
   \inPASslashslashcommentfalse}

% \gdef\dodoPAStypefourthree% #1%
%   {\endPLtypesix
%    \handlenextnextpretty\dododoPAStypefourthree\dodododoPLtypefourthree}

% \gdef\dododoPAStypefourthree%
%   {\ifnewpretty\expandafter\handlenewpretty\fi\dodododoPAStypefourthree}

% \gdef\dodododoPAStypefourthree#1#2%
%   {\ifinPLcomment
%      \getpretties{#1}{#2}%
%    \else
%      \global\inPLcommenttrue
%      \PLverbosecorrection
%      \beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty
%    \fi}

\gdef\PAStypefourfour%
  {\handlenextnextpretty\doPAStypefourfour\PLtypefourtwo}

\gdef\doPAStypefourfour#1#2%
  {\ifinPASslashstarcomment
     \getprettydata{#2}%
     \ifnum\prettytype=43
       \PASstopslashstarcomment{#1}#2%
     \else
       \endPLtypesix
       \beginofpretty[\!!prettyfour]\getpretty{#1}\endofpretty
       \expandafter#2%
     \fi
   \else
     \endPLtypesix
     \beginofpretty[\!!prettyfour]\getpretty{#1}\endofpretty
     \expandafter#2%
   \fi}


% the { and } comments
% we assume { is closed by } and do not follow the braindead Standard
% Pascal standard in this respect
% Note: brackets are not output correctly if natural font is \tf.
% Therefore natural font is default to \tttf now (Hans is this ok??)
% You have to use postscript fonts it seems to get brackets in that case.

\gdef\PAStypefourfive#1%
  {\endPLtypesix
   \ifinPLcomment
     \getpretty{#1}%
   \else
     \ifinPLsingle
       \getpretty{#1}%
     \else
       \global\inPLcommenttrue
       \global\inPASbracketcommenttrue
       \prettynaturalfont
       \beginofpretty[\!!prettyone]\getpretty{#1}\endofpretty
     \fi
   \fi}

\gdef\PAStypefoursix#1%
  {\endPLtypesix
   \ifinPASbracketcomment
     \prettynaturalfont\beginofpretty[\!!prettyone]\getpretty{#1}\endofpretty
     \verbatimfont
     \global\inPLcommentfalse
     \global\inPASbracketcommentfalse
   \else
     \getpretty{#1}%
   \fi}


% Standard Pascal keywords (ISO/IEC 7185)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  and array begin case const div do downto else end file
  for function goto if in label mod nil not of or packed
  procedure program record repeat set then to type until
  var while with

% Standard Pascal directives (ISO/IEC 7185)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  forward

% Extended Pascal keywords (ISO/IEC 10206)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  and_then bindable export import module only or_else
  otherwise pow protected qualified restricted

% Extended Pascal directives (ISO/IEC 10206)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  implementation interface

% Object Pascal keywords (draft September 20, 1993)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  abstract class constructor destructor inherited is
  property view

% Object Pascal directives (draft September 20, 1993)

\useprettyidentifiers \PASidentifiers \PASsetspecials
  override

% Delphi keywords

\useprettyidentifiers \PASidentifiers \PASsetspecials
  as asm dispinterface except exports finalization finally
  initialization inline library object out raise resourcestring
  shl shr string threadvar try unit uses xor

% Delphi directives
% the read and write directive have been skipped
% as they're pretty common procedure calls too

\useprettyidentifiers \PASidentifiers \PASsetspecials
  absolute assembler automated cdecl contains default dispid
  dynamic external far implements index message name near
  nodefault overload override package pascal private protected
  public published readonly register reintroduce requires
  resident safecall stdcall stored virtual writeonly

\useprettyidentifiers \PASvariables \PASsetspecials
  not-yet-defined

\protect \endinput