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:
parent
e2fe830d28
commit
69b5916270
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user