Rewrite the Scanner

The scanner was causing problems, including infinite loops. This is a rewrite that hopefully does away with the weaknesses.

Unclosed references and comments are now treated as syntax errors, and Curly::SyntaxError will be raised.