1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 14:13:27 +03:00

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

This pr makes it possible to properly hihglight .juvix.md files
This commit is contained in:
Jan Mas Rovira 2024-09-11 14:07:16 +02:00 committed by GitHub
parent 799d85034f
commit 8e204634b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View File

@ -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 "---"

View File

@ -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 ::

View File

@ -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

View File

@ -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;