- Timestamp:
- 11/04/08 20:32:32 (2 months ago)
- Files:
-
- 1 modified
-
src/perl6/STD_syntax_highlight (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/perl6/STD_syntax_highlight
r22878 r22881 12 12 use File::Slurp; 13 13 use Term::ANSIColor; 14 use YAML::Dumper; 14 15 15 16 # And finally our modules … … 40 41 STD_syntax_highlight --ansi-text=- foo.pl 41 42 43 # write yaml output to STDOUT (can be useful to build filters) 44 STD_syntax_highlight --yaml=- foo.pl 42 45 =head1 SUBROUTINES 43 46 … … 47 50 48 51 my ($clean_html,$help) = (0,0); 49 my ($full_html,$simple_html,$snippet_html,$ansi_text ) = (0,0,0,0);52 my ($full_html,$simple_html,$snippet_html,$ansi_text,$yaml) = (0,0,0,0,0); 50 53 my ($file, $parser, $src_text); 51 54 … … 66 69 "snippet-html=s"=>\$snippet_html, 67 70 "ansi-text=s"=>\$ansi_text, 71 "yaml=s"=>\$yaml, 68 72 "help"=>\$help 69 73 ); … … 93 97 write simple-mode ansi color text to filename (- for STDOUT) 94 98 99 --yaml=filename 100 writes a dump of redspans to filename (- for STDOUT) 95 101 HELP 96 102 } 97 103 98 104 #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) { 100 106 $simple_html = '-'; 101 107 } … … 158 164 my $text = highlight_perl6_ansi(); 159 165 write_output $ansi_text, $text; 166 } 167 if($yaml) { 168 my $text = highlight_perl6_yaml(); 169 write_output $yaml, $text; 160 170 } 161 171 } … … 385 395 $str; 386 396 } 397 398 399 =item highlight_perl6_yaml 400 401 Spits out YAML that can be useful for the future 402 =cut 403 sub 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 387 432 388 433 =item redspans_traverse
