packages feed

language-elm 0.1.0.1 → 0.1.0.2

raw patch · 3 files changed

+53/−111 lines, 3 filesdep ~hspecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hspec

API changes (from Hackage documentation)

Files

README.md view
@@ -10,83 +10,3 @@ ## Documentation [Documentation](https://hackage.haskell.org/package/language-elm) -<!---Import the libraries-```haskell-import Elm.Decleration-import Elm.Expression-import Elm.Import-import Elm.Program-import Elm.Type-```--Declare a program type-```haskell-program : Program-program =-    Program-        "Tuple"-        (Select-            [ Item "first"-            , Item "second"-            , Item "mapFirst"-            , Item "mapSecond"-            ])-        []-        [ Dec-            "first"-            (TApp [TTuple2 (tvar "a1") (tvar "a2"), tvar "a1"])-            [Tuple2 (var "x") (Under)]-            (var "x")-        , Dec-            "second"-            (TApp [TTuple2 (tvar "a1") (tvar "a2"), tvar "a2"])-            [Tuple2 (Under) (var "y")]-            (var "y")-        , Dec-            "mapFirst"-            (TApp-                [ TApp [tvar "a", tvar "b"]-                , TTuple2 (tvar "a") (tvar "a2")-                , TTuple2 (tvar "b") (tvar "a2")-                ])-            [var "func", Tuple2 (var "x") (var "y")]-            (Tuple2 (App "func" [var "x"]) (var "y"))-        , Dec-            "mapSecond"-            (TApp-                [ TApp [tvar "a", tvar "b"]-                , TTuple2 (tvar "a1") (tvar "a")-                , TTuple2 (tvar "a1") (tvar "b")-                ])-            [var "func", Tuple2 (var "x") (var "y")]-            (Tuple2 (var "x") (App "func" [var "y"]))-        ]-```--Then render the program--```haskell-output :: String-output = renderProgram program-```--Which results in the following output--```elm-module Tuple exposing (first, second, mapFirst, mapSecond)--first :: ((a1, a2)) -> a1-first (x, _) = x--second :: ((a1, a2)) -> a2-second (_, y) = y--mapFirst :: (a -> b) -> ((a, a2)) -> ((b, a2))-mapFirst func (x, y) = (func x, y)--mapSecond :: (a -> b) -> ((a1, a)) -> ((a1, b))-mapSecond func (x, y) = (x, func y)-```---->
language-elm.cabal view
@@ -1,5 +1,5 @@ name:               language-elm-version:            0.1.0.1+version:            0.1.0.2 synopsis:           Generate elm code description:        Generate elm code from an ast homepage:           https://github.com/eliaslfox/language-elm#readme@@ -31,7 +31,7 @@   build-depends:    base                      , language-elm                      , pretty >= 1.1.3 && < 1.2-                     , hspec >= 2.4.4 && < 2.5+                     , hspec >= 2.4.3 && < 2.5                      , mtl >= 2.2.1 && < 2.3                      , protolude >= 0.2 && < 0.3   ghc-options:      -threaded -rtsopts -with-rtsopts=-N
src/Elm.hs view
@@ -2,7 +2,6 @@ {-# OPTIONS_GHC -Wall -Werror #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE Trustworthy       #-}- module Elm     (     -- * Expressions@@ -51,19 +50,25 @@     -- * Generation     , renderModule     , render+    , genStr     )     where -import           Prelude         (error)-import           Protolude       hiding (bool, list)+-- Please note that doctest is very specefic about spacing+-- so chaning spacing in the examples may break tests+import           Prelude              (error)+import           Protolude            hiding (bool, list) +import           Control.Monad.Writer import           Data.String+import           Elm.Classes import qualified Elm.Decleration import qualified Elm.Expression-import           Elm.GenError    (GenError (WarningList))+import           Elm.GenError         (GenError (WarningList)) import qualified Elm.Import import qualified Elm.Program-import qualified Elm.Type        (TypeDec (..))+import qualified Elm.Type             (TypeDec (..))+import qualified Text.PrettyPrint  type Expr = Elm.Expression.Expr type Type = Elm.Type.TypeDec@@ -99,7 +104,7 @@  -- | Function application ----- >>> render (app [var "a", var "b", var "c"])+-- >>> genStr (app [var "a", var "b", var "c"]) -- "a b c" app :: [Expr] -> Expr app = Elm.Expression.App@@ -110,30 +115,36 @@  -- | Apply an operator to two sub expressions ----- >>> render (Op "+" (Int 5) (Int 6))+-- >>> genStr (op "+" (int 5) (int 6)) -- "5 + 6" op :: String -> Expr -> Expr -> Expr op = Elm.Expression.Op  -- | A let...in block ----- >>> render (let_ (var "a") [(var "a", Int 5)])--- "let---      a = 5---  in---      a"+-- >>> putStrLn $ genStr (let_ (var "a") [(var "a", int 5)])+-- let+--     a = 5+-- in+--     a let_ :: Expr -> [(Expr, Expr)] -> Expr let_ = Elm.Expression.Let  -- | A case...of block ----- >>> render (case_ (var "m") [(App [var "Just", var "x"], var "x"), (var "Nothing", var "default")]--- "case m of---      Just x ->---          x+-- >>> :{+--  putStrLn $ genStr+--      (case_ (var "m")+--          [ (app [var "Just", var "x"], var "x")+--          , (var "Nothing", var "default")+--          ])+-- :}+-- case m of+--     Just x ->+--         x -- <BLANKLINE>---      Nothing ->---          default"+--     Nothing ->+--         default case_ :: Expr -> [(Expr, Expr)] -> Expr case_ = Elm.Expression.Case @@ -147,10 +158,10 @@  -- | A type or type variable ----- >>> render (tvar "Nothing")+-- >>> genStr (tvar "Nothing") -- "Nothing" ----- >>> render (tvar "a")+-- >>> genStr (tvar "a") -- "a" -- tvar :: String -> Type@@ -158,7 +169,7 @@  -- | A type with a single paramater ----- >>> render (tparam "Just" (tvar "a"))+-- >>> genStr (tparam "Just" (tvar "a")) -- "Just a" -- tparam :: String -> Type -> Type@@ -166,7 +177,7 @@  -- | A type with multiple paramaters ----- >>> render (tparams "Result" [tvar "String", tvar "Int"])+-- >>> genStr (tparams "Result" [tvar "String", tvar "Int"]) -- "Result String Int" -- tparams :: String -> [Type] -> Type@@ -174,7 +185,7 @@  -- | A zero item tuple type ----- >>> render tunit+-- >>> genStr tunit -- "()" -- tunit :: Type@@ -182,16 +193,16 @@  -- | A multiple item tuple ----- >>> render (ttuple [tvar "a", tvar "b"])--- "( a, b )"+-- >>> genStr (ttuple [tvar "a", tvar "b"])+-- "(a, b)" -- ttuple :: [Type] -> Type ttuple = Elm.Type.TTuple  -- | Type application ----- >>> render (tapp [tvar "a", tvar "b", tvar "c"])--- "[a, b, c]"+-- >>> genStr (tapp [tvar "a", tvar "b", tvar "c"])+-- "a -> b -> c" -- tapp :: [Type] -> Type tapp = Elm.Type.TApp@@ -199,7 +210,7 @@  -- | A record type ----- >>> render (trecord [("a", tvar "Int"), ("b", tvar "String")]+-- >>> genStr (trecord [("a", tvar "Int"), ("b", tvar "String")]) -- "{ a : Int, b : String }" -- trecord :: [(String, Type)] -> Type@@ -207,7 +218,7 @@  -- | A paramaterized record type ----- >>> render (trecord "a" [("b", tvar "Int")])+-- >>> genStr (trecordParam "a" [("b", tvar "Int")]) -- "{ a | b : Int }" -- trecordParam :: String -> [(String, Type)] -> Type@@ -291,5 +302,16 @@     in         if err == WarningList [] then             str+        else+            error . show $ err+++genStr :: (Generate a) => a -> String+genStr g =+    let+        (str, err) = runWriter . generate $ g+    in+        if err == WarningList [] then+            Text.PrettyPrint.render str         else             error . show $ err