Changeset 23020 for src

Show
Ignore:
Timestamp:
11/15/08 09:28:25 (8 weeks ago)
Author:
azawawi
Message:

[STD_syntax_highlight] Read from stdin when no filename is given or is '-'
[STD_syntax_highlight] Default output mode is ansi-escaped sequences (--ansi-text)
[STD_syntax_highlight] Replaced $parser->parseFile($file) with parse($file_text)
[STD_syntax_highlight] # slurp file once instead of twice
[STD_syntax_highlight] Updated pod comments along with usage

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/STD_syntax_highlight

    r22881 r23020  
    2323=head1 SYNOPSIS 
    2424 
    25     # print html output with inlined resources for 'comp_unit' 
     25    # read from standard input 
     26    STD_syntax_highlight 
     27 
     28    # print ansi-escaped text for 'comp_unit' 
    2629    STD_syntax_highlight foo.pl 
    2730 
    2831    # print separate html, css and javascript files 
    29     STD_syntax_highlight --clean-html foo.pl 
    30  
    31     # print html for with 'statementlist' as the top-level rule 
     32    STD_syntax_highlight --full-html=foo.full.html --clean-html foo.pl 
     33 
     34    # print ansi-escaped text for with 'statementlist' as the top-level rule 
    3235    STD_syntax_highlight foo.pl statementlist 
    3336 
     
    7376    ); 
    7477 
    75     if ($#ARGV < 0 || $help) { 
     78    if ($help) { 
    7679        die <<"HELP"; 
    7780USAGE:  
    78     $PROGRAM_NAME [options] filename [rule] 
    79  
    80     where options can be one of the following: 
     81    $PROGRAM_NAME [options] [file] [rule] 
     82 
     83    where 'file' is optional; if omitted or is '-' then  
     84    STDIN will be used. And 'options' can be one of the following: 
    8185 
    8286    --clean-html     
     
    8791 
    8892    --simple-html=filename    
    89         write simple-mode html to filename (defaults to STDOUT if no other  
    90         option is selected, - for STDOUT) 
     93        write simple-mode html to filename (- for STDOUT) 
    9194 
    9295    --snippet-html=filename 
    93         same as --simple-html but with only the body section.  
    94         This is typically ideal for inline html code. 
     96        This is typically ideal for inline html code. (- for STDOUT) 
    9597 
    9698    --ansi-text=filename    
     
    103105 
    104106    #default is --simple-html=- if no option is selected 
    105     if(!($ansi_text || $full_html || $snippet_html || $yaml) && !$simple_html) { 
    106         $simple_html = '-';     
     107    if(!($simple_html || $full_html || $snippet_html || $yaml) && !$ansi_text) { 
     108        $ansi_text = '-';     
    107109    } 
    108110 
     
    111113    my $what = shift @ARGV // 'comp_unit'; 
    112114 
    113     unless(-r $file) { 
    114         die "Could not open '$file' for reading\n"; 
    115     } 
    116  
    117     # slurp the file for redspans 
     115    #what is the meaning of your input file? 
     116    if(!$file || $file eq '-') { 
     117        # i think you mean standard input 
     118        $file = \*STDIN;         
     119    } else { 
     120        # no it is should be a file, let me check 
     121        unless(-r $file) { 
     122            die "Could not open '$file' for reading\n"; 
     123        } 
     124    } 
     125 
     126    # slurp the file for parsing and redspans 
    118127    $src_text = Encode::decode('utf8', read_file($file) ); 
    119  
    120128    $loc[length($src_text) - 1] = []; 
    121  
    122     $parser = STD->parsefile($file,$what); 
     129    $parser = STD->parse($src_text,$what); 
    123130 
    124131    # and finally print out the html code