From 2416f78a3eb4c83a5bf01533d3047edb52a28820 Mon Sep 17 00:00:00 2001 From: Jonathan Cubides Date: Tue, 30 Jul 2024 16:51:55 -0500 Subject: [PATCH] Fix #2924. Use MegaParsec scanner for Markdown files (#2925) This PR addresses a bug/missing case present since v0.6.2, introduced specifically by - PR #2779, That PR involves detecting imports in Juvix files before type checking, and that's the issue. Detecting/scanning imports is done by running a flat parser (which ignores the Juvix Markdown structure) and when it fails, it runs a Megaparser parse. So, for simplicity, we could just continue using the same Megaparser as before for Juvix Markdown files. --------- Co-authored-by: Jan Mas Rovira --- .../Compiler/Concrete/Translation/ImportScanner/FlatParse.hs | 5 ++++- tests/positive/Markdown/Test.juvix.md | 2 ++ tests/positive/Markdown/markdown/Test.md | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs index f39c42d0d..9ca6e710f 100644 --- a/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs +++ b/src/Juvix/Compiler/Concrete/Translation/ImportScanner/FlatParse.hs @@ -12,7 +12,10 @@ import Juvix.Prelude.FlatParse qualified as FP import Juvix.Prelude.FlatParse.Lexer qualified as L scanBSImports :: Path Abs File -> ByteString -> Maybe ScanResult -scanBSImports fp = fromResult . scanner fp +scanBSImports fp + -- FlatParse only supports .juvix files + | isJuvixFile fp = fromResult . scanner fp + | otherwise = const Nothing where fromResult :: Result () ok -> Maybe ok fromResult = \case diff --git a/tests/positive/Markdown/Test.juvix.md b/tests/positive/Markdown/Test.juvix.md index 12698dd12..aeb24dfa7 100644 --- a/tests/positive/Markdown/Test.juvix.md +++ b/tests/positive/Markdown/Test.juvix.md @@ -1,5 +1,7 @@ # Example +What is important is seldom urgent. + A Juvix Markdown file name ends with `.juvix.md`. This kind of file must contain a module declaration at the top, as shown below ---in the first code block. diff --git a/tests/positive/Markdown/markdown/Test.md b/tests/positive/Markdown/markdown/Test.md index d4c15f200..e816efa3c 100644 --- a/tests/positive/Markdown/markdown/Test.md +++ b/tests/positive/Markdown/markdown/Test.md @@ -1,5 +1,7 @@ # Example +What is important is seldom urgent. + A Juvix Markdown file name ends with `.juvix.md`. This kind of file must contain a module declaration at the top, as shown below ---in the first code block.