| 330 | | } |
| | 340 | my $str = ""; |
| | 341 | my %colors = (); |
| | 342 | |
| | 343 | my $CSS = "STD_syntax_highlight.css"; |
| | 344 | open CSS_FILE, $CSS |
| | 345 | or die "Could not open $CSS: $OS_ERROR\n"; |
| | 346 | my $line; |
| | 347 | my $css_class; |
| | 348 | while($line = <CSS_FILE>) { |
| | 349 | if($line =~ /^\s*\.(\w+)/) { |
| | 350 | $css_class = $1; |
| | 351 | } elsif($line =~ /^#\w+/) { |
| | 352 | # ignore #elem colors |
| | 353 | $css_class = 0; |
| | 354 | } elsif($line =~ /color\s*:\s*(\w+)/) { |
| | 355 | $colors{$css_class} = $1 if $css_class; |
| | 356 | } |
| | 357 | } |
| | 358 | close CSS_FILE; |
| | 359 | |
| | 360 | # slurp libraries and javascript to inline them |
| | 361 | my $css = qq{<link href="../$CSS" rel="stylesheet" type="text/css">}; |
| | 362 | if(!$clean_html) { |
| | 363 | $css = read_file($CSS) |
| | 364 | or die "Error while slurping file: $OS_ERROR\n"; |
| | 365 | $css = qq{<style type="text/css">\n$css\n</style>}; |
| | 366 | } |
| | 367 | |
| | 368 | my $timestamp = localtime; |
| | 369 | $str .= <<"HTML"; |
| | 370 | <html> |
| | 371 | <head> |
| | 372 | <title>$file</title> |
| | 373 | <!-- |
| | 374 | Generated by $PROGRAM_NAME at $timestamp |
| | 375 | --> |
| | 376 | $css |
| | 377 | </head> |
| | 378 | <body> |
| | 379 | <pre> |
| | 380 | HTML |
| | 381 | |
| | 382 | my ($last_tree,$buffer) = ("",""); |
| | 383 | for my $i (0 .. @loc-1) { |
| | 384 | say("Undefined $i"),next unless defined $loc[$i]; |
| | 385 | my $c = substr($txt,$i,1); |
| | 386 | my $tree = "@{$loc[$i]}"; |
| | 387 | if($tree ne $last_tree) { |
| | 388 | $str .= "\n'$buffer'\n$last_tree\n" if $buffer ne ''; |
| | 389 | $buffer = $c; |
| | 390 | } else { |
| | 391 | $buffer .= $c; |
| | 392 | } |
| | 393 | $last_tree = $tree; |
| | 394 | } |
| | 395 | |
| | 396 | $str .= <<"HTML"; |
| | 397 | </pre> |
| | 398 | </body> |
| | 399 | </html> |
| | 400 | HTML |
| | 401 | |
| | 402 | $str; |
| | 403 | } |
| | 404 | |
| | 405 | ################################################################### |
| | 406 | # R E D S P A N S |
| | 407 | my @locs; |
| | 408 | { |
| | 409 | package Actions; |
| | 410 | |
| | 411 | our $AUTOLOAD; |
| | 412 | |
| | 413 | sub AUTOLOAD { |
| | 414 | my $self = shift; |
| | 415 | my $C = shift; |
| | 416 | my $F = $C->{_from}; |
| | 417 | my $P = $C->{_pos}; |
| | 418 | $AUTOLOAD =~ s/^Actions:://; |
| | 419 | $loc[$P] = [] if $loc[$P]; # in case we backtracked to here |
| | 420 | for ($F..$P-1) { |
| | 421 | unshift @{$loc[$_]}, $AUTOLOAD; |
| | 422 | } |
| | 423 | } |
| | 424 | |
| | 425 | sub stdstopper { } |
| | 426 | sub terminator { } |
| | 427 | sub unitstopper { } |
| | 428 | sub comp_unit { } |
| | 429 | } |
| | 430 | |