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

Do not try flatparse scanner for .md files #2934

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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
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
Loading