Changeset 22876 for src

Show
Ignore:
Timestamp:
11/04/08 18:48:23 (2 months ago)
Author:
azawawi
Message:

[STD_syntax_highlight] more code cleanups

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD_syntax_highlight

    r22875 r22876  
    296296} 
    297297 
     298 
     299=item highlight_perl6_ansi 
     300 
     301This is same as C<highlight_perl6_full> when --ansi-text is used. 
     302No more javascript tree viewer or anything fancy.  
     303Only nodes that have a color are printed. Not optimal but works ;-) 
     304=cut 
     305sub highlight_perl6_ansi { 
     306    my $str = ""; 
     307    my %colors = (); 
     308 
     309    my $ANSI = "STD_syntax_highlight.ansi"; 
     310    open ANSI_FILE, $ANSI 
     311        or die "Could not open $ANSI: $OS_ERROR\n"; 
     312    my $line; 
     313    while($line = <ANSI_FILE>) { 
     314        if($line =~ /^(\w+)=(.+)$/) { 
     315            $colors{$1} = $2; 
     316        } 
     317    } 
     318    close ANSI_FILE; 
     319 
     320    local *spit_ansi_text = sub { 
     321        my ($i, $buffer, $rule, $tree) = @ARG; 
     322        if($rule) { 
     323            my $color = $colors{$rule}; 
     324            $str .= (color $color) . $buffer. (color 'reset'); 
     325        } else { 
     326            $str .= $buffer; 
     327        } 
     328    }; 
     329 
     330    redspans_traverse(\&spit_ansi_text,%colors);  
     331    
     332    $str; 
     333} 
     334 
    298335=item redspans_traverse 
    299     XXX- document 
     336    Walk the path that no one wanted to travel ;) 
    300337=cut 
    301338sub redspans_traverse($%) { 
     
    344381} 
    345382 
    346 =item highlight_perl6_ansi 
    347  
    348 This is same as C<highlight_perl6_full> when --ansi-text is used. 
    349 No more javascript tree viewer or anything fancy.  
    350 Only nodes that have a color are printed. Not optimal but works ;-) 
    351 =cut 
    352 sub highlight_perl6_ansi { 
    353     my $str = ""; 
    354     my %colors = (); 
    355  
    356     my $ANSI = "STD_syntax_highlight.ansi"; 
    357     open ANSI_FILE, $ANSI 
    358         or die "Could not open $ANSI: $OS_ERROR\n"; 
    359     my $line; 
    360     while($line = <ANSI_FILE>) { 
    361         if($line =~ /^(\w+)=(.+)$/) { 
    362             $colors{$1} = $2; 
    363         } 
    364     } 
    365     close ANSI_FILE; 
    366  
    367     local *spit_ansi_text = sub { 
    368         my ($i, $buffer, $rule, $tree) = @ARG; 
    369         if($rule) { 
    370             my $color = $colors{$rule}; 
    371             $str .= (color $color) . $buffer. (color 'reset'); 
    372         } else { 
    373             $str .= $buffer; 
    374         } 
    375     }; 
    376  
    377     redspans_traverse(\&spit_ansi_text,%colors);  
    378     
    379     $str; 
    380 } 
    381  
    382383################################################################### 
    383384# R E D S P A N S