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

Fix the location in the parser for .juvix.md #3020

Merged
merged 1 commit into from
Sep 11, 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
3 changes: 1 addition & 2 deletions src/Juvix/Compiler/Backend/Markdown/Data/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ processCodeBlock info t loc =
let b = "```" <> info <> t <> "```"
in MkTextBlock TextBlock {_textBlock = b, _textBlockInterval = loc}

instance-- (MK.IsInline TextBlock) =>
MK.IsBlock TextBlock Mk where
instance MK.IsBlock TextBlock Mk where
paragraph a = MkTextBlock a
plain a = MkTextBlock a
thematicBreak = toMK "---"
Expand Down
14 changes: 11 additions & 3 deletions src/Juvix/Compiler/Concrete/Translation/FromSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,32 @@ runMarkdownModuleParser fpath mk =
P.sourceColumn = P.mkPos (intervalStartCol i)
}

getInitFileLoc :: Interval -> FileLoc
getInitFileLoc = (^. intervalStart)

getInitialParserState :: forall a. MK.JuvixCodeBlock -> P.State Text a
getInitialParserState code =
let initPos =
let initPos :: P.SourcePos =
maybe
(P.initialPos (toFilePath fpath))
getInitPos
(code ^. MK.juvixCodeBlockInterval)
initFileLoc :: FileLoc =
maybe
mkInitialFileLoc
getInitFileLoc
(code ^. MK.juvixCodeBlockInterval)
in P.State
{ P.stateInput = code ^. MK.juvixCodeBlock,
P.statePosState =
P.PosState
{ P.pstateInput = code ^. MK.juvixCodeBlock,
P.pstateOffset = 0,
P.pstateOffset = fromIntegral (initFileLoc ^. locOffset),
P.pstateSourcePos = initPos,
P.pstateTabWidth = P.defaultTabWidth,
P.pstateLinePrefix = ""
},
P.stateOffset = 0,
P.stateOffset = fromIntegral (initFileLoc ^. locOffset),
P.stateParseErrors = []
}
parseHelper ::
Expand Down
8 changes: 8 additions & 0 deletions src/Juvix/Data/Loc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ mkLoc offset M.SourcePos {..} =
mkInitialLoc :: Path Abs File -> Loc
mkInitialLoc = mkLoc 0 . M.initialPos . fromAbsFile

mkInitialFileLoc :: FileLoc
mkInitialFileLoc =
FileLoc
{ _locLine = 0,
_locCol = 0,
_locOffset = 0
}

fromPos :: M.Pos -> Pos
fromPos = Pos . fromIntegral . M.unPos

Expand Down
5 changes: 2 additions & 3 deletions tests/positive/Markdown/Test.juvix.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Example

What is important is seldom urgent.
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.
a module declaration at the top, as shown below ---in the first code block.

```juvix
module Test;
Expand All @@ -18,7 +18,6 @@ import Stdlib.Prelude open;
```juvix
fib : Nat → Nat → Nat → Nat
| zero x1 _ := x1

| (suc n) x1 x2 := fib n x2 (x1 + x2);

fibonacci (n : Nat) : Nat := fib n 0 1;
Expand Down
Loading