evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.09k stars 39 forks source link

Simplify the layout rule. #125

Closed evincarofautumn closed 10 years ago

evincarofautumn commented 10 years ago

Previously, this:

foo : bar : baz
            quux
      blerg

Would desugar to this:

foo { bar { baz
            quux
      blerg } }

Because blerg is indented more than the line containing the most recent colon, following bar. The desugaring that the programmer almost certainly intended is this:

foo { bar { baz
            quux }
      blerg }

This caused problems with line-wrapped conditionals:

if (this
    || that
    || anotherThing):
  take
  some
  actions

Here, take some actions would be interpreted as falling outside the block, because they are indented less than the layout line, which begins with || and not if.

The new, simplified layout rule is that all tokens in a layout block must be indented at least as far as the first token in the block. That leads naturally to a few legal styles:

// Colons at the end of the line with consistent spacing.
if (quux):
  foo
  if (bar):
    baz
    frob
  blerg

// Colons before a block with consistent spacing.
if (quux)
: foo
  if (bar)
  : baz
    frob
  blerg

// Colons before an aligned block with inconsistent spacing.
if (quux): foo
           if (bar): baz
                     frob
           blerg
evincarofautumn commented 10 years ago

Committed in 24cc633fbd6f34d0476a12a50e3cbbc015fd5d65 and addressed lambda concern in fe8c890b91167e36f39d0530600936c0b573445e.