The time I wrote that code I thought there is a case that is ambiguous but now I can't see such a case any more. Inserting opening braces until all closing braces are matched is indeed a good idea. I will try to implement it, then it should turn out if there is a case that is ambiguous...