|
|
/* FILE: pov2html.yy */
/************************************************************************/
/* Code section */
/************************************************************************/
%{
/* Syntax highlite a POV-Ray 3.5 script using FLEX. Output is HTML.
* by Mike Lundy - May 10, 2003
*
* To complie:
* flex pov.yy
* gcc lex.yy.c -lfl -opov2html
*
* Usage: pov2html <filename.pov >filename.html
* or: pov2html filename.pov >filename.html
* or: pov2html filename.pov filename.html
*/
#define PAGE_COLOR "#FDF5E6"
#define TEXT_COLOR "#000000"
#define KEYWORD_COLOR "#0000BF"
#define DIRECTIVE_COLOR "#0000FF"
#define COMMENT_COLOR "#007F00"
#define STRING_COLOR "#BF0000"
#define INTEGER_COLOR "#800080"
#define FLOAT_COLOR "#800080"
#define OPERATOR_COLOR "#FF0000"
#define DELIMITER_COLOR "#008080"
#define FONT_TAG(tExT, cOlOr) fprintf(yyout, "<FONT COLOR=\"%s\">%s</FONT>",
(cOlOr), (tExT));
#define ECHO fprintf(yyout, "%s", yytext);
#define AUTHOR "mwl### [at] netscapenet"
/* tidy HTML source on '//' type comments */
char *kill_EOL (char* line)
{
char *p1 = line;
int len = 0;
while(*p1++) len++;
if( (line[--len]) == '\n') { line[len] = 0; }
return line;
}
%}
/************************************************************************/
/* Definition section */
/************************************************************************/
%option noyywrap
DIGIT [0-9]
INTEGER {DIGIT}+
FLOAT ({DIGIT}+"."{DIGIT}*)|("."{DIGIT}+)|({DIGIT}+".")
STRING \"[^"]*[\"]*\"
OPERATOR [+*/|!:?=]|"-"
DELIMITER [;{}]
DIRECTIVE
break|case|debug|declare|default|else|end|error|fclose|fopen|if|ifdef|ifndef|include|local|macro|range|read|render|statistics|switch|undef|version|warning|while|write
%x comment1
%x comment2
/************************************************************************/
/* Rules section */
/************************************************************************/
%%
"/*" { BEGIN(comment1); fprintf(yyout, "<FONT COLOR=\"%s\">%s",
COMMENT_COLOR, yytext); }
<comment1>[^*\n]* ECHO;
<comment1>[^*\n]*\n ECHO;
<comment1>"*"+[^*/\n]* ECHO;
<comment1>"*"+[^*/\n]*\n ECHO;
<comment1>"*"+"/" { fprintf(yyout, "%s%s", yytext, "</FONT>"); BEGIN(INITIAL);
}
"//" { BEGIN(comment2); fprintf(yyout, "<FONT COLOR=\"%s\">%s",
COMMENT_COLOR, yytext);; }
<comment2>\n+ { fprintf(yyout, "%s%s", kill_EOL(yytext), "</FONT>\n");
BEGIN(INITIAL); }
<comment1,comment2>< { fprintf(yyout, "%s", "<" ); }
<comment1,comment2>> { fprintf(yyout, "%s", ">" ); }
<comment1,comment2>& { fprintf(yyout, "%s", "&" ); }
<comment1,comment2>\" { fprintf(yyout, "%s", """); }
<INITIAL>< { FONT_TAG("<", OPERATOR_COLOR); }
<INITIAL>> { FONT_TAG(">", OPERATOR_COLOR); }
<INITIAL>& { FONT_TAG("&", OPERATOR_COLOR); }
<INITIAL>\" { FONT_TAG(""", STRING_COLOR); }
{STRING} { FONT_TAG(yytext, STRING_COLOR); }
{OPERATOR} { FONT_TAG(yytext, OPERATOR_COLOR); }
{INTEGER} { FONT_TAG(yytext, INTEGER_COLOR); }
{FLOAT} { FONT_TAG(yytext, FLOAT_COLOR); }
{DELIMITER} { FONT_TAG(yytext, DELIMITER_COLOR); }
#+[ \t]*{DIRECTIVE}+ { FONT_TAG(yytext, DIRECTIVE_COLOR); }
aa_level |
aa_threshold |
abs |
absorption |
accuracy |
acos |
acosh |
adaptive |
adc_bailout |
agate |
agate_turb |
all |
all_intersections |
alpha |
altitude |
always_sample |
ambient |
ambient_light |
angle |
aperture |
append |
arc_angle |
area_light |
array |
asc |
ascii |
asin |
asinh |
assumed_gamma |
atan |
atan2 |
atanh |
autostop |
average |
b_spline |
background |
bezier_spline |
bicubic_patch |
black_hole |
blob |
blue |
blur_samples |
bounded_by |
box |
boxed |
bozo |
break |
brick |
brick_size |
brightness |
brilliance |
bump_map |
bump_size |
bumps |
camera |
case |
caustics |
ceil |
cells |
charset |
checker |
chr |
circular |
clipped_by |
clock |
clock_delta |
clock_on |
collect |
color |
color_map |
colour |
colour_map |
component |
composite |
concat |
cone |
confidence |
conic_sweep |
conserve_energy |
contained_by |
control0 |
control1 |
coords |
cos |
cosh |
count |
crackle |
crand |
cube |
cubic |
cubic_spline |
cubic_wave |
cutaway_textures |
cylinder |
cylindrical |
debug |
declare |
default |
defined |
degrees |
density |
density_file |
density_map |
dents |
df3 |
difference |
diffuse |
dimension_size |
dimensions |
direction |
disc |
dispersion |
dispersion_samples |
dist_exp |
distance |
div |
double_illuminate |
eccentricity |
else |
emission |
end |
error |
error_bound |
evaluate |
exp |
expand_thresholds |
exponent |
exterior |
extinction |
face_indices |
facets |
fade_color |
fade_colour |
fade_distance |
fade_power |
falloff |
falloff_angle |
false |
fclose |
file_exists |
filter |
final_clock |
final_frame |
finish |
fisheye |
flatness |
flip |
floor |
focal_point |
fog |
fog_alt |
fog_offset |
fog_type |
fopen |
form |
frame_number |
frequency |
fresnel |
function |
gather |
gif |
global_lights |
global_settings |
gradient |
granite |
gray |
gray_threshold |
green |
height_field |
hexagon |
hf_gray_16 |
hierarchy |
hypercomplex |
hollow |
if |
ifdef |
iff |
ifndef |
image_height |
image_map |
image_pattern |
image_width |
include |
initial_clock |
initial_frame |
inside |
inside_vector |
int |
interior |
interior_texture |
internal |
interpolate |
intersection |
intervals |
inverse |
ior |
irid |
irid_wavelength |
isosurface |
jitter |
jpeg |
julia |
julia_fractal |
lambda |
lathe |
leopard |
light_group |
light_source |
linear_spline |
linear_sweep |
ln |
load_file |
local |
location |
log |
look_at |
looks_like |
low_error_factor |
macro |
magnet |
major_radius |
mandel |
map_type |
marble |
material |
material_map |
matrix |
max |
max_extent |
max_gradient |
max_intersections |
max_iteration |
max_sample |
max_trace |
max_trace_level |
media |
media_attenuation |
media_interaction |
merge |
mesh |
mesh2 |
metallic |
method |
metric |
min |
min_extent |
minimum_reuse |
mod |
mortar |
natural_spline |
nearest_count |
no |
no_bump_scale |
no_image |
no_reflection |
no_shadow |
noise_generator |
normal |
normal_indices |
normal_map |
normal_vectors |
number_of_waves |
object |
octaves |
off |
offset |
omega |
omnimax |
on |
once |
onion |
open |
orient |
orientation |
orthographic |
panoramic |
parallel |
parametric |
pass_through |
pattern |
perspective |
pgm |
phase |
phong |
phong_size |
photons |
pi |
pigment |
pigment_map |
pigment_pattern |
planar |
plane |
png |
point_at |
poly |
poly_wave |
polygon |
pot |
pow |
ppm |
precision |
precompute |
pretrace_end |
pretrace_start |
prism |
prod |
projected_through |
pwr |
quadratic_spline |
quadric |
quartic |
quaternion |
quick_color |
quick_colour |
quilted |
radial |
radians |
radiosity |
radius |
rainbow |
ramp_wave |
rand |
range |
ratio |
read |
reciprocal |
recursion_limit |
red |
reflection |
reflection_exponent |
refraction |
render |
repeat |
rgb |
rgbf |
rgbft |
rgbt |
right |
ripples |
rotate |
roughness |
samples |
save_file |
scale |
scallop_wave |
scattering |
seed |
select |
shadowless |
sin |
sine_wave |
sinh |
size |
sky |
sky_sphere |
slice |
slope |
slope_map |
smooth |
smooth_triangle |
solid |
sor |
spacing |
specular |
sphere |
sphere_sweep |
spherical |
spiral1 |
spiral2 |
spline |
split_union |
spotlight |
spotted |
sqr |
sqrt |
statistics |
str |
strcmp |
strength |
strlen |
strlwr |
strupr |
sturm |
substr |
sum |
superellipsoid |
switch |
sys |
t |
tan |
tanh |
target |
text |
texture |
texture_list |
texture_map |
tga |
thickness |
threshold |
tiff |
tightness |
tile2 |
tiles |
tolerance |
toroidal |
torus |
trace |
transform |
translate |
transmit |
triangle |
triangle_wave |
true |
ttf |
turb_depth |
turbulence |
type |
u |
u_steps |
ultra_wide_angle |
undef |
union |
up |
use_alpha |
use_color |
use_colour |
use_index |
utf8 |
uv_indices |
uv_mapping |
uv_vectors |
v |
v_steps |
val |
variance |
vaxis_rotate |
vcross |
vdot |
version |
vertex_vectors |
vlength |
vnormalize |
vrotate |
vstr |
vturbulence |
warning |
warp |
water_level |
waves |
while |
width |
wood |
wrinkles |
write |
x |
y |
yes |
z { FONT_TAG(yytext, KEYWORD_COLOR); }
[a-zA-Z0-9_#]+ |
<*>.|\n ECHO;
<<EOF>> yyterminate();
%%
/************************************************************************/
/* User code section */
/************************************************************************/
#include <time.h>
/* return current system date & time as char ptr */
char* get_time(void)
{
static char *the_time_str;
time_t the_time;
time(&the_time);
the_time_str = ctime(&the_time);
return(the_time_str);
}
int main(int argc, char **argv)
{
if (!yyin) yyin = stdin;
if (!yyout) yyout = stdout;
if(argc >= 2) {
if( (yyin = fopen (argv[1], "r")) == NULL) {
perror(argv[1]);
return(1);
}
if(argc == 3) {
if( (yyout = fopen (argv[2], "w")) == NULL) {
perror(argv[2]);
return(2);
}
}
}
fprintf(yyout, "<HTML>\n"
"<HEAD>\n"
" <META NAME=\"GENERATOR\" CONTENT=\"%s by %s %s\">\n"
" <TITLE>POV-Ray SDL: %s</TITLE>\n"
"</HEAD>\n"
"<BODY BGCOLOR=\"%s\" TEXT=\"%s\">\n\n"
"<PRE>\n",
argv[0], AUTHOR, __DATE__, get_time(), PAGE_COLOR, TEXT_COLOR );
yylex();
fprintf(yyout, "</PRE>\n"
"<BR>\n"
"</BODY>\n"
"</HTML>\n" );
return(0);
}
/* EOF */
Alex wrote:
>>Playing with DocBook I have readed there are some tools to automatically
>>create parsers for C++ - you only have to define syntax/grammar in XML iirc.
>>Sorry, I don't remember details.
>>
>>ABX
>>
>
> Two words:
>
> flex, bison
>
> Alex
>
Post a reply to this message
|
|