Skip to content

Commit

Permalink
path info message
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Nov 12, 2024
1 parent 4ca7bb1 commit d07f45e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
27 changes: 21 additions & 6 deletions src/Juvix/Compiler/Nockma/Highlight.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Juvix.Compiler.Concrete.Data.Highlight (goFaceError, goFaceSemanticItem)
import Juvix.Compiler.Nockma.Highlight.Base
import Juvix.Compiler.Nockma.Highlight.Doc
import Juvix.Compiler.Nockma.Highlight.Input
import Juvix.Compiler.Nockma.Language
import Juvix.Compiler.Nockma.Language as Nockma
import Juvix.Data.CodeAnn
import Juvix.Emacs.Render
import Juvix.Emacs.SExp
Expand All @@ -25,7 +25,7 @@ buildProperties HighlightInput {..} =
mapMaybe goFaceSemanticItem _highlightSemanticItems
<> map goFaceError _highlightErrors,
_propertiesGoto = [],
_propertiesInfo = map goInfoNockOp _highlightNockOps
_propertiesInfo = map goInfoNockOp _highlightNockOps <> map goInfoPath _highlightPaths
}

-- | Used in nockma-mode
Expand Down Expand Up @@ -60,15 +60,30 @@ withDocTable body =
body
]

goInfoPath :: WithLoc Nockma.Path -> WithLoc PropertyInfo
goInfoPath = fmap toProperty
where
toProperty :: Nockma.Path -> PropertyInfo
toProperty p =
PropertyInfo
{ _infoInfo = String txt,
_infoInit = format
}
where
(txt, format) = renderEmacs msg

msg :: Doc CodeAnn
msg =
ppCodeAnn p
<+> kwEquals
<+> pretty (encodePath p ^. encodedPath)

goInfoNockOp :: WithLoc NockOp -> WithLoc PropertyInfo
goInfoNockOp = fmap toProperty
where
toProperty :: NockOp -> PropertyInfo
toProperty o =
PropertyInfo
{ _infoInfo = toInfo o,
{ _infoInfo = Symbol (nockOpKey o),
_infoInit = nil
}

toInfo :: NockOp -> SExp
toInfo = Symbol . nockOpKey
7 changes: 7 additions & 0 deletions src/Juvix/Compiler/Nockma/Highlight/Input.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module Juvix.Compiler.Nockma.Highlight.Input where

import Juvix.Compiler.Nockma.Language hiding (Path)
import Juvix.Compiler.Nockma.Language qualified as Nockma
import Juvix.Data.CodeAnn
import Juvix.Prelude

data HighlightInput = HighlightInput
{ _highlightSemanticItems :: [SemanticItem],
_highlightNockOps :: [WithLoc NockOp],
_highlightPaths :: [WithLoc Nockma.Path],
_highlightErrors :: [Interval]
}

Expand All @@ -17,6 +19,7 @@ emptyHighlightInput =
HighlightInput
{ _highlightSemanticItems = [],
_highlightNockOps = [],
_highlightPaths = [],
_highlightErrors = []
}

Expand All @@ -25,19 +28,22 @@ filterInput absPth HighlightInput {..} =
HighlightInput
{ _highlightSemanticItems = filterByLoc absPth _highlightSemanticItems,
_highlightNockOps = filterByLoc absPth _highlightNockOps,
_highlightPaths = filterByLoc absPth _highlightPaths,
_highlightErrors = _highlightErrors
}

data HighlightBuilder :: Effect where
HighlightItem :: SemanticItem -> HighlightBuilder m ()
HighlightNockOp :: WithLoc NockOp -> HighlightBuilder m ()
HighlightPath :: WithLoc Nockma.Path -> HighlightBuilder m ()

makeSem ''HighlightBuilder

ignoreHighlightBuilder :: Sem (HighlightBuilder ': r) a -> Sem r a
ignoreHighlightBuilder = interpret $ \case
HighlightItem {} -> return ()
HighlightNockOp {} -> return ()
HighlightPath {} -> return ()

execHighlightBuilder :: Sem (HighlightBuilder ': r) a -> Sem r (HighlightInput)
execHighlightBuilder = fmap fst . runHighlightBuilder
Expand All @@ -46,3 +52,4 @@ runHighlightBuilder :: Sem (HighlightBuilder ': r) a -> Sem r (HighlightInput, a
runHighlightBuilder = reinterpret (runState emptyHighlightInput) $ \case
HighlightItem i -> modify (over highlightSemanticItems (i :))
HighlightNockOp i -> modify (over highlightNockOps (i :))
HighlightPath i -> modify (over highlightPaths (i :))
11 changes: 11 additions & 0 deletions src/Juvix/Compiler/Nockma/Language/Path.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Juvix.Compiler.Nockma.Language.Path where

import Juvix.Data.CodeAnn
import Juvix.Prelude hiding (Atom, Path)
import Prelude (show)

Expand Down Expand Up @@ -56,3 +57,13 @@ instance Semigroup EncodedPath where

instance Monoid EncodedPath where
mempty = encodePath []

instance PrettyCodeAnn Path where
ppCodeAnn = \case
[] -> annotate (AnnKind KNameInductive) "S"
ds -> mconcatMap ppCodeAnn ds

instance PrettyCodeAnn Direction where
ppCodeAnn d = annotate (AnnKind KNameInductive) $ case d of
L -> "L"
R -> "R"
9 changes: 2 additions & 7 deletions src/Juvix/Compiler/Nockma/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ instance PrettyCode Natural where
ppCode = return . pretty

instance PrettyCode Path where
ppCode = \case
[] -> return "S"
ds -> mconcatMapM ppCode ds
ppCode = return . ppCodeAnn

instance PrettyCode Direction where
ppCode =
return . \case
L -> annotate (AnnKind KNameAxiom) "L"
R -> annotate AnnKeyword "R"
ppCode = return . ppCodeAnn

instance PrettyCode NockOp where
ppCode =
Expand Down
12 changes: 9 additions & 3 deletions src/Juvix/Compiler/Nockma/Translation/FromSource/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ direction :: Parser Direction
direction = choice [directionSymbol (show lr) $> lr | lr <- allElements :: [Direction]]

pPath :: Parser Path
pPath =
directionSymbol "S" $> []
<|> NonEmpty.toList <$> some direction
pPath = do
p <-
withLoc $
choice
[ directionSymbol "S" $> [],
NonEmpty.toList <$> some direction
]
lift (highlightPath p)
return (p ^. withLocParam)

atomNat :: Maybe Tag -> Parser (Atom Natural)
atomNat mtag = do
Expand Down
6 changes: 5 additions & 1 deletion src/Juvix/Emacs/Render.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Juvix.Emacs.Render (renderEmacs, nameKindFace) where
module Juvix.Emacs.Render
( renderEmacs,
nameKindFace,
)
where

import Data.Text qualified as Text
import Juvix.Data.CodeAnn
Expand Down

0 comments on commit d07f45e

Please sign in to comment.