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

Fix flatparse location #3264

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Up @@ -5,6 +5,7 @@ import Juvix.Compiler.Concrete.Translation.ImportScanner

data ScanFileOptions = ScanFileOptions
{ _scanFileFile :: AppPath File,
_scanFilePrintLoc :: Bool,
_scanFileStrategy :: ImportScanStrategy
}
deriving stock (Data)
Expand All @@ -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
Expand Up @@ -52,3 +52,5 @@ data Token
| TokenImport ImportScanParsed
| TokenReserved
| TokenCode

makePrisms ''Token
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ scanner fp bs = do
allFileLocs :: [FileLoc]
allFileLocs =
[ FileLoc
{ _locLine = Pos (fromIntegral l),
_locCol = Pos (fromIntegral c),
{ _locLine = Pos (1 + fromIntegral l),
_locCol = Pos (1 + fromIntegral c),
_locOffset = Pos (fromIntegral p)
}
| (FP.Pos p, (l, c)) <- zipExact importsPositions (posLineCols bs importsPositions)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Prelude/FlatParse/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading