[Python-Dev] Better SyntaxError messages

Ka-Ping Yee ping@lfw.org
Sat, 8 Jul 2000 02:35:05 -0700 (PDT)


On Fri, 7 Jul 2000, Vladimir Marangozov wrote:
> Okay. Since you've already altered the error list in errcode.h,
> I think that the best thing to do is to re-introduce E_INDENT
> but for the "missing indentation" case (reported to the user as
> "expected an indented block"), then return E_INDENT from AddToken()
> and revert back its signature. Thus all additional error cases you've
> detected so far would be handled fine in pythonrun.c.

I think i'd rather leave the patch as it is.  I can see that what
you're suggesting would eliminate the need for the expected_ret
argument to PyParser_AddToken(), but i think there's more value
in exposing the expected token to pythonrun -- it leaves open the
possibility for further more detailed and helpful messages in the
future, without having to create separate error codes for each.

It seems right that these situations should fall under the E_SYNTAX
error code (otherwise we'd have to say that E_SYNTAX means "syntax
error except for missing-indentation errors" etc.).  E_SYNTAX is
the general error code for "we got a token but the parser wouldn't
accept it".  (E_TABSPACE, E_TOODEEP, and E_DEDENT are errors at
the token level.)

And i don't see a lot of motivation to *avoid* passing back the
expected token.  There isn't anyone else depending on the interface
to PyParser_AddToken (parser.h is a private header file).

Hmm.  Is that sufficiently convincing?


-- ?!ng

"To be human is to continually change.  Your desire to remain as you are
is what ultimately limits you."
    -- The Puppet Master, Ghost in the Shell