Port findMatchingParen from Python implementation