wip: printer
build / build (push) Successful in 1m33s

This commit is contained in:
2026-08-21 15:01:31 -06:00
parent 6ff01a8607
commit b234a52d4b
40 changed files with 341 additions and 221 deletions
+88 -11
View File
@@ -12,6 +12,23 @@ module Gyehoek.Sexp.Syntax
, Cofree((:<))
, Fix(..)
, Compound
, Indentation(..)
, Syn(..)
, pattern Simple
, pattern Compound
, pattern Labeled
, pattern LabelRef
, pattern Abbrev
, pattern Vector
, pattern DotList
, pattern Gyehoek.Sexp.Syntax.List
, adorn
, pattern Bytevector
, pattern Symbol
, pattern String
, pattern Character
, pattern Number
, pattern Boolean
) where
import Language.Haskell.TH.Syntax (Lift)
@@ -35,17 +52,17 @@ data DatumF a
deriving anyclass (NFData)
data Simple
= Boolean Bool
| Number Scientific
| Character Char
| String Text
| Symbol Text
| Bytevector ByteString
= SimpleBoolean Bool
| SimpleNumber Scientific
| SimpleCharacter Char
| SimpleString Text
| SimpleSymbol Text
| SimpleBytevector ByteString
deriving stock (Show, Eq, Data, Generic, Lift)
deriving anyclass (NFData)
data CompoundF a
= ListF (List a)
= ListF Indentation (List a)
| DotListF (NonEmpty a) a
| VectorF (List a)
| AbbrevF Prefix a
@@ -69,10 +86,70 @@ newtype Label = MkLabel Natural
deriving newtype (Eq, Ord, Show)
deriving anyclass (NFData)
deriveShow1 ''CompoundF
deriveShow1 ''DatumF
type Datum = Cofree DatumF Syn
type Compound = CompoundF Datum
data Indentation
= NSpecial Int
| Ordinary
deriving stock (Data, Eq, Generic, Show, Lift, Read)
deriving anyclass (NFData)
data Syn
= SynMacro
| SynBuiltin
| SynProcedure
| SynParen Int
| SynString
| SynConstant
| SynNone
deriving (Show, Read)
type Datum = Fix DatumF
type Compound = CompoundF Datum
deriveShow1 ''CompoundF
deriveShow1 ''DatumF
adorn :: Syn -> Datum -> Datum
adorn syn (_ :< d) = syn :< d
pattern Simple :: Simple -> Datum
pattern Simple a <- _ :< SimpleF a
where Simple a = SynNone :< SimpleF a
pattern Compound :: CompoundF Datum -> Datum
pattern Compound a <- _ :< CompoundF a
where Compound a = SynNone :< CompoundF a
pattern Labeled :: Label -> Datum -> Datum
pattern Labeled l a <- _ :< LabeledF l a
where Labeled l a = SynNone :< LabeledF l a
pattern LabelRef :: Label -> Datum
pattern LabelRef l <- _ :< LabelRefF l
where LabelRef l = SynNone :< LabelRefF l
pattern List :: List Datum -> Datum
pattern List a <- _ :< CompoundF (ListF _ a)
where List a = SynNone :< CompoundF (ListF Ordinary a)
pattern DotList :: NonEmpty Datum -> Datum -> Datum
pattern DotList xs x <- _ :< CompoundF (DotListF xs x)
where DotList xs x = SynNone :< CompoundF (DotListF xs x)
pattern Vector :: [Datum] -> Datum
pattern Vector xs <- _ :< CompoundF (VectorF xs)
where Vector xs = SynNone :< CompoundF (VectorF xs)
pattern Abbrev :: Prefix -> Datum -> Datum
pattern Abbrev p a <- _ :< CompoundF (AbbrevF p a)
where Abbrev p a = SynNone :< CompoundF (AbbrevF p a)
pattern Boolean a = Simple (SimpleBoolean a)
pattern Number a = Simple (SimpleNumber a)
pattern Character a = Simple (SimpleCharacter a)
pattern String a = Simple (SimpleString a)
pattern Symbol a = Simple (SimpleSymbol a)
pattern Bytevector a = Simple (SimpleBytevector a)