xarvh / squarepants

13 stars 0 forks source link

Formatter improvements #27

Open xarvh opened 1 year ago

xarvh commented 1 year ago

A named function (ie, x = fn ....) should have a blank line after the fn ...:

FROM

x =
     fn _:
     blah blah blah

TO

x =
     fn _:

     blah blah blah

Named function's body should always be aligned, not indented.

FROM

x =
     fn _:

         blah blah blah

TO

x =
     fn _:

     blah blah blah

Parse multiple statements in parenthesis?


Multiline list items should be followed by a blank?

FROM

[
, a
  >>b
, c
  >> d
]

TO

[
, a
  >>b

, c
  >> d

]

Continuations should always be followed by a blank?

FROM

    >> onOk fn x:
    a = 1

TO

    >> onOk fn x:

    a = 1

How do we distinguish between the cases where the body of the lambda should be indented:

blah
>> List.for 0 __ fn a, b:
       doStuffWith a b

from those where it should not?

blah
>> onOk fn b:
doStuffWith b
xarvh commented 1 year ago
xarvh commented 1 year ago
            name & []
            >> Ok

Should be preserved.

Specifically: changing var & [] >> Ok to var & [] \n >> Ok should be enough to make the following try..as go on multiple lines:

    try expr_ as
        , FA.Constructor var: var & [] >> Ok
        , FA.Call (FA.Expression _ _ (FA.Constructor var)) pars: var & pars >> Ok
        , _: error env pos [ "I was expecting a 'constructor name here!" ]
xarvh commented 1 year ago
            error env pos
                [
                , "I was expecting a 'constructor name here!"
                ]

Should be preserved

xarvh commented 1 year ago

FROM

    [
    , a
    , b
    >> c
    >> d
    ]

TO

    [
    , a
    , b
      >> c
      >> d
    ]
xarvh commented 1 year ago

FROM

a :: b

TO

[a, b...]
xarvh commented 1 year ago
    [
    , Prelude.unaryPlus.usr & unaryPlus
    , Prelude.unaryMinus.usr & unaryMinus
    #
    , Prelude.add.usr
    & binop "+"
    , Prelude.multiply.usr & binop "*"
    , Prelude.subtract.usr & binop "-"
    , Prelude.mutableAssign.usr & binop "="
    ]
xarvh commented 1 year ago

preserves text interpolation:

   """
      const rec = (ls) => {
        if (ls[0] === '""" .. listNilName .. """')
          return hash;
    """

IT CURRENTLY BREAKS Runtime.sp!!!

xarvh commented 1 year ago

FROM

resolve as fn fn key: Dict key whatever, key, [ key ], State key: State key with key NonFunction =

TO

resolve as fn (fn key: Dict key whatever), key, [ key ], State key: State key with key NonFunction =
xarvh commented 1 month ago

This is just plain unreadable

                     [
                     , 3
                     & [
                     , TH.moduleUsr "a" & 1
                     , TH.moduleUsr "a" & 2
                     , TH.moduleUsr "p" & 1
                     , TH.moduleUsr "q" & 1
                     ]
xarvh commented 3 weeks ago

{} and [] can be on a single line only if they don't contain any commas? Would be annoying in annotations?

xarvh commented 2 weeks ago

We have three types of fn formatting:

A) Inline

fn args: body

This is when body fits a single line.

B) Non-indented body

f =
   fn meh:
   nonIndentedBody

>> blah fn meh:
nonIndentedBody

C) Indented body

someFunction fn args:
     body

Case B) should have a blank line between fn and body. C) should not.

xarvh commented 2 weeks ago

This is too long.

                    addErrorIf (uni /= expectedPatternType.uni) env (CA.patternPos caPattern) ('errorUniquenessDoesNotMatchParameter uni expectedPatternType) @state

We should calculate some sort of complexity-per-line and break the call into multiple lines if it hits a threshold.

If the last argument is a function that breaks into multiple lines, only its first line (ie, "fn a, b, c:") should be counted.

xarvh commented 2 weeks ago

Constructors should be in alphabetic order, this is necessary because they are comparable and their order changes with their name.