Skip to content

Commit

Permalink
Do not try flatparse scanner for .md files (#2934)
Browse files Browse the repository at this point in the history
- In #2925, the flatparse scanner
always fails for .md files and silently falls back to megaparsec.
- In #2929, a warning is introduced
that informs the user when the fallback parser is being used. This is
causing a warning every time we scan a markdown file.
- This pr fixes the problem by changing the default strategy to directly
use megaparsec when a .md file is given.
  • Loading branch information
janmasrovira authored Aug 2, 2024
1 parent e2fe830 commit 69b5916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/Juvix/Compiler/Concrete/Translation/ImportScanner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scanBSImports ::
ByteString ->
Sem r ScanResult
scanBSImports fp inputBS = do
strat <- ask
strat <- adaptStrategy <$> ask
case strat of
ImportScanStrategyFallback ->
case FlatParse.scanBSImports fp inputBS of
Expand All @@ -59,13 +59,20 @@ scanBSImports fp inputBS = do
Just r -> return r
ImportScanStrategyMegaparsec -> Megaparsec.scanBSImports fp inputBS
where
adaptStrategy :: ImportScanStrategy -> ImportScanStrategy
adaptStrategy = \case
ImportScanStrategyFallback
| not (isJuvixFile fp) -> ImportScanStrategyMegaparsec
s -> s

fileLoc :: Interval
fileLoc =
Interval
{ _intervalFile = fp,
_intervalStart = tmpFileLoc,
_intervalEnd = tmpFileLoc
}

tmpFileLoc :: FileLoc
tmpFileLoc =
FileLoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import Juvix.Prelude.FlatParse qualified as FP
import Juvix.Prelude.FlatParse.Lexer qualified as L

scanBSImports :: Path Abs File -> ByteString -> Maybe ScanResult
scanBSImports fp
-- FlatParse only supports .juvix files
| isJuvixFile fp = fromResult . scanner fp
| otherwise = const Nothing
scanBSImports fp = fromResult . scanner fp
where
fromResult :: Result () ok -> Maybe ok
fromResult = \case
Expand Down

0 comments on commit 69b5916

Please sign in to comment.