pythonizer icon indicating copy to clipboard operation
pythonizer copied to clipboard

unless expression loses the required parenthesis for proper code generation

Open snoopyjc opened this issue 3 years ago • 2 comments

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 avatar Nov 08 '21 05:11 snoopyjc

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 avatar Nov 08 '21 17:11 snoopyjc

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

snoopyjc avatar Feb 07 '22 16:02 snoopyjc