Changeset 22826 for src

Show
Ignore:
Timestamp:
10/30/08 17:27:32 (2 months ago)
Author:
azawawi
Message:

[STD_syntax_highlight] refactored highlight_match() to be simpler

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD_syntax_highlight

    r22824 r22826  
    55use warnings; 
    66use utf8; 
     7use feature qw(say); 
    78use English; 
    89use Getopt::Long; 
     
    9394my $r = STD->parsefile($file,$what); 
    9495 
     96=item write_html_file 
     97 
     98Writes the html file to filename or to STDOUT 
     99=cut 
     100sub write_html_file { 
     101    my ($html_file, $html) = @_; 
     102    if($html_file eq '-') { 
     103        say $html; 
     104    } else { 
     105        open FILE, ">$html_file" or 
     106            die "Cannot open $html_file for writing: $OS_ERROR\n"; 
     107        say FILE $html; 
     108        close FILE; 
     109    } 
     110} 
     111 
    95112=item highlight_match 
    96113 
     
    107124    if($simple_html) { 
    108125        traverse_match($r,$name,0,$events,$opt); 
    109         my $output = highlight_perl6_simple($::ORIG,$events,$opt); 
    110         if($simple_html eq '-') { 
    111             print $output; 
    112         } else { 
    113             open FILE, ">$simple_html" or 
    114                 die "Cannot open $simple_html for writing: $OS_ERROR\n"; 
    115             print FILE $output; 
    116             close FILE; 
    117         } 
     126        my $html = highlight_perl6_simple($::ORIG,$events,$opt); 
     127        write_html_file $simple_html, $html; 
    118128    } 
    119129    if($full_html) { 
    120130        traverse_match($r,$name,0,$events,$opt); 
    121         my $output = highlight_perl6($::ORIG,$events,$opt); 
    122         if($full_html eq '-') { 
    123             print $output; 
    124         } else { 
    125             open FILE, ">$full_html" or 
    126                 die "Cannot open $full_html for writing: $OS_ERROR\n"; 
    127             print FILE $output; 
    128             close FILE; 
    129         } 
     131        my $html = highlight_perl6($::ORIG,$events,$opt); 
     132        write_html_file $full_html, $html; 
    130133    } 
    131134    if($redspans_html) { 
    132         my $output = highlight_perl6_redspans(); 
    133         if($redspans_html eq '-') { 
    134             print $output; 
    135         } else { 
    136             open FILE, ">$redspans_html" or 
    137                 die "Cannot open $redspans_html for writing: $OS_ERROR\n"; 
    138             print FILE $output; 
    139             close FILE; 
    140         } 
     135        my $html = highlight_perl6_redspans(); 
     136        write_html_file $redspans_html, $html; 
    141137    } 
    142138}