diff --git a/src/Lib/Prettier.idr b/src/Lib/Prettier.idr index b0dc33a..cf99175 100644 --- a/src/Lib/Prettier.idr +++ b/src/Lib/Prettier.idr @@ -33,10 +33,10 @@ group : Doc -> Doc group x = Alt (flatten x) x -- TODO - we can accumulate snoc and cat all at once -layout : List Item -> String -layout [] = "" -layout (LINE k :: x) = "\n" ++ replicate k ' ' ++ layout x -layout (TEXT str :: x) = str ++ layout x +layout : List Item -> SnocList String -> String +layout [] acc = fastConcat $ cast acc +layout (LINE k :: x) acc = layout x (acc :< "\n" :< replicate k ' ') +layout (TEXT str :: x) acc = layout x (acc :< str) ||| Whether a documents first line fits. fits : Nat -> List Item -> Bool @@ -73,7 +73,7 @@ interface Pretty a where export render : Nat -> Doc -> String -render w x = layout (best w 0 x) +render w x = layout (best w 0 x) [<] public export Semigroup Doc where x <+> y = Seq x (Seq (Text " ") y) diff --git a/src/Main.idr b/src/Main.idr index 4e70838..a9d281f 100644 --- a/src/Main.idr +++ b/src/Main.idr @@ -41,11 +41,11 @@ dumpContext top = do writeSource : String -> M () writeSource fn = do docs <- compile - let src = unlines $ ["#!/usr/bin/env node"] + let src = unlines $ + [ "#!/usr/bin/env node" + , "const PiType = (h0, h1) => ({ tag: \"PiType\", h0, h1 })" ] ++ map (render 90) docs - ++ [ "const PiType = (h0, h1) => ({ tag: \"PiType\", h0, h1 })" - , "main();" - ] + ++ [ "main();" ] Right _ <- writeFile fn src | Left err => fail (show err) Right _ <- chmodRaw fn 493 | Left err => fail (show err)