kaitai_struct_compiler
kaitai_struct_compiler copied to clipboard
Implement optimal parenthesis for ternary operator + add tests
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 (+addextPrecpropagation 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 ? ifFalserendering 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)
- This provides default implementation which is ok for most languages following popular
- Add/fix tests proving that it works in many contexts