From 590ee7e964641a3ed5fa75e49245eaa1f078ad27 Mon Sep 17 00:00:00 2001 From: anikarni Date: Fri, 26 Aug 2016 16:49:19 -0300 Subject: [PATCH 1/8] Cria aplicacao stack --- LICENSE | 30 ++++++++++++++++++++++++ Setup.hs | 2 ++ app/Main.hs | 6 +++++ edioma.cabal | 41 ++++++++++++++++++++++++++++++++ src/Lib.hs | 6 +++++ stack.yaml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/Spec.hs | 2 ++ 7 files changed, 153 insertions(+) create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 app/Main.hs create mode 100644 edioma.cabal create mode 100644 src/Lib.hs create mode 100644 stack.yaml create mode 100644 test/Spec.hs diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fc03544 --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +Copyright Author name here (c) 2016 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Author name here nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..de1c1ab --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = someFunc diff --git a/edioma.cabal b/edioma.cabal new file mode 100644 index 0000000..4c41071 --- /dev/null +++ b/edioma.cabal @@ -0,0 +1,41 @@ +name: edioma +version: 0.1.0.0 +synopsis: Initial project template from stack +description: Please see README.md +homepage: https://github.com/githubuser/edioma#readme +license: BSD3 +license-file: LICENSE +author: Author name here +maintainer: example@example.com +copyright: 2016 Author name here +category: Web +build-type: Simple +-- extra-source-files: +cabal-version: >=1.10 + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base >= 4.7 && < 5 + default-language: Haskell2010 + +executable edioma-exe + hs-source-dirs: app + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: base + , edioma + default-language: Haskell2010 + +test-suite edioma-test + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Spec.hs + build-depends: base + , edioma + ghc-options: -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 + +source-repository head + type: git + location: https://github.com/githubuser/edioma diff --git a/src/Lib.hs b/src/Lib.hs new file mode 100644 index 0000000..d36ff27 --- /dev/null +++ b/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..fd93e18 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,66 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# http://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# resolver: ghcjs-0.1.0_ghc-7.10.2 +# resolver: +# name: custom-snapshot +# location: "./custom-snapshot.yaml" +resolver: lts-6.13 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# - location: +# git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# extra-dep: true +# subdirs: +# - auto-update +# - wai +# +# A package marked 'extra-dep: true' will only be built if demanded by a +# non-dependency (i.e. a user package), and its test suites and benchmarks +# will not be run. This is useful for tweaking upstream packages. +packages: +- '.' +# Dependency packages to be pulled from upstream that are not in the resolver +# (e.g., acme-missiles-0.3) +extra-deps: [] + +# Override default flag values for local packages and extra-deps +flags: {} + +# Extra package databases containing global packages +extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=1.1" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor \ No newline at end of file diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented" From 0b7c38108b8c4fe88abd820407401b504b07767e Mon Sep 17 00:00:00 2001 From: anikarni Date: Fri, 26 Aug 2016 18:16:17 -0300 Subject: [PATCH 2/8] Adiciona interpretador inicial com soma, menos, mult --- app/Main.hs | 2 +- edioma.cabal | 8 ++++++-- src/Edioma.hs | 20 ++++++++++++++++++++ src/Lib.hs | 6 +++--- test/EdiomaSpec.hs | 33 +++++++++++++++++++++++++++++++++ test/Spec.hs | 3 +-- 6 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 src/Edioma.hs create mode 100644 test/EdiomaSpec.hs diff --git a/app/Main.hs b/app/Main.hs index de1c1ab..07d5ae8 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -3,4 +3,4 @@ module Main where import Lib main :: IO () -main = someFunc +main = parse diff --git a/edioma.cabal b/edioma.cabal index 4c41071..1f261e4 100644 --- a/edioma.cabal +++ b/edioma.cabal @@ -2,7 +2,7 @@ name: edioma version: 0.1.0.0 synopsis: Initial project template from stack description: Please see README.md -homepage: https://github.com/githubuser/edioma#readme +homepage: https://github.com/ProjetoDora/edioma#readme license: BSD3 license-file: LICENSE author: Author name here @@ -16,6 +16,7 @@ cabal-version: >=1.10 library hs-source-dirs: src exposed-modules: Lib + , Edioma build-depends: base >= 4.7 && < 5 default-language: Haskell2010 @@ -33,9 +34,12 @@ test-suite edioma-test main-is: Spec.hs build-depends: base , edioma + , text + , hspec > 2 && < 3 + , QuickCheck >= 2.8 && < 2.9 ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 source-repository head type: git - location: https://github.com/githubuser/edioma + location: https://github.com/ProjetoDora/edioma diff --git a/src/Edioma.hs b/src/Edioma.hs new file mode 100644 index 0000000..99ada0e --- /dev/null +++ b/src/Edioma.hs @@ -0,0 +1,20 @@ +module Edioma where + +data Expr + = Soma Expr Expr + | Mult Expr Expr + | Menos Expr Expr + | Lit Int + deriving (Show, Read, Eq) + +eval :: Expr -> Expr +eval (Lit a) = Lit a +eval (Soma a b) = case (eval a, eval b) of + (Lit a', Lit b') -> Lit (a' + b') + _ -> error "Cannot happen" +eval (Mult a b) = case (eval a, eval b) of + (Lit a', Lit b') -> Lit (a' * b') + _ -> error "Cannot happen" +eval (Menos a b) = case (eval a, eval b) of + (Lit a', Lit b') -> Lit (a' - b') + _ -> error "Cannot happen" diff --git a/src/Lib.hs b/src/Lib.hs index d36ff27..b9d7a3f 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,6 +1,6 @@ module Lib - ( someFunc + ( parse ) where -someFunc :: IO () -someFunc = putStrLn "someFunc" +parse :: IO () +parse = putStrLn "someFunc" diff --git a/test/EdiomaSpec.hs b/test/EdiomaSpec.hs new file mode 100644 index 0000000..a3e3904 --- /dev/null +++ b/test/EdiomaSpec.hs @@ -0,0 +1,33 @@ +module EdiomaSpec where + +import Test.Hspec +import Test.QuickCheck + +import Edioma + +spec :: Spec +spec = describe "eval" $ do + let isLit (Lit _) = True + isLit _ = False + let isSoma (Soma _ _) = True + isSoma _ = False + + it "does not change literals" $ property $ \x + -> isLit x ==> eval x `shouldBe` x + + it "evaluates adition" $ do + eval (Soma (Lit 1) (Lit 5)) `shouldBe` Lit 6 + + it "evaluates subtraction" $ do + eval (Menos (Lit 1) (Lit 5)) `shouldBe` Lit (-4) + + it "evaluates multiplication" $ do + eval (Mult (Lit 1) (Lit 5)) `shouldBe` Lit 5 + +instance Arbitrary Expr where + arbitrary = frequency + [ (1, Soma <$> arbitrary <*> arbitrary) + , (1, Mult <$> arbitrary <*> arbitrary) + , (1, Menos <$> arbitrary <*> arbitrary) + , (10, Lit <$> arbitrary) + ] diff --git a/test/Spec.hs b/test/Spec.hs index cd4753f..a824f8c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,2 +1 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} From d169952f0a4139c0a2c4522abd48ca951014523a Mon Sep 17 00:00:00 2001 From: anikarni Date: Fri, 26 Aug 2016 18:18:20 -0300 Subject: [PATCH 3/8] Adiciona stack-work a gitignore --- .gitignore | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4d159c2..104d08b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ -/bower_components/ -/node_modules/ -/.pulp-cache/ -/output/ -/.psci* -/src/.webpack.js +node_modules/ +.stack-work/ From f5285e4f334f826fbb8177f33cf908b8bf904baa Mon Sep 17 00:00:00 2001 From: anikarni Date: Mon, 29 Aug 2016 10:10:01 -0300 Subject: [PATCH 4/8] Adiciona parsec e testes com quickcheck para expressoes --- .gitignore | 2 ++ app/Main.hs | 13 +++++++++++-- edioma.cabal | 1 + src/Edioma.hs | 2 +- src/Lib.hs | 18 +++++++++++++----- test/EdiomaSpec.hs | 14 ++++++-------- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 104d08b..a7c8b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules/ .stack-work/ +*.hs.swo +npm-debug.log diff --git a/app/Main.hs b/app/Main.hs index 07d5ae8..96a2f1f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,15 @@ module Main where -import Lib +import System.Environment + +import Lib (parse) + +readExpr :: String -> String +readExpr input = case parse input of + Left err -> "No match: " ++ show err + Right val -> "Found value" main :: IO () -main = parse +main = do + (expr:_) <- getArgs + putStrLn (readExpr expr) diff --git a/edioma.cabal b/edioma.cabal index 1f261e4..b4bc0eb 100644 --- a/edioma.cabal +++ b/edioma.cabal @@ -18,6 +18,7 @@ library exposed-modules: Lib , Edioma build-depends: base >= 4.7 && < 5 + , parsec default-language: Haskell2010 executable edioma-exe diff --git a/src/Edioma.hs b/src/Edioma.hs index 99ada0e..0fe8a3e 100644 --- a/src/Edioma.hs +++ b/src/Edioma.hs @@ -1,4 +1,4 @@ -module Edioma where +module Edioma (Expr(..), eval) where data Expr = Soma Expr Expr diff --git a/src/Lib.hs b/src/Lib.hs index b9d7a3f..35d8ff1 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,6 +1,14 @@ -module Lib - ( parse - ) where +module Lib (parse) where -parse :: IO () -parse = putStrLn "someFunc" +import Edioma (Expr(..)) + +{- symbol :: Parser Char -} +{- symbol = oneOf "[a-zA-z]" -} + +{- parse :: String -> Either -} +parse s = case parseExpr s of + Lit x -> Right x + _ -> Left "Não parseou!!" + +parseExpr :: String -> Expr +parseExpr a = Lit 2 diff --git a/test/EdiomaSpec.hs b/test/EdiomaSpec.hs index a3e3904..ce7ec4c 100644 --- a/test/EdiomaSpec.hs +++ b/test/EdiomaSpec.hs @@ -9,20 +9,18 @@ spec :: Spec spec = describe "eval" $ do let isLit (Lit _) = True isLit _ = False - let isSoma (Soma _ _) = True - isSoma _ = False it "does not change literals" $ property $ \x -> isLit x ==> eval x `shouldBe` x - it "evaluates adition" $ do - eval (Soma (Lit 1) (Lit 5)) `shouldBe` Lit 6 + it "evaluates adition for literals" $ property $ \x y + -> eval (Soma (Lit x) (Lit y)) `shouldBe` Lit (x + y) - it "evaluates subtraction" $ do - eval (Menos (Lit 1) (Lit 5)) `shouldBe` Lit (-4) + it "evaluates subtraction for literals" $ property $ \x y + -> eval (Menos (Lit x) (Lit y)) `shouldBe` Lit (x - y) - it "evaluates multiplication" $ do - eval (Mult (Lit 1) (Lit 5)) `shouldBe` Lit 5 + it "evaluates multiplication for literals" $ property $ \x y + -> eval (Mult (Lit x) (Lit y)) `shouldBe` Lit (x * y) instance Arbitrary Expr where arbitrary = frequency From e089e106c19824750caf4e9957c9702eb9225865 Mon Sep 17 00:00:00 2001 From: anikarni Date: Wed, 31 Aug 2016 20:01:54 -0300 Subject: [PATCH 5/8] Faz o parser funcionar --- app/Main.hs | 4 +--- src/Lib.hs | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 96a2f1f..62e6fac 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -5,9 +5,7 @@ import System.Environment import Lib (parse) readExpr :: String -> String -readExpr input = case parse input of - Left err -> "No match: " ++ show err - Right val -> "Found value" +readExpr input = parse input main :: IO () main = do diff --git a/src/Lib.hs b/src/Lib.hs index 35d8ff1..0e3f94f 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -1,14 +1,31 @@ -module Lib (parse) where +module Lib (Lib.parse) where -import Edioma (Expr(..)) +import Edioma (Expr(..), eval) +import Text.ParserCombinators.Parsec +import Data.Char (digitToInt) {- symbol :: Parser Char -} {- symbol = oneOf "[a-zA-z]" -} {- parse :: String -> Either -} -parse s = case parseExpr s of - Lit x -> Right x - _ -> Left "Não parseou!!" +parse s = case Text.ParserCombinators.Parsec.parse parseExpr "expression" s of + Left err -> "No match: " ++ show err + Right x -> show x -parseExpr :: String -> Expr -parseExpr a = Lit 2 +parseExpr :: Parser Expr +parseExpr = parseSoma <|> parseLit + +parseSoma :: Parser Expr +parseSoma = do + char '(' + x <- parseExpr + char '+' + y <- parseExpr + char ')' + return $ Soma x y + + +parseLit :: Parser Expr +parseLit = do + x <- digit + return $ Lit (digitToInt x) From e120ebc0a54c542f3706033583d8aac940d5aa87 Mon Sep 17 00:00:00 2001 From: anikarni Date: Wed, 31 Aug 2016 20:10:38 -0300 Subject: [PATCH 6/8] Adiciona parseamento para operacoes --- src/Lib.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Lib.hs b/src/Lib.hs index 0e3f94f..bb3783e 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -4,26 +4,28 @@ import Edioma (Expr(..), eval) import Text.ParserCombinators.Parsec import Data.Char (digitToInt) -{- symbol :: Parser Char -} -{- symbol = oneOf "[a-zA-z]" -} - {- parse :: String -> Either -} parse s = case Text.ParserCombinators.Parsec.parse parseExpr "expression" s of Left err -> "No match: " ++ show err Right x -> show x parseExpr :: Parser Expr -parseExpr = parseSoma <|> parseLit +parseExpr = parseOp + <|> parseLit + +operators = oneOf "+-*" -parseSoma :: Parser Expr -parseSoma = do +parseOp :: Parser Expr +parseOp = do char '(' x <- parseExpr - char '+' + op <- operators y <- parseExpr char ')' - return $ Soma x y - + return $ case op of + '+' -> Soma x y + '-' -> Menos x y + '*' -> Mult x y parseLit :: Parser Expr parseLit = do From bc7c2e484a8d2f2b9f542f594eb206cd002b669c Mon Sep 17 00:00:00 2001 From: anikarni Date: Wed, 31 Aug 2016 20:13:50 -0300 Subject: [PATCH 7/8] Evalua resultado do parser --- src/Lib.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lib.hs b/src/Lib.hs index bb3783e..84b4d95 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -7,7 +7,7 @@ import Data.Char (digitToInt) {- parse :: String -> Either -} parse s = case Text.ParserCombinators.Parsec.parse parseExpr "expression" s of Left err -> "No match: " ++ show err - Right x -> show x + Right x -> show (eval x) parseExpr :: Parser Expr parseExpr = parseOp From 43c77962810d6501b59b8a31c415e79f1d349a52 Mon Sep 17 00:00:00 2001 From: Anike Arni Date: Mon, 3 Oct 2016 15:57:47 -0300 Subject: [PATCH 8/8] =?UTF-8?q?Remove=20permissoes=20de=20uso=20at=C3=A9?= =?UTF-8?q?=20que=20algo=20seja=20definido=20em=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index fc03544..0000000 --- a/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ -Copyright Author name here (c) 2016 - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of Author name here nor the names of other - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file