1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-07 16:22:14 +03:00

Do not try flatparse scanner for .md files (#2934)

- In https://github.com/anoma/juvix/pull/2925, the flatparse scanner
always fails for .md files and silently falls back to megaparsec.
- In https://github.com/anoma/juvix/pull/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.
This commit is contained in:
Jan Mas Rovira 2024-08-02 12:31:47 +02:00 committed by GitHub
parent e2fe830d28
commit 69b5916270
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -41,7 +41,7 @@ scanBSImports ::
ByteString -> ByteString ->
Sem r ScanResult Sem r ScanResult
scanBSImports fp inputBS = do scanBSImports fp inputBS = do
strat <- ask strat <- adaptStrategy <$> ask
case strat of case strat of
ImportScanStrategyFallback -> ImportScanStrategyFallback ->
case FlatParse.scanBSImports fp inputBS of case FlatParse.scanBSImports fp inputBS of
@ -59,6 +59,12 @@ scanBSImports fp inputBS = do
Just r -> return r Just r -> return r
ImportScanStrategyMegaparsec -> Megaparsec.scanBSImports fp inputBS ImportScanStrategyMegaparsec -> Megaparsec.scanBSImports fp inputBS
where where
adaptStrategy :: ImportScanStrategy -> ImportScanStrategy
adaptStrategy = \case
ImportScanStrategyFallback
| not (isJuvixFile fp) -> ImportScanStrategyMegaparsec
s -> s
fileLoc :: Interval fileLoc :: Interval
fileLoc = fileLoc =
Interval Interval
@ -66,6 +72,7 @@ scanBSImports fp inputBS = do
_intervalStart = tmpFileLoc, _intervalStart = tmpFileLoc,
_intervalEnd = tmpFileLoc _intervalEnd = tmpFileLoc
} }
tmpFileLoc :: FileLoc tmpFileLoc :: FileLoc
tmpFileLoc = tmpFileLoc =
FileLoc FileLoc

View File

@ -12,10 +12,7 @@ import Juvix.Prelude.FlatParse qualified as FP
import Juvix.Prelude.FlatParse.Lexer qualified as L import Juvix.Prelude.FlatParse.Lexer qualified as L
scanBSImports :: Path Abs File -> ByteString -> Maybe ScanResult scanBSImports :: Path Abs File -> ByteString -> Maybe ScanResult
scanBSImports fp scanBSImports fp = fromResult . scanner fp
-- FlatParse only supports .juvix files
| isJuvixFile fp = fromResult . scanner fp
| otherwise = const Nothing
where where
fromResult :: Result () ok -> Maybe ok fromResult :: Result () ok -> Maybe ok
fromResult = \case fromResult = \case