print begin
build / build (push) Successful in 1m13s

This commit is contained in:
2026-08-21 16:25:04 -06:00
parent 66386cda64
commit c340ede84f
11 changed files with 76 additions and 13 deletions
+12 -6
View File
@@ -13,7 +13,7 @@ import Gyehoek.Sexp.Read (rd)
import Data.Foldable (traverse_)
import qualified Prettyprinter.Render.Terminal as ANSI
import System.IO (stdout)
import Prettyprinter.Render.Terminal (Color(..), color, italicized, AnsiStyle)
import Prettyprinter.Render.Terminal (Color(..), color, italicized, AnsiStyle, bold)
printDatum :: Datum -> Text
@@ -36,10 +36,16 @@ prettyDatum depth = \case
syn :< CompoundF compound -> case compound of
ListF indent xs ->
case indent of
NSpecial 1 | special:body <- xs
-> pparen depth $
nest 2 $ prettyDatum (depth+1) special
<+> vsep (prettyDatum (depth+1) <$> body)
NSpecial n | keyword:args <- xs ->
let (specialArgs,body) = splitAt n args
in pparen depth . nest 2 . vsep $
[ group . nest 2 . hcat $
[ prettyDatum (depth+1) keyword
, if null specialArgs then mempty else softline
, hsep $ prettyDatum (depth+1) <$> specialArgs
]
, vsep $ prettyDatum (depth+1) <$> body
]
Ordinary; NSpecial _ -> pparen depth $
group . align . vsep $
prettyDatum (depth+1) <$> xs
@@ -68,7 +74,7 @@ putDoc = ANSI.renderIO stdout
highlight :: Syn -> AnsiStyle
highlight = \case
SynBuiltin -> color Magenta <> italicized
(SynBuiltin; SynMacro) -> color Magenta <> italicized <> bold
SynParen n -> color $ rainbow ^?! ix n
_ -> mempty
where
+17 -1
View File
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ApplicativeDo #-}
module Gyehoek.Sexp.Syntax
( DatumF(..)
, Simple(..)
@@ -22,7 +23,10 @@ module Gyehoek.Sexp.Syntax
, pattern Vector
, pattern DotList
, pattern Gyehoek.Sexp.Syntax.List
, syntax
, indentation
, adorn
, indentWith
, pattern Bytevector
, pattern Symbol
, pattern String
@@ -36,7 +40,7 @@ import Data.Scientific (Scientific)
import Data.ByteString (ByteString)
import Gyehoek.Prelude hiding ((:<), Simple)
import Text.Megaparsec.Pos (SourcePos(..))
import Control.Comonad.Cofree (Cofree((:<)))
import Control.Comonad.Cofree (Cofree((:<)), _extract)
import Data.Fix (Fix (..))
import Data.Functor.Foldable
import Text.Show.Deriving (deriveShow1)
@@ -112,9 +116,21 @@ data Syn
deriveShow1 ''CompoundF
deriveShow1 ''DatumF
syntax :: Lens' Datum Syn
syntax = _extract
indentation :: Traversal' Datum Indentation
indentation k (syn :< CompoundF (ListF ind xs)) = do
ind' <- k ind
pure $ syn :< CompoundF (ListF ind' xs)
indentation k a = pure a
adorn :: Syn -> Datum -> Datum
adorn syn (_ :< d) = syn :< d
indentWith :: Indentation -> Datum -> Datum
indentWith = set indentation
pattern Simple :: Simple -> Datum
pattern Simple a <- _ :< SimpleF a
where Simple a = SynNone :< SimpleF a