From 3c49a688a151f3bbfd0ca11846b633ecd4b9d0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20S=CC=8Cebek?= Date: Wed, 23 Aug 2023 20:45:23 +0200 Subject: [PATCH 1/2] Make CLI format format --- app/Main.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index b3768f1c9..322fde08c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -16,7 +16,9 @@ import Options.Applicative import Swarm.App (appMain) import Swarm.Doc.Gen (EditorType (..), GenerateDocs (..), PageAddress (..), SheetType (..), generateDocs) import Swarm.Language.LSP (lspMain) -import Swarm.Language.Pipeline (processTerm) +import Swarm.Language.Module (Module (..)) +import Swarm.Language.Pipeline (ProcessedTerm (..), processTerm) +import Swarm.Language.Pretty (prettyText) import Swarm.TUI.Model (AppOpts (..), ColorMode (..)) import Swarm.TUI.Model.UI (defaultInitLgTicksPerSecond) import Swarm.Version @@ -161,8 +163,11 @@ formatFile :: Input -> IO () formatFile input = do content <- getInput input case processTerm content of - Right _ -> do - Text.putStrLn content + Right t -> do + case t of + Nothing -> Text.putStrLn "" + Just (ProcessedTerm (Module ast _mctx) _req _ctx) -> + Text.putStrLn $ prettyText ast exitSuccess Left e -> do Text.hPutStrLn stderr $ showInput input <> ":" <> e From 201a9a7d643c7bbb602b3a5524d7402a54dad970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20S=CC=8Cebek?= Date: Thu, 24 Aug 2023 22:48:12 +0200 Subject: [PATCH 2/2] Do not elaborate format (thanks @byorgey) --- app/Main.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 322fde08c..47d003407 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -16,8 +16,7 @@ import Options.Applicative import Swarm.App (appMain) import Swarm.Doc.Gen (EditorType (..), GenerateDocs (..), PageAddress (..), SheetType (..), generateDocs) import Swarm.Language.LSP (lspMain) -import Swarm.Language.Module (Module (..)) -import Swarm.Language.Pipeline (ProcessedTerm (..), processTerm) +import Swarm.Language.Parse (readTerm) import Swarm.Language.Pretty (prettyText) import Swarm.TUI.Model (AppOpts (..), ColorMode (..)) import Swarm.TUI.Model.UI (defaultInitLgTicksPerSecond) @@ -162,12 +161,11 @@ showInput (File fp) = pack fp formatFile :: Input -> IO () formatFile input = do content <- getInput input - case processTerm content of + case readTerm content of Right t -> do case t of Nothing -> Text.putStrLn "" - Just (ProcessedTerm (Module ast _mctx) _req _ctx) -> - Text.putStrLn $ prettyText ast + Just ast -> Text.putStrLn $ prettyText ast exitSuccess Left e -> do Text.hPutStrLn stderr $ showInput input <> ":" <> e