s-cargot 0.1.4.0 → 0.1.5.0
raw patch · 4 files changed
+46/−28 lines, 4 filesdep ~textPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: text
API changes (from Hackage documentation)
+ Data.SCargot.Print: instance GHC.Show.Show Data.SCargot.Print.Intermediate
+ Data.SCargot.Repr.Basic: pattern (:::) :: SExpr a -> SExpr a -> SExpr a
+ Data.SCargot.Repr.Basic: pattern A :: a -> SExpr a
+ Data.SCargot.Repr.Basic: pattern DL :: [SExpr a] -> a -> SExpr a
+ Data.SCargot.Repr.Basic: pattern L :: [SExpr a] -> SExpr a
+ Data.SCargot.Repr.Basic: pattern Nil :: SExpr a
+ Data.SCargot.Repr.Rich: pattern (:::) :: RichSExpr a -> RichSExpr a -> RichSExpr a
+ Data.SCargot.Repr.Rich: pattern A :: a -> RichSExpr a
+ Data.SCargot.Repr.Rich: pattern DL :: [RichSExpr a] -> a -> RichSExpr a
+ Data.SCargot.Repr.Rich: pattern L :: [RichSExpr a] -> RichSExpr a
+ Data.SCargot.Repr.Rich: pattern Nil :: RichSExpr a
+ Data.SCargot.Repr.WellFormed: pattern (:::) :: WellFormedSExpr a -> WellFormedSExpr a -> WellFormedSExpr a
+ Data.SCargot.Repr.WellFormed: pattern A :: t -> WellFormedSExpr t
+ Data.SCargot.Repr.WellFormed: pattern L :: [WellFormedSExpr t] -> WellFormedSExpr t
+ Data.SCargot.Repr.WellFormed: pattern Nil :: WellFormedSExpr t
- Data.SCargot.Repr: SCons :: (SExpr atom) -> (SExpr atom) -> SExpr atom
+ Data.SCargot.Repr: SCons :: SExpr atom -> SExpr atom -> SExpr atom
- Data.SCargot.Repr.Basic: SCons :: (SExpr atom) -> (SExpr atom) -> SExpr atom
+ Data.SCargot.Repr.Basic: SCons :: SExpr atom -> SExpr atom -> SExpr atom
Files
- CHANGELOG.md +7/−0
- Data/SCargot/Print.hs +32/−22
- README.md +1/−1
- s-cargot.cabal +6/−5
CHANGELOG.md view
@@ -1,3 +1,10 @@+v0.1.5.0+=======++Fixes:++* Bumped the `text` version to allow GHC 9.4 compatibility.+ v0.1.4.0 =======
Data/SCargot/Print.hs view
@@ -145,11 +145,12 @@ -- final improper element (if it exists) | IEmpty -- ^ An empty list+ deriving Show sizeOf :: Intermediate -> Size sizeOf IEmpty = Size 2 2 sizeOf (IAtom t) = Size len len where len = T.length t-sizeOf (IList _ s _ _ _) = s+sizeOf (IList _ (Size n m) _ _ _) = Size (n + 2) (m + 2) concatSize :: Size -> Size -> Size concatSize l r = Size@@ -194,7 +195,7 @@ -- s-expressions, then we might as well consider it flat and let -- it take the whole line | Just strings <- T.traverse ppBasic (initial Seq.<| values) =- Seq.singleton (B.fromString "(" <> buildUnwords strings <> pTail rest)+ Seq.singleton (B.singleton '(' <> buildUnwords strings <> pTail rest) -- it's not "flat", so we might want to swing after the first thing | Swing <- iv =@@ -206,7 +207,7 @@ -- ...or after several things | SwingAfter n <- iv = let (hs, xs) = Seq.splitAt n (initial Seq.<| values)- hd = B.fromString "(" <> buildUnwords (F.foldMap go hs)+ hd = B.singleton '(' <> buildUnwords (F.foldMap go hs) butLast = hd Seq.<| fmap doIndent (F.foldMap go xs) in handleTail rest butLast @@ -229,7 +230,7 @@ -- with spaces and everything else gets indended the -- forementioned length y Seq.:< ys ->- let hd = B.fromString "(" <> buildUnwords (F.foldMap go (Seq.fromList [initial, y]))+ let hd = B.singleton '(' <> buildUnwords (F.foldMap go (Seq.fromList [initial, y])) butLast = hd Seq.<| fmap (doIndentOf (fromIntegral len)) (F.foldMap go ys) in handleTail rest butLast @@ -242,25 +243,25 @@ insertParen :: Seq.Seq B.Builder -> Seq.Seq B.Builder insertParen s = case Seq.viewl s of Seq.EmptyL -> s- x Seq.:< xs -> (B.fromString "(" <> x) Seq.<| xs+ x Seq.:< xs -> (B.singleton '(' <> x) Seq.<| xs handleTail :: Maybe Text -> Seq.Seq B.Builder -> Seq.Seq B.Builder handleTail Nothing = insertCloseParen handleTail (Just t) =- (Seq.|> (B.fromString " . " <> B.fromText t <> B.fromString ")"))+ (Seq.|> (B.fromString " . " <> B.fromText t <> B.singleton ')')) insertCloseParen :: Seq.Seq B.Builder -> Seq.Seq B.Builder insertCloseParen s = case Seq.viewr s of- Seq.EmptyR -> Seq.singleton (B.fromString ")")- xs Seq.:> x -> xs Seq.|> (x <> B.fromString ")")+ Seq.EmptyR -> Seq.singleton (B.singleton ')')+ xs Seq.:> x -> xs Seq.|> (x <> B.singleton ')') buildUnwords sq = case Seq.viewl sq of Seq.EmptyL -> mempty- t Seq.:< ts -> t <> F.foldMap (\ x -> B.fromString " " <> x) ts+ t Seq.:< ts -> t <> F.foldMap (\ x -> B.singleton ' ' <> x) ts - pTail Nothing = B.fromString ")"- pTail (Just t) = B.fromString " . " <> B.fromText t <> B.fromString ")"+ pTail Nothing = B.singleton ')'+ pTail (Just t) = B.fromString " . " <> B.fromText t <> B.singleton ')' ppBasic (IAtom t) = Just (B.fromText t) ppBasic (IEmpty) = Just (B.fromString "()")@@ -324,9 +325,13 @@ setIndentStrategy st pr = pr { swingIndent = st } +spaceDot :: B.Builder+spaceDot = B.singleton ' ' <> B.singleton '.' <> B.singleton ' '+ -- Indents a line by n spaces indent :: Int -> B.Builder -> B.Builder-indent n ts = B.fromText (T.replicate n " ") <> ts+indent n ts =+ mconcat [ B.singleton ' ' | _ <- [1..n]] <> ts -- Sort of like 'unlines' but without the trailing newline@@ -344,7 +349,7 @@ Seq.EmptyL -> "" t Seq.:< ts | F.null ts -> t- | otherwise -> t <> " " <> joinLinesS ts+ | otherwise -> t <> " " <> unwordsS ts -- Indents every line n spaces, and adds a newline to the beginning@@ -352,7 +357,6 @@ indentAllS :: Int -> Seq.Seq B.Builder -> B.Builder indentAllS n = ("\n" <>) . joinLinesS . fmap (indent n) - -- Indents every line but the first by some amount -- used in aligned indents indentSubsequentS :: Int -> Seq.Seq B.Builder -> B.Builder@@ -386,7 +390,7 @@ pp ind (IList i sz h values end) = -- we always are going to have a head, a (possibly empty) body, -- and a (possibly empty) tail in our list formats- B.fromString "(" <> hd <> body <> tl <> B.fromString ")"+ B.singleton '(' <> hd <> body <> tl <> B.singleton ')' where -- the tail is either nothing, or the final dotted pair tl = case end of@@ -416,10 +420,10 @@ | length values == 0 = mempty -- if we can't fit the whole next s-expression on the same -- line, then we use the indented form- | sizeSum sz + ind > maxAmt = B.fromString " " <> indented+ | sizeSum sz + ind > maxAmt = B.singleton ' ' <> indented | otherwise = -- otherwise we print the whole thing on one line!- B.fromString " " <> unwordsS (fmap (pp (ind + 1)) values)+ B.singleton ' ' <> unwordsS (fmap (pp (ind + 1)) values) -- if we don't indent anything, then we can ignore a bunch of the@@ -428,36 +432,42 @@ flatPrintSExpr = B.toLazyText . pHead where pHead (SCons x xs) =- B.fromString "(" <> pHead x <> pTail xs+ B.singleton '(' <> pHead x <> pTail xs pHead (SAtom t) = B.fromText t pHead SNil =- B.fromString "()"+ B.singleton '(' <> B.singleton ')' pTail (SCons x xs) =- B.fromString " " <> pHead x <> pTail xs+ B.singleton ' ' <> pHead x <> pTail xs pTail (SAtom t) =- B.fromString " . " <> B.fromText t <> B.fromString ")"+ spaceDot <>+ B.fromText t <>+ B.singleton ')' pTail SNil =- B.fromString ")"+ B.singleton ')' + -- | Turn a single s-expression into a string according to a given -- 'SExprPrinter'. encodeOne :: SExprPrinter atom carrier -> carrier -> Text encodeOne s@(SExprPrinter { .. }) = TL.toStrict . prettyPrintSExpr (s { fromCarrier = id }) . fromCarrier + -- | Turn a list of s-expressions into a single string according to -- a given 'SExprPrinter'. encode :: SExprPrinter atom carrier -> [carrier] -> Text encode spec = T.intercalate "\n\n" . map (encodeOne spec) + -- | Turn a single s-expression into a lazy 'Text' according to a given -- 'SExprPrinter'. encodeOneLazy :: SExprPrinter atom carrier -> carrier -> TL.Text encodeOneLazy s@(SExprPrinter { .. }) = prettyPrintSExpr (s { fromCarrier = id }) . fromCarrier+ -- | Turn a list of s-expressions into a lazy 'Text' according to -- a given 'SExprPrinter'.
README.md view
@@ -1,4 +1,4 @@-[](https://hackage.haskell.org/package/s-cargot)+[](https://hackage.haskell.org/package/s-cargot)  S-Cargot is a library for parsing and emitting S-expressions, designed to be flexible, customizable, and extensible. Different uses of S-expressions often understand subtly different variations on what an S-expression is. The goal of S-Cargot is to create several reusable components that can be repurposed to nearly any S-expression variant.
s-cargot.cabal view
@@ -1,5 +1,5 @@ name: s-cargot-version: 0.1.4.0+version: 0.1.5.0 synopsis: A flexible, extensible s-expression library. homepage: https://github.com/aisamanra/s-cargot description: S-Cargot is a library for working with s-expressions in@@ -22,6 +22,7 @@ extra-source-files: README.md, CHANGELOG.md, test/*.sexp+tested-with: GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.4, GHC == 9.4.2 source-repository head type: git@@ -47,7 +48,7 @@ Data.SCargot.Language.HaskLike build-depends: base >=4.7 && <5, parsec >=3.1 && <4,- text >=1.2 && <2,+ text >=1.2 && <3, containers >=0.5 && <1 default-language: Haskell2010 default-extensions: CPP@@ -63,7 +64,7 @@ containers >=0.5 && <1, parsec >=3.1 && <4, s-cargot ,- text >=1.2 && <2+ text >=1.2 && <3 default-language: Haskell2010 ghc-options: -threaded -rtsopts -with-rtsopts=-N @@ -77,7 +78,7 @@ base >=4.7 && <5, parsec >=3.1 && <4, QuickCheck >=2.8 && <3,- text >=1.2 && <2+ text >=1.2 && <3 test-suite s-cargot-printparse@@ -89,4 +90,4 @@ base >=4.7 && <5, parsec >=3.1 && <4, HUnit >=1.6 && <1.7,- text >=1.2 && <2+ text >=1.2 && <3