mirror of
https://github.com/anoma/juvix.git
synced 2024-12-13 19:49:20 +03:00
f4aa70b13d
- Closes #2128 - Closes #2161 This pr fully implements the monadic pretty printer based on `ExactPrint`, which respects comments. Until now, comments inside expressions were printed after the current statement. Now they are printed in the correct place, except when a comment occurs before something that we don't store its location. E.g. parentheses, semicolons, braces, colons, etc. I proposed that we irone out this issue in a separate pr. Since the old non-monadic algorithm is no longer necessary, I removed it.
26 lines
972 B
Haskell
26 lines
972 B
Haskell
module Commands.Dev.Scope where
|
|
|
|
import Commands.Base
|
|
import Commands.Dev.Scope.Options
|
|
import Juvix.Compiler.Concrete.Language
|
|
import Juvix.Compiler.Concrete.Print qualified as Print
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping qualified as Scoper
|
|
import Juvix.Prelude.Pretty
|
|
|
|
runCommand :: (Members '[Embed IO, App] r) => ScopeOptions -> Sem r ()
|
|
runCommand opts = do
|
|
globalOpts <- askGlobalOptions
|
|
res :: Scoper.ScoperResult <- runPipeline (opts ^. scopeInputFile) upToScoping
|
|
let modules :: NonEmpty (Module 'Scoped 'ModuleTop) = res ^. Scoper.resultModules
|
|
forM_ modules $ \s ->
|
|
if
|
|
| opts ^. scopeWithComments ->
|
|
renderStdOut (Print.ppOut (globalOpts, opts) (res ^. Scoper.comments) s)
|
|
| otherwise ->
|
|
renderStdOut (Print.ppOutNoComments (globalOpts, opts) s)
|
|
when (opts ^. scopeListComments) $ do
|
|
newline
|
|
newline
|
|
say "Comments:"
|
|
say (prettyText (res ^. Scoper.comments))
|