File: java2html.l

package info (click to toggle)
java2html 0.9.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 232 kB
  • ctags: 55
  • sloc: ansic: 565; lex: 466; sh: 152; makefile: 139
file content (466 lines) | stat: -rw-r--r-- 15,229 bytes parent folder | download | duplicates (5)
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
%{ /* make it look better in emacs: -*- mode: Makefile; -*- */
/* We need the Makefile mode in emacs to type \t (tab) characters */

/*
  Copyright (C) 1999, 2000 Florian Schintke
  Copyright (C) 1999       Martin Kammerhofer for the CGI feature
  Copyright (C) 2000       Rob Ewan           for the indexing feature

  This is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free 
  Software Foundation; either version 2, or (at your option) any later 
  version. 

  This is distributed in the hope that it will be useful, but WITHOUT 
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  for more details. 

  You should have received a copy of the GNU General Public License with 
  the java2html source package as the 
  file COPYING. If not, write to the Free Software Foundation, Inc., 
  59 Temple Place - Suite 330, Boston, MA 
  02111-1307, USA. 
*/

/* 
 * We build a lexical analyzer that converts a Java or C++ source 
 * file to a beautifully highlighted HTML file now.
 */

#include "colors.h"
#include "mymain.h"

unsigned int oldstate = 0;

%}
%s COMMENT
%s ONELINECOMMENT
%s STRING
 /* We define handling for #define etc to support C++ with this
    program too */
%s DEFINELINE
%s PREPROLINE

id [a-zA-Z_][a-zA-Z01-9_]*
wsnl [\t \n]*
ws   [\t ]*
accessmode ("public"|"private"|"protected")
 /* when to break parsing comments, strings, etc to handle special 
    characters: */
commentnospecial         [^&<>----\\\n*/]
onelinecommentnospecial  [^&<>----\n]
stringnospecial          [^&<>----\\\n"]
definelinenospecial      [^&<>----\\\n"*/]
preprolinenospecial      [^&<>----\n"*/]

%%
	/* This characters have to be recoded everywhere
	 * because the WWW-browsers interpret them in their
	 * own (here not wanted) way.
	 */
"&"	{ MyStringOutput (yyout, "&amp;"); }
"<"	{ MyStringOutput (yyout, "&lt;"); }
">"	{ MyStringOutput (yyout, "&gt;"); }
	/* All character as latin1 greater than dec192 or hexBF */
""	{ MyStringOutput (yyout, "&Agrave;"); }
""	{ MyStringOutput (yyout, "&Aacute;"); }
""	{ MyStringOutput (yyout, "&Acirc;"); }
""	{ MyStringOutput (yyout, "&Atilde;"); }
""	{ MyStringOutput (yyout, "&Auml;"); } 
""	{ MyStringOutput (yyout, "&Aring;"); }
""	{ MyStringOutput (yyout, "&AElig;"); }
""	{ MyStringOutput (yyout, "&Ccedil;"); }
""	{ MyStringOutput (yyout, "&Egrave;"); }
""	{ MyStringOutput (yyout, "&Eacute;"); }
""	{ MyStringOutput (yyout, "&Ecirc;"); } 
""	{ MyStringOutput (yyout, "&Euml;"); }  
""	{ MyStringOutput (yyout, "&Igrave;"); }
""	{ MyStringOutput (yyout, "&Iacute;"); }
""	{ MyStringOutput (yyout, "&Icirc;"); } 
""	{ MyStringOutput (yyout, "&Iuml;"); }  
	/* ""	{ MyStringOutput (yyout, "", yytext); } */
""	{ MyStringOutput (yyout, "&Ntilde;"); }
""	{ MyStringOutput (yyout, "&Ograve;"); }
""	{ MyStringOutput (yyout, "&Oacute;"); }
""	{ MyStringOutput (yyout, "&Ocirc;"); } 
""	{ MyStringOutput (yyout, "&Otilde;"); }
""	{ MyStringOutput (yyout, "&Ouml;"); }  
	/* ""	{ MyStringOutput (yyout, "", yytext); } */
""	{ MyStringOutput (yyout, "&Oslash;"); }
""	{ MyStringOutput (yyout, "&Ugrave;"); }
""	{ MyStringOutput (yyout, "&Uacute;"); }
""	{ MyStringOutput (yyout, "&Ucirc;"); } 
""	{ MyStringOutput (yyout, "&Uuml;"); }  
""	{ MyStringOutput (yyout, "&Yacute;"); }
""	{ MyStringOutput (yyout, "&THORN;"); }
""	{ MyStringOutput (yyout, "&szlig;"); }
""	{ MyStringOutput (yyout, "&agrave;"); }
""	{ MyStringOutput (yyout, "&aacute;"); }
""	{ MyStringOutput (yyout, "&acirc;"); } 
""	{ MyStringOutput (yyout, "&atilde;"); }  
""	{ MyStringOutput (yyout, "&auml;"); }
""	{ MyStringOutput (yyout, "&aring;"); }
""	{ MyStringOutput (yyout, "&aelig;"); }
""	{ MyStringOutput (yyout, "&ccedil;"); }
""	{ MyStringOutput (yyout, "&egrave;"); }
""	{ MyStringOutput (yyout, "&eacute;"); }
""	{ MyStringOutput (yyout, "&ecirc;"); } 
""	{ MyStringOutput (yyout, "&euml;"); }  
""	{ MyStringOutput (yyout, "&igrave;"); }
""	{ MyStringOutput (yyout, "&iacute;"); }
""	{ MyStringOutput (yyout, "&icirc;"); } 
""	{ MyStringOutput (yyout, "&iuml;"); }  
""	{ MyStringOutput (yyout, "&eth;"); }
""	{ MyStringOutput (yyout, "&ntilde;"); }
""	{ MyStringOutput (yyout, "&ograve;"); }
""	{ MyStringOutput (yyout, "&oacute;"); }
""	{ MyStringOutput (yyout, "&ocirc;"); } 
""	{ MyStringOutput (yyout, "&otilde;"); }  
""	{ MyStringOutput (yyout, "&ouml;"); }
	/* ""	{ MyStringOutput (yyout, "", yytext); } */
""	{ MyStringOutput (yyout, "&oslash;"); }
""	{ MyStringOutput (yyout, "&ugrave;"); }
""	{ MyStringOutput (yyout, "&uacute;"); }
""	{ MyStringOutput (yyout, "&ucirc;"); } 
""	{ MyStringOutput (yyout, "&uuml;"); }  
""	{ MyStringOutput (yyout, "&yacute;"); }
""	{ MyStringOutput (yyout, "&thorn;"); }
""	{ MyStringOutput (yyout, "&yuml;"); }

\\\"		{  MyStringOutput(yyout, yytext); }
<STRING>\\\\	{ MyStringOutput(yyout, yytext); }
<STRING>\"	{ 
		  MyStringOutput(yyout, yytext);
		  switch (oldstate)
		  {
                  case 0: 
		    /* Close the string font */
		    BEGIN 0;
		    ChangeFontTo(yyout, NULL, NORMAL);
		    break;
		  case DEFINELINE: 
		    /* close a string in a defineline */
		    BEGIN DEFINELINE;
		    oldstate = 0;
		    ChangeFontTo(yyout, definelinecolor, NO_CHANGE);
		    break;
		  case PREPROLINE:
		    /* close a string in a preprocessor line */
		    BEGIN PREPROLINE;
		    oldstate = 0;
		    ChangeFontTo(yyout, preprolinecolor, NO_CHANGE);
		    break;
		  default:
		    fprintf (stderr, "internal error: bad oldstate\n");
		  }
		}
<STRING>\'	{
		  MyStringOutput(yyout, yytext);
		}		  
<STRING>\\\n	{ 
		  MyStringOutput(yyout, yytext);
		  if (oldstate == PREPROLINE) oldstate = 0; 
		}
<STRING>\n	{
		  switch (oldstate)
		  {
		  case 0: 
		    BEGIN STRING;
		    MyStringOutput(yyout, yytext);
		    break;
		  case DEFINELINE:
		  case PREPROLINE:
		    /* This was a string in a define or a */
		    /* preprocessor line */
		    /* With this newline we close this line */
		    /* and continue scanning the string until */
		    /* it is closed */
		    BEGIN STRING;
		    oldstate = 0;	
		    ChangeFontTo(yyout, NULL, NORMAL);    
		    MyStringOutput(yyout, yytext);
		    /* Now it is only a string */
		    ChangeFontTo(yyout, stringcolor, NORMAL);
		    break;
		  default:
		    fprintf (stderr, "internal error: bad oldstate\n");
		  }
		}
<STRING>{stringnospecial}+	{ MyStringOutput(yyout, yytext); }

<ONELINECOMMENT>\n	{ 
		  ChangeFontTo(yyout, NULL, NORMAL);
		  MyStringOutput(yyout, yytext); 
		  BEGIN 0;
		}
<ONELINECOMMENT>{onelinecommentnospecial}+	{ 
		  MyStringOutput(yyout, yytext); 
		}
<COMMENT>"/*"	{ MyStringOutput(yyout,yytext); }
<COMMENT>\\\n	{ 
		  MyStringOutput(yyout, yytext);
		  if (oldstate == PREPROLINE) oldstate = 0; 
		}
<COMMENT>\n	{
		  switch (oldstate)
		  {
		  case 0: 
		    BEGIN COMMENT;
		    MyStringOutput(yyout, yytext);
		    break;
		  case DEFINELINE:
		  case PREPROLINE:
		    /* this was a comment in a define or preprocessor */
		    /* line. So we close this line and start a normal */
		    /* comment scanning */
		    BEGIN COMMENT;
		    oldstate = 0;	
		    ChangeFontTo(yyout, NULL, NORMAL);
		    MyStringOutput(yyout, yytext);
		    ChangeFontTo(yyout, commentcolor, NORMAL);
		    break;
		  default:
		    fprintf (stderr, "internal error: bad oldstate\n");
		  }
		}
<COMMENT>{commentnospecial}+	{ MyStringOutput(yyout, yytext); }
<COMMENT>{commentnospecial}/[^/]	{ MyStringOutput(yyout, yytext); }
<COMMENT>"*/"	{
		  MyStringOutput(yyout, yytext);
		  switch (oldstate)
		  {
                  case 0: 
		    BEGIN 0; 
		    ChangeFontTo(yyout, NULL, NORMAL);	
		    break;
		  case DEFINELINE: 
		    BEGIN DEFINELINE;
		    oldstate = 0;
		    ChangeFontTo(yyout, definelinecolor, NO_CHANGE);
		    break;
		  case PREPROLINE:
		    BEGIN PREPROLINE;
		    oldstate = 0;
		    ChangeFontTo(yyout, preprolinecolor, NO_CHANGE);
		    break;
		  default:
		    fprintf (stderr, "internal error: bad oldstate\n");
		  }
		}
<COMMENT>{commentnospecial}\/	{ MyStringOutput(yyout, yytext); }
<COMMENT>"//"	{ MyStringOutput(yyout,yytext); }

<DEFINELINE>\"		{
		  /* Start a string in a defineline */
		  BEGIN STRING;
		  oldstate = DEFINELINE;
		  ChangeFontTo(yyout, stringcolor, NO_CHANGE);
		  MyStringOutput(yyout, yytext);
		}
<DEFINELINE>"/*"	{
		  /* Start a comment in a defineline */
		  BEGIN COMMENT;
		  oldstate = DEFINELINE;
		  ChangeFontTo(yyout, commentcolor, NO_CHANGE);
		  MyStringOutput(yyout, yytext);
		}
<DEFINELINE>\\\n	{ MyStringOutput(yyout, yytext); }
<DEFINELINE>\n	{
		  /* close a defineline */
		  BEGIN 0;
		  oldstate = 0;
		  ChangeFontTo(yyout, NULL, NORMAL);
		  MyStringOutput(yyout, yytext);
		}
<DEFINELINE>{definelinenospecial}+	{ MyStringOutput(yyout, yytext); }
^{ws}("#"|"??=")("define") |
^{ws}("#"|"??=")("undef")	{ 
		  /* Start a define line */
		  BEGIN DEFINELINE;
		  ChangeFontTo(yyout, definelinecolor, BOLD);
		  MyStringOutput(yyout, yytext); 
		}
<PREPROLINE>\"	{
		  /* Start a string in a preproline */
		  BEGIN STRING;
		  oldstate = PREPROLINE;
		  ChangeFontTo(yyout, stringcolor, NO_CHANGE);
		  MyStringOutput(yyout, yytext);
		}
<PREPROLINE>"/*"	{
		  /* Start a comment in a preproline */
		  BEGIN COMMENT;
		  oldstate = PREPROLINE;
		  ChangeFontTo(yyout, commentcolor, NO_CHANGE);
		  MyStringOutput(yyout, yytext);
		}
<PREPROLINE>\n	{
		  /* Close a preproline */
		  BEGIN 0;
		  oldstate = 0;
		  ChangeFontTo(yyout, NULL, NORMAL);
		  MyStringOutput(yyout, yytext);
		}
<PREPROLINE>{preprolinenospecial}+	{ MyStringOutput(yyout, yytext); }
^[\t ]*("#"|"??=")("") |
^[\t ]*("#"|"??=")("elif") |
^[\t ]*("#"|"??=")("else") |
^[\t ]*("#"|"??=")("endif") | 
^[\t ]*("#"|"??=")("error") | 
^[\t ]*("#"|"??=")("if ! defined") | 
^[\t ]*("#"|"??=")("if defined") |
^[\t ]*("#"|"??=")("if") |
^[\t ]*("#"|"??=")("ifdef") |
^[\t ]*("#"|"??=")("ifndef") |
^[\t ]*("#"|"??=")("include") |
^[\t ]*("#"|"??=")("line") |
^[\t ]*("#"|"??=")("pragma")	{
		  /* Start a preproline */
		  BEGIN PREPROLINE;
		  ChangeFontTo(yyout, preprolinecolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  /* highlight preprozessor statements */
		}
^"import"{ws}.*;	{
			  ChangeFontTo(yyout, definelinecolor, NORMAL);
			  MyStringOutput(yyout, yytext);
			  ChangeFontTo(yyout, NULL, NORMAL);
	}

\"	{
	  /* Start a string */
	  BEGIN STRING;
	  oldstate = 0;
	  ChangeFontTo(yyout, stringcolor, NORMAL);
	  MyStringOutput(yyout, yytext);
	}
\'([^\n']+|"\\\'")\'	{
	  MyStringOutput(yyout, yytext);
	}
"/*"	{
	  /* Start a comment */
	  BEGIN COMMENT;
	  oldstate = 0;
	  ChangeFontTo(yyout, commentcolor, NORMAL);
	  MyStringOutput(yyout, yytext);
	}
"//"	{
	  BEGIN ONELINECOMMENT;
	  ChangeFontTo(yyout, commentcolor, NORMAL);	  
	  MyStringOutput(yyout, yytext);
	}
[{}]	{ MyStringOutput(yyout, yytext); }


^{ws}{accessmode}{ws}({id}{wsnl}|"*")*"("({id}|{wsnl}|"\.\.\."|[][*(),])*")"	{
		  /* Write a function definition */
		  ChangeFontTo(yyout, keywordcolor, BOLD);
		  /* The labeling isn't stable for C++ */
		  /* AddLabelForFunction(yyout, yytext); */
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);		  
		}		  

^({accessmode}{ws}|{ws})"class"{ws}{id}({id}{ws})*	{
		  ChangeFontTo(yyout, keywordcolor, BOLD);
		  AddLabelForClass(yyout, yytext);
		  MyStringOutput(yyout, yytext);
		  EndLabelTag(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);		  
		}		  

^"typedef"({id}|{ws}|[*{}])*";"	{
		  ChangeFontTo(yyout, keywordcolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		}		  
"struct "{id}	{
		  ChangeFontTo(yyout, keywordcolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		}		  
^{ws}{id}":"    {
		  ChangeFontTo(yyout, labelcolor, BOLD);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		}		  

(char|double|float|int|long|short|signed|void|unsigned)/[^a-zA-Z_0123456789]	{ 
		  MyStringOutput(yyout, yytext);
		  /* highlight basic types */
		}

(char|double|float|int|long|short|signed|void|unsigned)\*/[^a-zA-Z_0123456789]	{ 
		  MyStringOutput(yyout, yytext);
		  /* highlight basic pointer types */
		}
(char|double|float|int|long|short|signed|void|unsigned)" *"	{ 
		  MyStringOutput(yyout, yytext);
		  /* highlight basic pointer types in the common style*/
		}

("auto"|"const"|"extern"|"register"|"static"|"volatile")/[^a-zA-Z_0123456789] 	{ 
		  MyStringOutput(yyout, yytext);
		  /* highlight attributes for types */
		}		  

("break"|"case"|"continue"|"default"|"do"|"else"|"enum"|"for"|"goto"|"if"|"return"|"sizeof"|"struct"|"switch"|"typedef"|"union"|"while"|"try"|"catch"|"throw"|"throws")/[^a-zA-Z_0123456789] 	{ 
		  ChangeFontTo(yyout, keywordcolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		  /* highlight the rest of the reserved words */
		}

("abort"|"abs"|"acos"|"asctime"|"asin"|"atan"|"atan2"|"atexit"|"atof"|"atoi"|"atol"|"bsearch"|"calloc"|"ceil"|"clearerr"|"clock"|"cos"|"cosh"|"ctime"|"difftime"|"div"|"exit"|"exp"|"fabs"|"fclose"|"feof"|"ferror"|"fflush"|"fgetc"|"fgetpos"|"fgets"|"floor"|"fmod"|"fopen"|"fprintf"|"fputc"|"fputs"|"fread"|"free"|"freopen"|"frexp"|"fscanf"|"fseek"|"fsetpos"|"ftell"|"fwrite"|"getc"|"getchar"|"getenv"|"gets"|"gmtime"|"isalnum"|"isalpha"|"iscntrl"|"isdigit"|"isgraph"|"islower"|"isprint"|"ispunct"|"isspace"|"isupper"|"isxdigit"|"labs"|"ldexp"|"ldiv"|"localtime"|"log"|"log10"|"longjmp"|"malloc"|"memchr"|"memcmp"|"memcpy"|"memmove"|"memset"|"mktime"|"modf"|"perror"|"pow"|"printf"|"putc"|"putchar"|"puts"|"qsort"|"raise"|"rand"|"realloc"|"remove"|"rename"|"rewind"|"scanf"|"setbuf"|"setvbuf"|"setjmp"|"signal"|"sin"|"sinh"|"sprintf"|"sqrt"|"srand"|"sscanf"|"strcat"|"strchr"|"strcmp"|"strcpy"|"strcspn"|"strerror"|"strftime"|"strlen"|"strncat"|"strncmp"|"strncpy"|"strpbrk"|"strrchr"|"strspn"|"strstr"|"strtod"|"strtok"|"strtol"|"strtul"|"system"|"tan"|"tanh"|"time"|"tmpfile"|"tmpnam"|"tolower"|"toupper"|"ungetc"|"vfprintf"|"vprintf"|"vsprintf")/[^a-zA-Z_0123456789]	{
		  MyStringOutput(yyout, yytext);
		  /* highlight lybrary functions */
		}

("close"|"create"|"fstat"|"lseek"|"open"|"read"|"abrk"|"stat"|"unlink"|"write")/[^a-zA-Z_0123456789]	{
		  MyStringOutput(yyout, yytext);
		  /* highlight basic system calls */
		}

[\t ]+		{ 
		  MyStringOutput(yyout, yytext);
		  /* let whitespaces like they are */
		}

[a-zA-Z_][a-zA-Z_0123456789]*	{
		  MyStringOutput(yyout, yytext);
		}

.		{ 
		  MyStringOutput(yyout, yytext);
		}
\n		{ 
		  MyStringOutput(yyout, yytext);
		}

%%

void 
StartNewYylex(FILE * in, FILE * out)
{
  BEGIN 0;
  oldstate              = 0;
  yyin                  = in;
  yyout                 = out;
  config.lineNumber     = 1;
  config.needLabel      = 1;
  config.currentColor   = NULL;
  config.currentWeight  = NORMAL;
  config.suppressOutput = config.indexOnly;

  yylex();
}

int
main(int argc, char *argv[])
{
  return MyMain(argc, argv);
  /* unreachable, but suppresses compiler warning. */
  yyunput(0, NULL);
}