Acme-Pythonic
view release on metacpan or search on metacpan
lib/Acme/Pythonic.pm view on Meta::CPAN
return unless @lines;
# If unsure about the ending indentation level, add an extra
# non-indented line to ensure the stack gets emptied.
push @lines, '1; # added by Acme::Pythonic' if $lines[-1] =~ /^(?:\s|\s*#)/;
my ($comment, # comment in the current line, if any
$indent, # indentation of the current logical line
$id_at_sob, # identifier at StartOfBlock, for instance "else", or "eval"
$prev_line_with_code, # previous line with code
$might_be_modifier, # flag: current logical line might be a modifier
$line_with_modifier, # physical line which started the current modifier
$joining, # flag: are we joining lines?
$unbalanced_paren, # flag: we opened a paren that remains to be closed
@stack, # keeps track of indentation stuff
);
@stack = ();
foreach my $line (@lines) {
# We remove any trailing comment so that we can assert stuff
# easily about the end of the code in this line. It is later
# appended back in the continue block below.
$comment = $line =~ s/(\s*$tc)//o ? $1 : '';
next if $line =~ /^\s*$/;
lib/Acme/Pythonic.pm view on Meta::CPAN
$n = 3*$n + 1
else:
$n /= 2
=head1 DETAILS
=head2 Labels
The syntax this module provides introduces an ambiguity: Given
if $flag:
do_this()
else:
do_that()
there's no way to know whether that is meant to be
if ($flag) {
do_this();
} else {
do_that();
}
or rather
if ($flag) {
do_this();
}
else: {
do_that();
}
The former is a regular if/else, whereas the latter consists of an if and a
labeled block, so C<do_that()> is unconditionally executed.
To solve this B<labels in Pythonic code have to be in upper case>.
lib/Acme/Pythonic.pm view on Meta::CPAN
consumed in the compilation phase by then.
=head1 DEBUG
L<Filter::ExtractSource> can be used to inspect the source code
generated by Acme::Pythonic:
perl -c -MFilter::ExtractSource pythonic_script.pl
Acme::Pythonic itself has a C<debug> flag though:
use Acme::Pythonic debug => 1;
In debug mode the module prints to standard output the code it has
generated, and passes just a dummy C<1;> to L<Filter::Simple>.
This happens I<before> L<Filter::Simple> undoes the blanking out of
PODs, strings, and regexps. Those parts are marked with the label
C<BLANKED_OUT> for easy identification.
( run in 1.651 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )