Fix the grammar definitions

Fix the grammar definitions, add (leaked) error handling and closing quotation
mark checking in text literal.