(bug 27936) Improve parser handling of nested braces.

Parser tests also included, test case and original patch supplied by
Bergi on bugzilla. Tested against the current version.

Change-Id: Id7ec4e694783dd0f682f65f39d8b9e59f82e58aa