File: perl2html.l

package info (click to toggle)
perl2html 0.9.2-2
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 220 kB
  • ctags: 55
  • sloc: ansic: 565; lex: 268; sh: 152; makefile: 140
file content (268 lines) | stat: -rw-r--r-- 8,974 bytes parent folder | download
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
%{ /* 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

  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 perl2html 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 Perl source file to 
 * a beautifully highlighted HTML file now.
 */

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

%}
%s ONELINECOMMENT
%s STRING1
%s STRING2

id [a-zA-Z_][a-zA-Z01-9_]*
wsnl [\t \n]*
ws   [\t ]*
/* when to break parsing comments, strings, etc to handle special 
   characters: */
onelinecommentnospecial  [^&<>----\n]
string1nospecial         [^&<>----\\\n']
string2nospecial         [^&<>----\\\n$@%*"]
variable		 ((("$"*|"@"|"%"|"*")*){id}((("::"|"."){id})*))|("$"([]_./,\#*?[;!@:0$<>()%=-~^|&+1-9]))

%%
	/* 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); }
\\\'		{  MyStringOutput(yyout, yytext); }
<STRING1>\'	{ 
		  MyStringOutput(yyout, yytext);
		  /* Close the string font */
		  BEGIN 0;
		  ChangeFontTo(yyout, NULL, NORMAL);
		}
<STRING1>\\\\	{ MyStringOutput(yyout, yytext); }
<STRING1>\\\n	{ MyStringOutput(yyout, yytext); }
<STRING1>\n	{ MyStringOutput(yyout, yytext); }
<STRING1>{string1nospecial}+	{ MyStringOutput(yyout, yytext); }

<STRING2>\\[^\\\"\n]	{ MyStringOutput(yyout, yytext); }
<STRING2>{variable}	{ 
		  ChangeFontTo(yyout, NULL, NORMAL); 
		  MyStringOutput(yyout, yytext); 
		  ChangeFontTo(yyout, definelinecolor, NORMAL);
		}
<STRING2>\"	{ 
		  MyStringOutput(yyout, yytext);
		  /* Close the string font */
		  BEGIN 0;
		  ChangeFontTo(yyout, NULL, NORMAL);
		}
<STRING2>\\\\	{ MyStringOutput(yyout, yytext); }
<STRING2>\\\n	{ MyStringOutput(yyout, yytext); }
<STRING2>\n	{ MyStringOutput(yyout, yytext); }
<STRING2>{string2nospecial}+	{ MyStringOutput(yyout, yytext); }

<ONELINECOMMENT>\n	{ 
		  ChangeFontTo(yyout, NULL, NORMAL);
		  MyStringOutput(yyout, yytext); 
		  BEGIN 0;
		}
<ONELINECOMMENT>{onelinecommentnospecial}+	{ 
		  MyStringOutput(yyout, yytext); 
		}

^"import"{ws}.*;	{
			  ChangeFontTo(yyout, definelinecolor, NORMAL);
			  MyStringOutput(yyout, yytext);
			  ChangeFontTo(yyout, NULL, NORMAL);
	}

\"	{
	  /* Start a string */
	  BEGIN STRING2;
	  ChangeFontTo(yyout, definelinecolor, NORMAL);
	  MyStringOutput(yyout, yytext);
	}
\'	{
	  /* Start a string */
	  BEGIN STRING1;
	  ChangeFontTo(yyout, definelinecolor, NORMAL);
	  MyStringOutput(yyout, yytext);
	}
^"#"{onelinecommentnospecial}*	{
	  BEGIN ONELINECOMMENT;
	  ChangeFontTo(yyout, commentcolor, NORMAL);	  
	  MyStringOutput(yyout, yytext);
	}
[\t ]+"#"{onelinecommentnospecial}*	{
	  BEGIN ONELINECOMMENT;
	  ChangeFontTo(yyout, commentcolor, NORMAL);	  
	  MyStringOutput(yyout, yytext);
	}
[{}]	{ MyStringOutput(yyout, yytext); }


^{ws}"sub"{ws}({id}{wsnl})"("([$@%;\\])*(";")?")"	{
		  ChangeFontTo(yyout, keywordcolor, BOLD);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);		  
		}		  
^{ws}"sub"{ws}({id}{wsnl})	{
		/*^{ws}"sub"{ws}({id}{wsnl}|"*")*"("({id}|{wsnl}|"\.\.\."|[][*(),])*")"	*/
		  ChangeFontTo(yyout, keywordcolor, BOLD);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);		  
		}		  

^("use"|"import"|"no"|"package"|"require")({wsnl}|((("$"*|"@"|"%"|"*")*){id}((("::"|"."){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);
		}		  

^("bless"|"caller"|"close"|"continue"|"do"|"else"|"elsif"|"for"|"foreach"|"goto"|"if"|"last"|"local"|"my"|"next"|"open"|"pop"|"push"|"redo"|"return"|"tie"|"split"|"system"|"untie"|"until"|"unless"|"while")/[^a-zA-Z_0123456789] 	{ 
		  ChangeFontTo(yyout, keywordcolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		  /* highlight the rest of the reserved words */
		}
[\t ]+("bless"|"caller"|"close"|"continue"|"do"|"else"|"elsif"|"for"|"foreach"|"goto"|"if"|"last"|"local"|"my"|"next"|"open"|"pop"|"push"|"redo"|"return"|"tie"|"split"|"system"|"untie"|"until"|"unless"|"while")/[^a-zA-Z_0123456789] 	{ 
		  ChangeFontTo(yyout, keywordcolor, NORMAL);
		  MyStringOutput(yyout, yytext);
		  ChangeFontTo(yyout, NULL, NORMAL);
		  /* highlight the rest of the reserved words */
		}

[\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;
  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);
}