History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-496
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Doug H
Reporter: Arron Washington
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Boo

Allow for compact statements for block-based expressions

Created: 26/Sep/05 10:15 AM   Updated: 28/Feb/06 01:57 PM
Component/s: Compiler
Affects Version/s: 0.6
Fix Version/s: 0.7.6

Time Tracking:
Not Specified

File Attachments: 1. Text File boo496b.patch (6 kb)
2. Text File boo496c.patch (7 kb)
3. Text File boo496d.patch (7 kb)



 Description  « Hide
Some discussion on the list - the tail end of this thread: http://groups.google.com/group/boolang/browse_frm/thread/ac20f7172255287e/99ea344d11fe6bc6#99ea344d11fe6bc6 - brings up something in general that I think a lot of people might like:

while true: print 'var'; print 'hello'

or, as mentioned in the thread,

if false: print 'empty codeblock'

Sometimes its not really necessary to consume that much space if there's only going to be one or two elements within the block. Othertimes its just easier to expand a statement like that into a fully block-based statement with a little hassle.

Note: this is not a proposal to remove the "print 'foo' if bar" syntax; this is just a more general way of allowing compacted block-based statements/expressions/technical jargon.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Doug H - 26/Sep/05 11:13 AM
If this is ever wanted, changing the compound_stmt rule in boo.g to this appears to allow it:

protected
compound_stmt[Block b]
{
StatementCollection statements = b.Statements;
}:
(COLON (EOS)* stmt[statements]) |
(
COLON begin:INDENT

{ b.LexicalInfo = ToLexicalInfo(begin); }

block[statements]
end[b]
)
;

Some simple examples:

if true: print "ok"

if false: print "true"
else: print "false"

try: raise "uh oh"
except e: print "caught it"


Arron Washington - 26/Sep/05 02:14 PM
That seems most excellent!

What does everyone else think?


Doug H - 24/Feb/06 11:41 AM
This patch works like python, except it doesn't allow stuff like:
class C: pass
def doit(): pass
See tests/testcases/compilation/simple_statements.boo

Doug H - 25/Feb/06 08:35 AM
This version allows for pass, like:
if true: pass

Doug H - 25/Feb/06 09:00 AM
boo496d.patch fixes typo with pass handling.
if true: pass; print "ok"
is disallowed