Reserved words as identifies (was Re: Long names are doom ?)

Alex Martelli aleaxit at yahoo.com
Sun May 27 17:39:48 EDT 2001


"Chris Gonnerman" <chris.gonnerman at newcenturycomputers.net> wrote in message
news:mailman.990997121.29290.python-list at python.org...
    ...
> The fact is, it really just requires that reserved words which would
> otherwise
> raise a SyntaxError should be rechecked as identifiers.  The code to do it
> shouldn't be long or slow.  I admit that my cursory study of the parser
code
> left me a bit lost as to how such a change would be made, but I haven't

A logical line containing N reserved words can be "re-lexed" in
2**(N-1) ways (after the obvious one in which each reserved
word is lexed as itself) to consider some subset of the reserved
words as identifiers instead.  I think all variations had better be
tried if we want to parse something like
    from from import import as from
for example (or "from print import class as if", if you prefer:-).
('as' is NOT a reserved word, btw, but that, I hope, won't
break anything in this extension).  And I don't quite see how
considering 2**(N-1) reparses may fail to be slow, but maybe
I'm being pessimistic about typical values for N.

Will stopping at the first re-lexing to yield no syntax error be
sufficient, or would that make things ambiguous?


Alex






More information about the Python-list mailing list