softpano / pythonizer

Translator (or more correctly transcriber) from Perl to Python
http://www.softpanorama.org/Scripting/Pythonorama/Python_for_perl_programmers/Pythonizer/index.shtml
Other
39 stars 17 forks source link

unless expression loses the required parenthesis for proper code generation #20

Open snoopyjc opened 2 years ago

snoopyjc commented 2 years ago

The perl "unless" construct generated an "if not" in python, but it fails to keep the parenthesis so it's probably wrong code:

        unless (($area_hidden) || ($area_rtr_hidden) ||
                ($intf_hidden) || ($link_hidden)) {

generates:

if not (area_hidden) or (area_rtr_hidden) or (link_hidden):

but the "not" only applies to the first part of the expression - it needs to be applied to the whole thing.

snoopyjc commented 2 years ago

Fix in sub control of pythonizer:

  gen_chunk($ValPy[$begin]); # gen initial keyword
  if( $ValPerl[$begin] eq 'unless' ) { gen_chunk('('); }    # issue 20
  $k=expression($start,$limit,0); # last bracket was erased.
  return -255 if ($k<0);
  if( $ValPerl[$begin] eq 'unless' ) { gen_chunk(')'); }    # issue 20
  gen_chunk(':');
snoopyjc commented 2 years ago

Fixed in https://github.com/snoopyjc/pythonizer