[Python-ideas] An Alternate Suite Delineation Syntax For Python? (was Re: [Python-Dev] [PATCH] Adding braces to __future__)
Masklinn
masklinn at masklinn.net
Sun Dec 11 09:44:17 CET 2011
On 2011-12-11, at 01:16 , Mike Meyer wrote:
> A minor improvement in just that one method, but it will show up in
> every generate method of every class, making it significant in total.
If users are not supposed to read the generated code, why not generate
pyc files directly? That would avoid the issue would it not?
And if users are supposed to edit (therefore read) the generated code,
wouldn't you want to make the file actually readable, therefore use
indentation-based blocks?
> I think not. As someone else observed, Haskell has both options
> available - and the rules for the indented version are a lot less
> straightforward than they are in Python (at least I haven't seen as
> clean a statement of them).
The short version is:
http://www.haskell.org/onlinereport/lexemes.html#lexemes-layout
* when a brace is omitted after a `where`, `let`, `of` or `do` keyword,
a brace is inserted and the indentation of the next lexeme is
remembered
* if the next lexeme is indented below the keyword, immediately insert
a closing brace (before the lexeme itself)
* otherwise, for each subsequent line
- if it contains only whitespace or is indented further than the
current level, continue the current expression
- if it is indented at the current level, insert a semicolon
- if it is indented below the current level, insert a closing brace
You can find the complete and more formal definition at
http://www.haskell.org/onlinereport/syntax-iso.html#layout
More information about the Python-ideas
mailing list