textlib contains a lot of parsing functionality, built using regex. This usually works well, however it becomes complicated / error prone especially with nested templates.
However, as mwparserfromhell tokenizer doesn't expose start & end of each token, the textlib algorithms will need to be heavily revised, or mwparserfromhell needs improvements.