| 18 | | # These are needed for redspan |
| | 18 | =head1 NAME |
| | 19 | |
| | 20 | STD_syntax_highlight - Highlights Perl 6 source code using STD.pm |
| | 21 | |
| | 22 | =head1 SYNOPSIS |
| | 23 | |
| | 24 | # print html output with inlined resources for 'comp_unit' |
| | 25 | STD_syntax_highlight foo.pl |
| | 26 | |
| | 27 | # print separate html, css and javascript files |
| | 28 | STD_syntax_highlight --clean-html foo.pl |
| | 29 | |
| | 30 | # print html for with 'statementlist' as the top-level rule |
| | 31 | STD_syntax_highlight foo.pl statementlist |
| | 32 | |
| | 33 | # write only simple html/css to simple.html |
| | 34 | STD_syntax_highlight --simple-html=foo.simple.html foo.pl |
| | 35 | |
| | 36 | # write redspans output to foo.redspans.html |
| | 37 | STD_syntax_highlight --redspans-html=foo.redspans.html foo.pl |
| | 38 | |
| | 39 | =head1 SUBROUTINES |
| | 40 | |
| | 41 | =over |
| | 42 | |
| | 43 | =cut |
| | 44 | |
| | 45 | my ($clean_html,$help) = (0,0); |
| | 46 | my ($simple_html,$full_html,$redspans_html) = (0,0,'-'); |
| | 47 | my ($file, $parser, $src_text); |
| | 48 | |
| | 49 | # These are needed for redspans |
| 22 | | =head1 NAME |
| 23 | | |
| 24 | | STD_syntax_highlight - Highlights Perl 6 source code using STD.pm |
| 25 | | |
| 26 | | =head1 SYNOPSIS |
| 27 | | |
| 28 | | # print html output with inlined resources for 'comp_unit' |
| 29 | | STD_syntax_highlight foo.pl |
| 30 | | |
| 31 | | # print separate html, css and javascript files |
| 32 | | STD_syntax_highlight --clean-html foo.pl |
| 33 | | |
| 34 | | # print html for with 'statementlist' as the top-level rule |
| 35 | | STD_syntax_highlight foo.pl statementlist |
| 36 | | |
| 37 | | # write only simple html/css to simple.html |
| 38 | | STD_syntax_highlight --simple-html=foo.simple.html foo.pl |
| 39 | | |
| 40 | | # write redspans output to foo.redspans.html |
| 41 | | STD_syntax_highlight --redspans-html=foo.redspans.html foo.pl |
| 42 | | |
| 43 | | =head1 SUBROUTINES |
| 44 | | |
| 45 | | =over |
| 46 | | |
| 47 | | =cut |
| 48 | | |
| 49 | | #process the command line |
| 50 | | my ($clean_html,$help) = (0,0); |
| 51 | | my ($simple_html,$full_html,$redspans_html) = (0,0,'-'); |
| 52 | | GetOptions( |
| 53 | | "clean-html"=>\$clean_html, |
| 54 | | "simple-html=s"=>\$simple_html, |
| 55 | | "full-html=s"=>\$full_html, |
| 56 | | "redspans-html=s"=>\$redspans_html, |
| 57 | | "help"=>\$help |
| 58 | | ); |
| 59 | | |
| 60 | | if ($#ARGV < 0 || $help) { |
| 61 | | die <<"HELP"; |
| | 53 | =item main |
| | 54 | |
| | 55 | Your standard main method |
| | 56 | =cut |
| | 57 | sub main { |
| | 58 | |
| | 59 | #process the command line |
| | 60 | GetOptions( |
| | 61 | "clean-html"=>\$clean_html, |
| | 62 | "simple-html=s"=>\$simple_html, |
| | 63 | "full-html=s"=>\$full_html, |
| | 64 | "redspans-html=s"=>\$redspans_html, |
| | 65 | "help"=>\$help |
| | 66 | ); |
| | 67 | |
| | 68 | if ($#ARGV < 0 || $help) { |
| | 69 | die <<"HELP"; |
| 80 | | } |
| 81 | | |
| 82 | | #start parsing... |
| 83 | | my $file = shift; |
| 84 | | my $what = shift // 'comp_unit'; |
| 85 | | |
| 86 | | unless(-r $file) { |
| 87 | | die "Could not open '$file' for reading\n"; |
| 88 | | } |
| 89 | | |
| 90 | | # slurp the file for redspans |
| 91 | | my $txt = read_file($file); |
| 92 | | $loc[length($txt) - 1] = []; |
| 93 | | |
| 94 | | my $r = STD->parsefile($file,$what); |
| | 88 | } |
| | 89 | |
| | 90 | #start parsing... |
| | 91 | $file = shift @ARGV; |
| | 92 | my $what = shift @ARGV // 'comp_unit'; |
| | 93 | |
| | 94 | unless(-r $file) { |
| | 95 | die "Could not open '$file' for reading\n"; |
| | 96 | } |
| | 97 | |
| | 98 | # slurp the file for redspans |
| | 99 | $src_text = read_file($file); |
| | 100 | $loc[length($src_text) - 1] = []; |
| | 101 | |
| | 102 | $parser = STD->parsefile($file,$what); |
| | 103 | |
| | 104 | # and finally print out the html code |
| | 105 | highlight_match($what=>$parser,{}); |
| | 106 | } |