-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b50a271
commit d1260cf
Showing
12 changed files
with
122 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
module Commands.Dev.ImportTree.ScanFile where | ||
module Commands.Dev.ImportTree.ScanFile (runCommand) where | ||
|
||
import Commands.Base | ||
import Commands.Dev.ImportTree.ScanFile.Options | ||
import Data.Yaml qualified as Yaml | ||
import Juvix.Compiler.Concrete.Print | ||
import Juvix.Compiler.Concrete.Translation.ImportScanner | ||
|
||
runCommand :: (Members AppEffects r) => ScanFileOptions -> Sem r () | ||
runCommand ScanFileOptions {..} = | ||
runCommand opts@ScanFileOptions {..} = | ||
runFilesIO | ||
. runAppError @ParserError | ||
. runReader _scanFileStrategy | ||
$ do | ||
scanRes <- fromAppPathFile _scanFileFile >>= scanFileImports | ||
forM_ (scanRes ^. scanResultImports) $ \impor -> do | ||
opts <- askGenericOptions | ||
renderStdOut (ppOutNoComments opts impor) | ||
when _scanFilePrintLoc $ do | ||
renderStdOut @Text " " | ||
renderStdOut (ppOutNoComments opts (getLoc impor)) | ||
newline | ||
p <- fromAppPathFile _scanFileFile | ||
scanRes <- scanFileImports p | ||
printRes opts scanRes | ||
when _scanFileCheck (check p scanRes) | ||
|
||
printRes :: (Members (AppEffects) r) => ScanFileOptions -> ScanResult -> Sem r () | ||
printRes ScanFileOptions {..} scanRes = do | ||
forM_ (scanRes ^. scanResultImports) $ \impor -> do | ||
opts <- askGenericOptions | ||
renderStdOut (ppOutNoComments opts impor) | ||
when _scanFilePrintLoc $ do | ||
renderStdOut @Text " " | ||
renderStdOut (ppOutNoComments opts (getLoc impor)) | ||
newline | ||
|
||
check :: (Members (Reader ImportScanStrategy ': AppEffects) r) => Path Abs File -> ScanResult -> Sem r () | ||
check file reference = runAppError @ParserError $ do | ||
refStrat :: ImportScanStrategy <- ask | ||
forM_ allElements $ \strat -> when (refStrat /= strat) . local (const strat) $ do | ||
res <- scanFileImports file | ||
let yamlFile :: ImportScanStrategy -> Path Abs File | ||
yamlFile s = replaceExtensions' ["." <> show s, ".yaml"] file | ||
let err :: AnsiText | ||
err = | ||
mkAnsiText @Text $ | ||
prettyText refStrat | ||
<> " and " | ||
<> prettyText strat | ||
<> " don't match" | ||
<> "\n" | ||
<> prettyText refStrat | ||
<> " written to:\n" | ||
<> toFilePath (yamlFile refStrat) | ||
<> "\n" | ||
<> prettyText strat | ||
<> " written to:\n" | ||
<> toFilePath (yamlFile strat) | ||
<> "\n" | ||
unless (res == reference) $ do | ||
liftIO (Yaml.encodeFile (toFilePath (yamlFile refStrat)) reference) | ||
liftIO (Yaml.encodeFile (toFilePath (yamlFile strat)) res) | ||
logErrorWithTag err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters