Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --print-loc option to dev import-tree scan command #3263

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Commands/Dev/ImportTree/ScanFile.hs
Original file line number Diff line number Diff line change
@@ -16,4 +16,7 @@ runCommand ScanFileOptions {..} =
forM_ (scanRes ^. scanResultImports) $ \impor -> do
opts <- askGenericOptions
renderStdOut (ppOutNoComments opts impor)
when _scanFilePrintLoc $ do
renderStdOut @Text " "
renderStdOut (ppOutNoComments opts (getLoc impor))
newline
6 changes: 6 additions & 0 deletions app/Commands/Dev/ImportTree/ScanFile/Options.hs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import Juvix.Compiler.Concrete.Translation.ImportScanner

data ScanFileOptions = ScanFileOptions
{ _scanFileFile :: AppPath File,
_scanFilePrintLoc :: Bool,
_scanFileStrategy :: ImportScanStrategy
}
deriving stock (Data)
@@ -15,4 +16,9 @@ parseScanFile :: Parser ScanFileOptions
parseScanFile = do
_scanFileFile <- parseInputFiles (FileExtJuvix :| [FileExtJuvixMarkdown])
_scanFileStrategy <- optImportScanStrategy
_scanFilePrintLoc <-
switch
( long "print-loc"
<> help "Print the location of each import"
)
pure ScanFileOptions {..}
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Concrete/Translation/ImportScanner/Base.hs
Original file line number Diff line number Diff line change
@@ -52,3 +52,5 @@ data Token
| TokenImport ImportScanParsed
| TokenReserved
| TokenCode

makePrisms ''Token
Original file line number Diff line number Diff line change
@@ -69,14 +69,9 @@ scanner fp bs = do
pPreScanResult :: Parser e [ImportScanParsed]
pPreScanResult = do
whiteSpaceAndComments
imports <- mapMaybe getImport <$> many pToken
imports <- (^.. each . _TokenImport) <$> many pToken
eof
return imports
where
getImport :: Token -> Maybe ImportScanParsed
getImport = \case
TokenImport i -> Just i
_ -> Nothing

bareIdentifier :: ParserT st e String
bareIdentifier = do
2 changes: 0 additions & 2 deletions src/Juvix/Prelude/FlatParse/Lexer.hs
Original file line number Diff line number Diff line change
@@ -11,7 +11,5 @@ import Juvix.Prelude.FlatParse
whiteSpace1 :: Parser e ()
whiteSpace1 = skipSome whiteSpaceChar

-- TODO is Ascii version much faster?
whiteSpaceChar :: Parser e ()
-- whiteSpaceChar = skipSatisfyAscii L.isWhiteSpace
whiteSpaceChar = skipSatisfy L.isWhiteSpace