On Thu, Apr 2, 2009 at 12:35 PM, Bruce Frederiksen <dangyogi@gmail.com> wrote:
Another strange one: 'close with X'.
This hinges on the 'close' method returning X and also that this could be done syntactically *without* making 'close' a reserved word by relying on 'with' already being a reserved word with very limited usage in the grammar:
generator_return_stmt: NAME 'with' testlist
And then verify later that NAME is 'close' (or raise SyntaxError).
I'm not that familiar with Python's parser to know if it could handle this or not (LL vs. LR)...
The current parser generator cannot deal with this -- when it sees a NAME at the start of the line it has to decide which non-terminal to pick to parse the rest of the line. Besides (before you put effort into trying to fix this or prove me wrong) this syntax looks too weird -- we don't normally refer to leaving a stack frame as "closing" anything. Close is a verb we apply to other things, e.g. files -- or generators. But not the current frame or generator. -- --Guido van Rossum (home page: http://www.python.org/~guido/)