App-sh2p
view release on metacpan or search on metacpan
lib/App/sh2p/Parser.pm view on Meta::CPAN
App::sh2p::Handlers::Handle_open_redirection ($rtok->[$i],
$redirection_file);
# Remove tokens processed
splice (@$rtok, $i, 2);
splice (@$rtype, $i, 2);
return 2;
}
}
}
########################################################
sub join_parse_tokens {
my ($sep, @args) = @_;
my $ntok = 0;
# C style for loop because I need to check the position
for (my $i = 0; $i < @args; $i++) {
my @tokens = ($args[$i]);
my @types = identify (2, @tokens);
#print_types_tokens(\@types, \@tokens);
convert (@tokens, @types);
$ntok++;
# Look ahead to see if we are at end
if ($i < $#args) {
last if substr($args[$i+1],0,1) eq '#';
last if is_break($args[$i+1]);
last if $args[$i+1] eq ';'; # January 2009
out $sep;
}
}
return $ntok;
}
###########################################################
sub analyse_pipeline {
my @args = @_;
my $ntok = @args;
my $end_value = '';
error_out ();
error_out "Pipeline '@args' detected";
#my @caller = caller();
#print STDERR "analyse_pipeline: <@args><@caller>\n";
# Get commands, sometimes the | is separate, sometimes not
@args = split /\|/, "@args";
App::sh2p::Handlers::no_semi_colon();
# Let's make a guess. echo or print at the front usually means
# that the command which follows wants a string
if ($args[0] =~ s/^(echo |print )//) {
$end_value = shift @args;
}
for (my $i = 0; $i < @args; $i++) {
$args[$i] =~ s/^\s+//; # Strip leading whitespace
$args[$i] =~ s/\s+$//; # Strip trailing whitespace
if (! $args[$i] ) {
# Blank line - remove it
splice (@args, $i, 1);
$i--; # to counteract the ++
next;
}
my @tokens = tokenise ($args[$i]);
my @types = identify (0, @tokens);
# We are delimited by |, so get the arguments as well
# external call is not the last in the pipe, change to back-ticks
if ( $types[0][0] eq 'EXTERNAL' && $i < $#args) {
@types = (['DELIMITER',\&App::sh2p::Handlers::Handle_2char_qx]);
@tokens = ("\$(@tokens)");
if ($args[$i+1] =~ /^\s*grep/) {
# Switch next command around with this
$i++;
$args[$i] =~ s/^\s+//;
$args[$i] =~ s/\s+$//;
my @next_tokens = tokenise ($args[$i]);
my @next_types = identify (0, @next_tokens);
convert (@next_tokens, @next_types);
}
}
#print_types_tokens (\@types, \@tokens);
convert (@tokens, @types);
out '|' if $i < $#args;
}
out "$end_value";
out "\n" if !App::sh2p::Compound::get_context();
App::sh2p::Handlers::reset_semi_colon();
error_out ();
return $ntok;
}
###########################################################
1;
( run in 2.201 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )