kaitai_struct_compiler icon indicating copy to clipboard operation
kaitai_struct_compiler copied to clipboard

Implement optimal parenthesis for ternary operator + add tests

Open GreyCat opened this issue 1 year ago • 0 comments

Another piece of partially contributing to resolving https://github.com/kaitai-io/kaitai_struct/issues/69 — this one handles ternary operator:

  • Add common doIfExp() implementation (+add extPrec propagation into it) into CommonOps, which does a good job at parenthesizing
    • This provides default implementation which is ok for most languages following popular condition ? ifTrue ? ifFalse rendering originating from C.
    • Remove individual copy-pasted implementations in specific languages where we can rely on common one.
    • Adjust Python rendering to follow the same correct strategy
    • Don't touch special ad hoc implementations (Lua, Go)
  • Add/fix tests proving that it works in many contexts

GreyCat avatar Mar 26 '24 15:03 GreyCat