coco
coco copied to clipboard
Implicit block overhaul
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:
- Insert an implicit INDENT after an implicit block opener (
then->etc.) if the next token isn't NEWLINE or INDENT. - Insert an implicit DEDENT before an implicit block closer (
elsecatchetc.) 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.
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 |>.
- 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.