Changeset 22835 for src

Show
Ignore:
Timestamp:
10/31/08 07:46:11 (2 months ago)
Author:
azawawi
Message:

[STD_syntax_highlight] dropped --simple DumpMatch? in favor of the agile --redspans

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD_syntax_highlight

    r22834 r22835  
    3131    STD_syntax_highlight foo.pl statementlist 
    3232 
    33     # write only simple html/css to simple.html 
    34     STD_syntax_highlight --simple-html=foo.simple.html foo.pl 
    35  
    3633    # write redspans output to foo.redspans.html 
    3734    STD_syntax_highlight --redspans-html=foo.redspans.html foo.pl 
    38  
    3935=head1 SUBROUTINES 
    4036 
     
    4440 
    4541my ($clean_html,$help) = (0,0); 
    46 my ($simple_html,$full_html,$redspans_html) = (0,0,'-'); 
     42my ($full_html,$redspans_html) = (0,0,'-'); 
    4743my ($file, $parser, $src_text);  
    4844 
     
    6056    GetOptions( 
    6157        "clean-html"=>\$clean_html, 
    62         "simple-html=s"=>\$simple_html, 
    6358        "full-html=s"=>\$full_html, 
    6459        "redspans-html=s"=>\$redspans_html, 
     
    7671        generates separate html,css and javascript 
    7772 
    78     --simple-html=filename 
    79         write simple-mode html to filename (disabled by default, - for STDOUT)   
    80  
    8173    --full-html=filename    
    8274        write full-mode html to filename (disabled by default, - for STDOUT) 
    83   
     75     
    8476    --redspans-html=filename    
    8577        write redspans-mode html to filename (enabled by default, - for STDOUT) 
     
    134126    my $events = []; 
    135127 
    136     if($simple_html) { 
    137         traverse_match($r,$name,0,$events,$opt); 
    138         my $html = highlight_perl6_simple($r,$::ORIG,$events,$opt); 
    139         write_html_file $simple_html, $html; 
    140     } 
    141128    if($full_html) { 
    142129        traverse_match($r,$name,0,$events,$opt); 
     
    237224} 
    238225 
    239 =item highlight_perl6_simple 
    240  
    241 This is same as C<highlight_perl> when --simple is used. 
    242 No more javascript tree viewer or anything fancy.  
    243 Only nodes that have a color are printed. Not optimal but works ;-) 
    244 =cut 
    245 sub highlight_perl6_simple { 
    246     my ($orig,$events,$opt) = @ARG; 
    247     my $str = ""; 
    248     my $at = 0; 
    249     my %colors = (); 
    250  
    251     my $CSS = "STD_syntax_highlight.css"; 
    252     open CSS_FILE, $CSS 
    253         or die "Could not open $CSS: $OS_ERROR\n"; 
    254     my $line; 
    255     while($line = <CSS_FILE>) { 
    256         if($line =~ /^\s*\.(\w+)\s*{\s*color\s*:\s*(\w+)/) { 
    257             $colors{$1} = $2; 
    258         } 
    259     } 
    260     close CSS_FILE; 
    261  
    262     # slurp libraries and javascript to inline them 
    263     my $css = qq{<link href="../$CSS" rel="stylesheet" type="text/css">}; 
    264     if(!$clean_html) { 
    265         $css = read_file($CSS) 
    266             or die "Error while slurping file: $OS_ERROR\n"; 
    267         $css = qq{<style type="text/css">\n$css\n</style>}; 
    268     } 
    269  
    270     my $timestamp = localtime; 
    271     $str .= <<"HTML"; 
    272 <html> 
    273 <head> 
    274     <title>$file</title> 
    275 <!-- 
    276      Generated by $PROGRAM_NAME at $timestamp 
    277 --> 
    278     $css 
    279 </head> 
    280 <body> 
    281     <pre> 
    282 HTML 
    283     my $curr_rule = q{}; 
    284     my @rules = ();  
    285     my $code = ""; 
    286     for (sort {$a->[0] <=> $b->[0] or $a->[4] <=> $b->[4]} @{$events}) { 
    287         my $text = substr($orig,$at,$_->[0]-$at); 
    288         my $esc_text .= escape_html($text); 
    289         $at = $_->[0]; 
    290  
    291         # process types, routines and identifiers 
    292         if($curr_rule eq 'identifier') { 
    293             if($parser->is_type($text)) { 
    294                 $code .= qq{<span class="_type">$esc_text</span>}; 
    295             } elsif($parser->is_routine($text)) { 
    296                 $code .= qq{<span class="_routine">$esc_text</span>}; 
    297             } else { 
    298                 $code .= $esc_text; 
    299             } 
    300         } else { 
    301             $code .= $esc_text; 
    302         } 
    303  
    304         if ($_->[1] eq 'from') { 
    305             $curr_rule = $_->[2]; 
    306             push @rules, $curr_rule; 
    307             my $has_color = $colors{$curr_rule}; 
    308             $code .= '<span class="'.$curr_rule.'">' if $has_color; 
    309         } elsif ($_->[1] eq 'to') { 
    310             my $rule = pop @rules; 
    311             my $has_color = $colors{$rule}; 
    312             $code .=  '</span>' if $has_color; 
    313         } 
    314     } 
    315     # process comments 
    316     $code =~ s{(#[^\n]*)}{<span class="_comment">$1</span>}g; 
    317     $str .= $code; 
    318     $str .= <<"HTML"; 
    319     </pre> 
    320 </body> 
    321 </html> 
    322 HTML 
    323  
    324    $str; 
    325 } 
    326  
    327226=item highlight_perl6_redspans 
    328227 
    329 This is same as C<highlight_perl> when --redspans is used. 
     228This is same as C<highlight_perl6_full> when --redspans is used. 
    330229No more javascript tree viewer or anything fancy.  
    331230Only nodes that have a color are printed. Not optimal but works ;-)