eclipse-archived / ceylon.formatter

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

Add support for “pipe” operator #151

Closed lucaswerkmeister closed 6 years ago

lucaswerkmeister commented 6 years ago

AFAICT eclipse/ceylon#6615 isn’t quite settled yet, but it looks like some form of the operator will make it into the next release, so don’t forget to add support for it.

Looks like this:

shared void run() {
    "hello world how are you today, I'm doing great !!!! xxxxxyyy"
            |> String.size
            |> (Integer i) => Integer.format(i, 16) 
            |> String.uppercased 
            |> String.trimmed 
            |> print;
}

and should be formatted like that too, I think (one level of pre-indent, just like other binary operators).

lucaswerkmeister commented 6 years ago

Looks like the operator is settled now (final form: |>), see eclipse/ceylon@4c0288b45ae908ab91b00b25f889b0c380df30bd for spec.

lucaswerkmeister commented 6 years ago

@gavinking the way that you implemented |> and >|> in eclipse/ceylon@5c80f1de3ebc4fb82e2bd59d491913384b6aa17f (desugaring them inside the parser) makes it almost impossible for me to format them. How difficult would it be to do that desugaring in a post-processing step instead (which I would skip)?

gavinking commented 6 years ago

Pffffff. Hard, I think. You can't look at the token, or something?

lucaswerkmeister commented 6 years ago

I can try, but it’s almost certainly going to break as soon as you touch the desugaring code. And then I suppose I’ll also have to do the same thing in ceylon.ast, in both directions.

gavinking commented 6 years ago

Thanks @lucaswerkmeister. Sorry about the hackery.