Changed brace matching algorythm to avoid matching one extra closing
parenthesis
Fixes #1040
Merge pull request #1099 from perrito666/master

Fixes #1040