plow-technologies / inferno

A statically-typed functional scripting language
MIT License
4 stars 1 forks source link

Improve pretty printer: use consistent indentation levels #110

Closed siddharth-krishna closed 8 months ago

siddharth-krishna commented 8 months ago

This PR makes the pretty printer use consistent indentation levels (+2 spaces for each level) and other clean-ups that result in generally using less horizontal whitespace. Here's a before/after: image

Full sample before:

let bigApp = bigbigbigbigbigbigbigbigbigbigbig
               bigbigbigbigbigbigbigbigbigbigbig
               bigbigbigbigbigbigbigbigbigbigbig
in let null = ()
in let smallTup = (12314314, fadsfdfsadfa, 13413241345)
in let mediumTup = ( medium
                   , medium
                   , medium
                   , medium
                   , medium
                   , medium
                   , medium
                   , medium
                   , mediu
                   , mediu )
in let bigTup = ( bigbigbigbigbigbigbigbigbigbigbig
                , bigbigbigbigbigbigbigbigbigbigbig
                , bigbigbigbigbigbigbigbigbigbigbig
                , Some bigbigbigbigbigbigbigbigbigbigbig
                         bigbigbigbigbigbigbigbigbigbigbig
                         bigbigbigbigbigbigbigbigbigbigbig )
in assert some thing small
    in assert some
                thing
                medium
                medium
                medium
                medium
                medium
                medium
                medium
                medium
                medium
           in assert some
                       thing
                       bigbigbigbigbigbigbigbigbigbigbig
                       bigbigbigbigbigbigbigbigbigbigbig
                       bigbigbigbigbigbigbigbigbigbigbig
                  in let x = match some thing small with { | 1 -> 2 | _ -> 3}
                     in let x = match some
                                        thing
                                        bigbigbigbigbigbigbigbigbigbigbig
                                        bigbigbigbigbigbigbigbigbigbigbig
                                        bigbigbigbigbigbigbigbigbigbigbig with {
                                  | ( biggbig
                                    , bigbigbig
                                    , bigbigbigbig
                                    , bigbigbigbigbig
                                    , bigbigbigbigbigbigbig
                                    , bigbigbigbigbigbigbigbigbig ) ->
                                    2
                                  | xyz -> 3
                                  | _ -> 4 }
                     in let smallRec = {height = 2; weight = (3.54, "kgs")}
                     in let bigRec = { expr = let x = 2
                                              in x + 1
                                     ; height = ( 12314314
                                                , fadsfdfsadfa
                                                , 13413241345 )
                                     ; weight = (3.54, "kgs")
                                     ; name = ( biggbig
                                              , bigbigbig
                                              , bigbigbigbig
                                              , bigbigbigbigbig
                                              , bigbigbigbigbigbigbig
                                              , bigbigbigbigbigbigbigbigbig ) }
                     in let smallArr = [12314314, fadsfdfsadfa, 13413241345]
                     in let mediumArr = [ medium
                                        , medium
                                        , medium
                                        , medium
                                        , medium
                                        , medium
                                        , medium
                                        , medium
                                        , mediu
                                        , mediu ]
                     in let bigArr = [ bigbigbigbigbigbigbigbigbigbigbig
                                     , bigbigbigbigbigbigbigbigbigbigbig
                                     , bigbigbigbigbigbigbigbigbigbigbig
                                     , Some bigbigbigbigbigbigbigbigbigbigbig
                                              bigbigbigbigbigbigbigbigbigbigbig
                                              bigbigbigbigbigbigbigbigbigbigbig ]
                     in let arrayComp = [bigFun
                                           one
                                           two
                                           three
                                           four | one <- some thing
                                                , if one two]
                     in let arrayComp = [getBitValAndTime
                                           t
                                           bigbig
                                           bigbigbig
                                           bigbigbigbigbig
                                           bigbigbigbigbigbigbigbigbigbigbig
                                           bigbigbigbigbigbigbigbigbigbigbig | t <- Time.intervalEvery
                                                                                      (Time.seconds
                                                                                        intervalStep)
                                                                                      startOfInterval
                                                                                      ?now
                                                                             , one <- some
                                                                                        thing
                                                                             , two <- some
                                                                                        other
                                                                                        thing
                                                                             , three <- Some bigbigbigbigbigbigbigbigbigbigbig
                                                                                               bigbigbigbigbigbigbigbigbigbigbig
                                                                                               bigbigbigbigbigbigbigbigbigbigbig
                                                                             , if (one
                                                                                    two
                                                                                    bigbigbigbigbigbigbigbigbigbigbig
                                                                                    bigbigbigbigbigbigbigbigbigbigbig
                                                                                    bigbigbigbigbigbigbigbigbigbigbig)]
                     in let module mSmall = Number
                      in let module bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig = Array
                          in open Array
                               in open Array(foo, bar, baz, bar, baz, bar, baz)
                                    in open Array( foo
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz
                                                 , bar
                                                 , baz )
                                         in let nested = Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some Some bla
                                            in 2.0

Full sample after:

let bigApp =
  bigbigbigbigbigbigbigbigbigbigbig
    bigbigbigbigbigbigbigbigbigbigbig
    bigbigbigbigbigbigbigbigbigbigbig
in
let null = () in
let smallTup = (12314314, fadsfdfsadfa, 13413241345) in
let mediumTup =
  (medium, medium, medium, medium, medium, medium, medium, medium, mediu, mediu)
in
let bigTup =
  ( bigbigbigbigbigbigbigbigbigbigbig
  , bigbigbigbigbigbigbigbigbigbigbig
  , bigbigbigbigbigbigbigbigbigbigbig
  , Some
    bigbigbigbigbigbigbigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
  )
in
assert some thing small in
assert
  some thing medium medium medium medium medium medium medium medium medium
in
assert
  some
    thing
    bigbigbigbigbigbigbigbigbigbigbig
    bigbigbigbigbigbigbigbigbigbigbig
    bigbigbigbigbigbigbigbigbigbigbig
in
let x = match some thing small with {1 -> 2 | _ -> 3} in
let x =
  match
    some
      thing
      bigbigbigbigbigbigbigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
  with {
    | ( biggbig
      , bigbigbig
      , bigbigbigbig
      , bigbigbigbigbig
      , bigbigbigbigbigbigbig
      , bigbigbigbigbigbigbigbigbig )
    ->
      2
    | xyz -> 3
    | _ -> 4
  }
in
let smallRec = {height = 2; weight = (3.54, "kgs")} in
let bigRec =
  { expr = let x = 2 in x + 1
  ; height = (12314314, fadsfdfsadfa, 13413241345)
  ; weight = (3.54, "kgs")
  ; name =
    ( biggbig
    , bigbigbig
    , bigbigbigbig
    , bigbigbigbigbig
    , bigbigbigbigbigbigbig
    , bigbigbigbigbigbigbigbigbig
    )
  }
in
let smallArr = [12314314, fadsfdfsadfa, 13413241345] in
let mediumArr =
  [medium, medium, medium, medium, medium, medium, medium, medium, mediu, mediu]
in
let bigArr =
  [ bigbigbigbigbigbigbigbigbigbigbig
  , bigbigbigbigbigbigbigbigbigbigbig
  , bigbigbigbigbigbigbigbigbigbigbig
  , Some
      bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig
  ]
in
let arrayComp = [bigFun one two three four | one <- some thing, if one two] in
let arrayComp =
  [ getBitValAndTime
      t
      bigbig
      bigbigbig
      bigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
      bigbigbigbigbigbigbigbigbigbigbig
  | t <- Time.intervalEvery (Time.seconds intervalStep) startOfInterval ?now
  , one <- some thing
  , two <- some other thing
  , three <-
    Some
      bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig
  , if
    ( one
        two
        bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig
        bigbigbigbigbigbigbigbigbigbigbig)
  ]
in
let module mSmall = Number in
let module
  bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig = Array
in
open Array in
open Array (foo, bar, baz, bar, baz, bar, baz) in
open Array
  ( foo
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  , bar
  , baz
  )
in
let nested =
  Some
    Some
      Some
        Some
          Some
            Some
              Some
                Some
                  Some
                    Some Some Some Some Some Some Some Some Some Some Some bla
in
2.0