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:
parent
799d85034f
commit
8e204634b8
@ -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 "---"
|
||||
|
@ -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 ::
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user