|
1 | 1 | #!/usr/bin/perl |
2 | | -## pythonizer Version 0.55 (Sept 2, 2020) |
3 | | -## Fuzzy prettyprint STDERR for Perl scripts |
4 | | -## Copyright Nikolai Bezroukov, 2019-2020. |
| 2 | +## pythonizer -- Translator of the subset of Perl 5 to Python 3.x |
| 3 | +## Copyright Nikolai Bezroukov, 2019-2021. |
5 | 4 | ## Licensed under Perl Artistic license |
6 | 5 | ## |
7 | 6 | ## As most Perl statement are simple over 80% of them usually allow sucessful translation. That's why we use the term "fuzzy" translation. |
|
85 | 84 | # 0.850 2020/10/12 BEZROUN print translation improved; many fixes in lex analyser |
86 | 85 | # 0.860 2020/10/14 BEZROUN Python 2.7 mode eliminated to simplify the code. Option -p removed. "since" test passed |
87 | 86 | # 0.870 2020/10/21 BEZROUN Treatment of brackets systematised. The code of subroutine expression revised. |
| 87 | +# 0.871 2021/05/10 BEZROUN Minor corrections in the header. |
88 | 88 | #!start =============================================================================================================================== |
89 | 89 |
|
90 | 90 | use v5.10.1; |
|
103 | 103 |
|
104 | 104 | use Pythonizer qw(correct_nest getline prolog output_line @LocalSub %GlobalVar); |
105 | 105 |
|
106 | | - $VERSION='0.85'; |
| 106 | + $VERSION='0.871'; |
107 | 107 | $SCRIPT_NAME='pythonizer'; |
108 | 108 | # |
109 | 109 | # options |
|
159 | 159 | # |
160 | 160 | @Perlscan::BufferValClass=@Perlscan::BufferValCom=@Perlscan::BufferValPerl=@Perlscan::BufferValPy=(); # cleaning after the first pass |
161 | 161 | my ($start,$token_buffer_active); |
162 | | - $CurSub='main'; # default value of the current subroutine |
| 162 | + $CurSub='main'; |
163 | 163 | $token_buffer_active=0; |
164 | 164 | $we_are_in_sub_body=0; |
165 | 165 | while( defined($line) || scalar(@Perlscan::BufferValClass)>0 ){ |
@@ -450,6 +450,7 @@ my ($start,$token_buffer_active); |
450 | 450 | $rc=open_fun(0,'s'); |
451 | 451 | }else{ |
452 | 452 | $TrStatus=function(0); |
| 453 | + |
453 | 454 | } |
454 | 455 | }elsif( $ValClass[0] eq 'x' ){ |
455 | 456 | # this is backquotes |
@@ -1302,12 +1303,7 @@ my ($k, $split, $split2, $delta, $dict, $incr, $arg1, $arg2, $perl_name, $py_nam |
1302 | 1303 | }elsif($perl_name eq 'shift' ){ |
1303 | 1304 | # assent only a single arg -- array; if no argument then it uses @_ array |
1304 | 1305 | if( $bracketed==-1 ){ |
1305 | | - if( $CurSub eq 'main' || $Pythonizer::CurNest==0 ){ |
1306 | | - $arg1='sys.argv'; |
1307 | | - }else{ |
1308 | | - $arg1='perl_arg_array'; |
1309 | | - } |
1310 | | - gen_chunk("$arg1$py_name"); |
| 1306 | + gen_chunk("perl_arg_array$py_name"); |
1311 | 1307 | }elsif( $end_pos==$start ){ |
1312 | 1308 | gen_chunk($ValPy[$start],$py_name); |
1313 | 1309 | }else{ |
@@ -1376,7 +1372,7 @@ my ($k, $split, $split2, $delta, $dict, $incr, $arg1, $arg2, $perl_name, $py_nam |
1376 | 1372 | # single argument |
1377 | 1373 | gen_chunk('('.$ValPy[$start].')') |
1378 | 1374 | }elsif( $bracketed==1 ){ |
1379 | | - $TrStatus=expression($start,$end_pos,1); |
| 1375 | + $TrStatus=expression($start,$end_pos,0); |
1380 | 1376 | return -255 if ($TrStatus<0); |
1381 | 1377 | }else{ |
1382 | 1378 | gen_chunk('('); |
|
0 commit comments