Changeset 22881 for src

Show
Ignore:
Timestamp:
11/04/08 20:32:32 (2 months ago)
Author:
azawawi
Message:

[STD_syntax_highlight] implemented --yaml, [particle]++

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD_syntax_highlight

    r22878 r22881  
    1212use File::Slurp; 
    1313use Term::ANSIColor; 
     14use YAML::Dumper; 
    1415 
    1516# And finally our modules 
     
    4041    STD_syntax_highlight --ansi-text=- foo.pl 
    4142 
     43    # write yaml output to STDOUT (can be useful to build filters) 
     44    STD_syntax_highlight --yaml=- foo.pl 
    4245=head1 SUBROUTINES 
    4346 
     
    4750 
    4851my ($clean_html,$help) = (0,0); 
    49 my ($full_html,$simple_html,$snippet_html,$ansi_text) = (0,0,0,0); 
     52my ($full_html,$simple_html,$snippet_html,$ansi_text,$yaml) = (0,0,0,0,0); 
    5053my ($file, $parser, $src_text);  
    5154 
     
    6669        "snippet-html=s"=>\$snippet_html, 
    6770        "ansi-text=s"=>\$ansi_text, 
     71        "yaml=s"=>\$yaml, 
    6872        "help"=>\$help 
    6973    ); 
     
    9397        write simple-mode ansi color text to filename (- for STDOUT) 
    9498 
     99    --yaml=filename 
     100        writes a dump of redspans to filename (- for STDOUT) 
    95101HELP 
    96102    } 
    97103 
    98104    #default is --simple-html=- if no option is selected 
    99     if(!($ansi_text || $full_html || $snippet_html) && !$simple_html) { 
     105    if(!($ansi_text || $full_html || $snippet_html || $yaml) && !$simple_html) { 
    100106        $simple_html = '-';     
    101107    } 
     
    158164        my $text = highlight_perl6_ansi(); 
    159165        write_output $ansi_text, $text; 
     166    } 
     167    if($yaml) { 
     168        my $text = highlight_perl6_yaml(); 
     169        write_output $yaml, $text; 
    160170    } 
    161171} 
     
    385395    $str; 
    386396} 
     397 
     398 
     399=item highlight_perl6_yaml 
     400 
     401Spits out YAML that can be useful for the future 
     402=cut 
     403sub highlight_perl6_yaml { 
     404    my $str = ""; 
     405    my %colors = (); 
     406 
     407    my $ANSI = "STD_syntax_highlight.ansi"; 
     408    open ANSI_FILE, $ANSI 
     409        or die "Could not open $ANSI: $OS_ERROR\n"; 
     410    my $line; 
     411    while($line = <ANSI_FILE>) { 
     412        if($line =~ /^(\w+)=(.+)$/) { 
     413            $colors{$1} = $2; 
     414        } 
     415    } 
     416    close ANSI_FILE; 
     417 
     418    my @yaml = (); 
     419    local *spit_yaml = sub { 
     420        push @yaml, @ARG; 
     421    }; 
     422 
     423    redspans_traverse(\&spit_yaml,%colors);  
     424 
     425    my $dumper = YAML::Dumper->new; 
     426    $dumper->indent_width(4); 
     427    $str .= $dumper->dump(@yaml); 
     428 
     429    $str; 
     430} 
     431 
    387432 
    388433=item redspans_traverse