For if there is if-feature statement. I think it will not cover complex scenarios.
For nested constructs - if you know the depth (and the depth is limited) , then you can repeat list definition N times (perhaps with help of grouping - put non key elements into grouping so you do not need to repeat them) . In many cases it is acceptable.
If possible, one option is to generate YANG during build time by some script (e.g. using yangbuilder).