packages feed

hs2ats 0.3.0.3 → 0.3.0.4

raw patch · 6 files changed

+46/−8 lines, 6 filesdep ~language-atssetup-changedPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: language-ats

API changes (from Hackage documentation)

+ Language.ATS.Generate: Malformed :: String -> GenerateError

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# hs2ats++## 0.3.0.4++  * Allow newer `language-ats`
+ README.md view
@@ -0,0 +1,25 @@+# hs2ats++This is a tool to convert Haskell types to ATS types.++Example use:++```+hs2ats --src DataTypes.hs --target generated_types.sats+```++Note that `hs2ats` does not preserve strictness semantics.++## Installation++Install [cabal](https://www.haskell.org/cabal/download.html). Then:++```+cabal new-install hs2ats --symlink-bindir ~/.cabal/bin+```++or++```+cabal new-install hs2ats --alex-options='-g' --happy-options='-gcsa' --symlink-bindir ~/.cabal/bin+```
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
hs2ats.cabal view
@@ -1,12 +1,11 @@ cabal-version: 1.18 name: hs2ats-version: 0.3.0.3+version: 0.3.0.4 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2018 Vanessa McHale maintainer: vamchale@gmail.com author: Vanessa McHale-homepage: https://github.com/vmchale/hs2ats#readme synopsis: Create ATS types from Haskell types description:     This package enables scanning Haskell source files for data types and then generating [ATS](http://www.ats-lang.org/) types from them.@@ -15,6 +14,8 @@ extra-source-files:     test/data/*.hs     test/data/*.out+extra-doc-files: CHANGELOG.md+                 README.md  flag development     description:@@ -35,7 +36,7 @@     build-depends:         base >=4.7 && <5,         haskell-src-exts -any,-        language-ats >=1.0.0.0,+        language-ats >=1.5.0.0,         casing -any,         microlens -any,         ansi-wl-pprint -any,
src/Language/ATS/Generate.hs view
@@ -14,6 +14,7 @@ import           Data.Char                    (toUpper) import           Data.Either                  (lefts, rights) import           Data.Foldable+import qualified Data.List.NonEmpty           as NE import           Data.Maybe import           Language.ATS                 as ATS import           Language.ATS.Generate.Error@@ -93,7 +94,8 @@ conDeclToType (ConDecl _ n [])  = Right (toStringATS n, Nothing) conDeclToType (ConDecl _ n [t]) = (,) (toStringATS n) . Just <$> typeToType t conDeclToType (ConDecl _ n ts)  = (,) (toStringATS n) . Just . ATS.Tuple undefined <$> traverse typeToType ts-conDeclToType (RecDecl _ n fs)  = (,) (toStringATS n) . Just . AnonymousRecord undefined <$> traverse fieldDeclToType (reverse fs)+conDeclToType (RecDecl _ _ []) = malformed "conDeclToType"+conDeclToType (RecDecl _ n fs)  = (,) (toStringATS n) . Just . AnonymousRecord undefined <$> traverse fieldDeclToType (NE.fromList (reverse fs)) conDeclToType _                 = unsupported "conDeclToType"  toStringATS :: HS.Name a -> String@@ -129,9 +131,10 @@ -- TODO if it derives functor, use + asATSType :: Decl a -> ErrM (Declaration b) asATSType (TypeDecl _ dh t) = ViewTypeDef undefined <$> (fst <$> asATSName dh) <*> (pruneATSNils . snd <$> asATSName dh) <*> typeToType t+asATSType (DataDecl _ DataType{} _ _ [] _)    = malformed "asATSType" asATSType (DataDecl _ NewType{} _ dh [qcd] _)  = ViewTypeDef undefined <$> (fst <$> asATSName dh) <*> (pruneATSNils . snd <$> asATSName dh) <*> qualConDeclToType qcd asATSType (DataDecl _ DataType{} _ dh [qcd] _) = ViewTypeDef undefined <$> (fst <$> asATSName dh) <*> (pruneATSNils . snd <$> asATSName dh) <*> qualConDeclToType qcd-asATSType (DataDecl _ DataType{} _ dh qcds _)  = SumViewType <$> (fst <$> asATSName dh) <*> (pruneATSNils . snd <$> asATSName dh) <*> traverse qualConDeclToLeaf (reverse qcds)+asATSType (DataDecl _ DataType{} _ dh qcds _)  = SumViewType <$> (fst <$> asATSName dh) <*> (pruneATSNils . snd <$> asATSName dh) <*> traverse qualConDeclToLeaf (NE.fromList (reverse qcds)) asATSType _                                    = unsupported "asATSType"  -- TODO GDataDecl@@ -146,7 +149,7 @@  modulePrint :: Module a -> (String, [GenerateError]) modulePrint = g . fmap asATSType . filterModule-    where g = (h . ATS . reverse . rights) &&& lefts+    where g = (h . ATS . rights) &&& lefts           h :: ATS AlexPosn -> String           h = printATS 
src/Language/ATS/Generate/Error.hs view
@@ -12,6 +12,7 @@                                    -- * Helper functions                                    , unsupported                                    , syntaxError+                                   , malformed                                    ) where  import           Control.Composition@@ -34,12 +35,17 @@ unsupported :: String -> ErrM a unsupported = Left . Unsupported +malformed :: String -> ErrM a+malformed = Left . Malformed+ data GenerateError = Unsupported String                    | HaskellSyntaxError SrcLoc String                    | Internal String+                   | Malformed String                    deriving (Eq, Show, Generic, NFData)  instance Pretty GenerateError where     pretty (Unsupported s)            = dullyellow "Warning:" <+> "skipping unsupported construct" <$$> indent 2 (squotes (text s)) <> linebreak     pretty (HaskellSyntaxError loc s) = dullred "Error:" <+> "failed to parse" <+> text (show loc) <> colon <$$> indent 2 (text s) <> linebreak     pretty (Internal s)               = dullred "Error:" <+> "internal error: " <$$> indent 2 (text s) <> linebreak+    pretty (Malformed s)              = dullred "Error:" <+> "incompatible type" <$$> indent 2 (squotes (text s)) <> linebreak