mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +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:
parent
e2fe830d28
commit
69b5916270
@ -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
|
||||
@ -59,6 +59,12 @@ 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
|
||||
@ -66,6 +72,7 @@ scanBSImports fp inputBS = do
|
||||
_intervalStart = tmpFileLoc,
|
||||
_intervalEnd = tmpFileLoc
|
||||
}
|
||||
|
||||
tmpFileLoc :: FileLoc
|
||||
tmpFileLoc =
|
||||
FileLoc
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user