coco icon indicating copy to clipboard operation
coco copied to clipboard

Implicit block overhaul

Open satyr opened this issue 13 years ago • 2 comments

The current rule for generating implicit block is too complicated to explain in a few sentences.

For example the following:

switch
case a then if b then c else d

doesn't parse, because the first then generates DEDENT before else. You pretty much have to read through addImplicitIndentations to grok the rule.

So here's a proposal to make it simpler:

  1. Insert an implicit INDENT after an implicit block opener (then -> etc.) if the next token isn't NEWLINE or INDENT.
  2. Insert an implicit DEDENT before an implicit block closer (else catch etc.) if the last INDENT is implicit.

E.g.:

-> a
   b
# parses as
->
   a
   b

switch
case a then if b then c else d
# parses as
switch
case a
            if b
                      c
            else
                             d

Pros

Simpler, grokkable rule.

Cons

Incompatibility. Some code currently valid like

for k in o then let
  ...

will be invalid.

satyr avatar Apr 18 '12 09:04 satyr

To compensate the loss of then if then let etc., we can backport LiveScript's =>:

truthies = for x of xs => if x => x

The pipe operator can be |>.

satyr avatar Jul 13 '12 05:07 satyr

  • 7ebcdbcc20b583afbd35f675fe5040baa6016519 fixed the OP test case.
  • d0a3b1d102cd3410dfa122c90c449c8d4786192b enabled the Haskell-ish off-side rule via =>.

Making this less attractive, especially with the then-if incompatibility.

satyr avatar Jul 29 '12 09:07 satyr