eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

let and if then else expressions #104

Closed davidfestal closed 9 years ago

davidfestal commented 9 years ago

The new let and if then else expressions allow doing some nesting like this :

function buildParents(String entry) 
    => let(parents = entry.split('/'.equals).filter(not(String.empty)).exceptLast)
            if (exists firstParent = parents.first)
            then
                if (nonempty restOfParents = parents.rest.sequence())
                then restOfParents.scan(firstParent + "/")(
                    (path, nextParent) => "".join { path, nextParent + "/"})
                else { firstParent + "/"}
            else {};

However the Ceylon formatter formats it like that :

function buildParents(String entry)
        => let (parents = entry.split('/'.equals).filter(not(String.empty)).exceptLast)
    if (exists firstParent = parents.first)
            then
    if (nonempty restOfParents = parents.rest.sequence())
            then restOfParents.scan(firstParent + "/")(
        (path, nextParent) => "".join { path, nextParent + "/" })
            else { firstParent + "/" }
            else {};
lucaswerkmeister commented 9 years ago

Two things here:

  1. [ ] Indentation of => should stack – can be emulated by separately creating the context
  2. [ ] if should have a proper indentation after it, and then and else shouldn’t have any indentation before them
lucaswerkmeister commented 9 years ago

if should have a proper indentation after it

Hm… which one is better?

if (c)
    then x
    else y
if (c)
then x
else y

Perhaps the issue is rather that then and else should introduce indentation, not if.

lucaswerkmeister commented 9 years ago

If expression part is done. => is a complicated issue which I keep forgetting I’ve already tried to solve; I’ll create a new issue for that.

luolong commented 9 years ago

I prefer this (its more regular):

if (c)
then x
else y
lucaswerkmeister commented 9 years ago

I agree, and that’s what we have now.