commit b45e0a3717632f7cfab0e2ef983f87dd77e74abf Author: ryuga4 Date: Fri May 3 17:23:30 2019 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..113031c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.stack-work/ +parser-sandbox.cabal +*~ \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..4f4f0c7 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,3 @@ +# Changelog for parser-sandbox + +## Unreleased changes diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..102126f --- /dev/null +++ b/LICENSE @@ -0,0 +1,30 @@ +Copyright Author name here (c) 2019 + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f9d8890 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# parser-sandbox 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..9a696da --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = go diff --git a/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/Paths_parser_sandbox.hs b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/Paths_parser_sandbox.hs new file mode 100644 index 0000000..b47563d --- /dev/null +++ b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/Paths_parser_sandbox.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE NoRebindableSyntax #-} +{-# OPTIONS_GHC -fno-warn-missing-import-lists #-} +module Paths_parser_sandbox ( + version, + getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, + getDataFileName, getSysconfDir + ) where + +import qualified Control.Exception as Exception +import Data.Version (Version(..)) +import System.Environment (getEnv) +import Prelude + +#if defined(VERSION_base) + +#if MIN_VERSION_base(4,0,0) +catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a +#else +catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a +#endif + +#else +catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a +#endif +catchIO = Exception.catch + +version :: Version +version = Version [0,1,0,0] [] +bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath + +bindir = "/home/me/.cabal/bin" +libdir = "/home/me/.cabal/lib/x86_64-linux-ghc-8.0.2/parser-sandbox-0.1.0.0-inplace" +dynlibdir = "/home/me/.cabal/lib/x86_64-linux-ghc-8.0.2" +datadir = "/home/me/.cabal/share/x86_64-linux-ghc-8.0.2/parser-sandbox-0.1.0.0" +libexecdir = "/home/me/.cabal/libexec/x86_64-linux-ghc-8.0.2/parser-sandbox-0.1.0.0" +sysconfdir = "/home/me/.cabal/etc" + +getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath +getBinDir = catchIO (getEnv "parser_sandbox_bindir") (\_ -> return bindir) +getLibDir = catchIO (getEnv "parser_sandbox_libdir") (\_ -> return libdir) +getDynLibDir = catchIO (getEnv "parser_sandbox_dynlibdir") (\_ -> return dynlibdir) +getDataDir = catchIO (getEnv "parser_sandbox_datadir") (\_ -> return datadir) +getLibexecDir = catchIO (getEnv "parser_sandbox_libexecdir") (\_ -> return libexecdir) +getSysconfDir = catchIO (getEnv "parser_sandbox_sysconfdir") (\_ -> return sysconfdir) + +getDataFileName :: FilePath -> IO FilePath +getDataFileName name = do + dir <- getDataDir + return (dir ++ "/" ++ name) diff --git a/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/cabal_macros.h b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/cabal_macros.h new file mode 100644 index 0000000..7251af3 --- /dev/null +++ b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/build/autogen/cabal_macros.h @@ -0,0 +1,154 @@ +/* DO NOT EDIT: This file is automatically generated by Cabal */ + +/* package parser-sandbox-0.1.0.0 */ +#ifndef VERSION_parser_sandbox +#define VERSION_parser_sandbox "0.1.0.0" +#endif /* VERSION_parser_sandbox */ +#ifndef MIN_VERSION_parser_sandbox +#define MIN_VERSION_parser_sandbox(major1,major2,minor) (\ + (major1) < 0 || \ + (major1) == 0 && (major2) < 1 || \ + (major1) == 0 && (major2) == 1 && (minor) <= 0) +#endif /* MIN_VERSION_parser_sandbox */ + +/* package base-4.9.1.0 */ +#ifndef VERSION_base +#define VERSION_base "4.9.1.0" +#endif /* VERSION_base */ +#ifndef MIN_VERSION_base +#define MIN_VERSION_base(major1,major2,minor) (\ + (major1) < 4 || \ + (major1) == 4 && (major2) < 9 || \ + (major1) == 4 && (major2) == 9 && (minor) <= 1) +#endif /* MIN_VERSION_base */ + +/* tool cpphs-1.20.8 */ +#ifndef TOOL_VERSION_cpphs +#define TOOL_VERSION_cpphs "1.20.8" +#endif /* TOOL_VERSION_cpphs */ +#ifndef MIN_TOOL_VERSION_cpphs +#define MIN_TOOL_VERSION_cpphs(major1,major2,minor) (\ + (major1) < 1 || \ + (major1) == 1 && (major2) < 20 || \ + (major1) == 1 && (major2) == 20 && (minor) <= 8) +#endif /* MIN_TOOL_VERSION_cpphs */ + +/* tool gcc-7 */ +#ifndef TOOL_VERSION_gcc +#define TOOL_VERSION_gcc "7" +#endif /* TOOL_VERSION_gcc */ +#ifndef MIN_TOOL_VERSION_gcc +#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\ + (major1) < 7 || \ + (major1) == 7 && (major2) < 0 || \ + (major1) == 7 && (major2) == 0 && (minor) <= 0) +#endif /* MIN_TOOL_VERSION_gcc */ + +/* tool ghc-8.0.2 */ +#ifndef TOOL_VERSION_ghc +#define TOOL_VERSION_ghc "8.0.2" +#endif /* TOOL_VERSION_ghc */ +#ifndef MIN_TOOL_VERSION_ghc +#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\ + (major1) < 8 || \ + (major1) == 8 && (major2) < 0 || \ + (major1) == 8 && (major2) == 0 && (minor) <= 2) +#endif /* MIN_TOOL_VERSION_ghc */ + +/* tool ghc-pkg-8.0.2 */ +#ifndef TOOL_VERSION_ghc_pkg +#define TOOL_VERSION_ghc_pkg "8.0.2" +#endif /* TOOL_VERSION_ghc_pkg */ +#ifndef MIN_TOOL_VERSION_ghc_pkg +#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\ + (major1) < 8 || \ + (major1) == 8 && (major2) < 0 || \ + (major1) == 8 && (major2) == 0 && (minor) <= 2) +#endif /* MIN_TOOL_VERSION_ghc_pkg */ + +/* tool haddock-2.17.3 */ +#ifndef TOOL_VERSION_haddock +#define TOOL_VERSION_haddock "2.17.3" +#endif /* TOOL_VERSION_haddock */ +#ifndef MIN_TOOL_VERSION_haddock +#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\ + (major1) < 2 || \ + (major1) == 2 && (major2) < 17 || \ + (major1) == 2 && (major2) == 17 && (minor) <= 3) +#endif /* MIN_TOOL_VERSION_haddock */ + +/* tool hpc-0.67 */ +#ifndef TOOL_VERSION_hpc +#define TOOL_VERSION_hpc "0.67" +#endif /* TOOL_VERSION_hpc */ +#ifndef MIN_TOOL_VERSION_hpc +#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\ + (major1) < 0 || \ + (major1) == 0 && (major2) < 67 || \ + (major1) == 0 && (major2) == 67 && (minor) <= 0) +#endif /* MIN_TOOL_VERSION_hpc */ + +/* tool hsc2hs-0.68.1 */ +#ifndef TOOL_VERSION_hsc2hs +#define TOOL_VERSION_hsc2hs "0.68.1" +#endif /* TOOL_VERSION_hsc2hs */ +#ifndef MIN_TOOL_VERSION_hsc2hs +#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\ + (major1) < 0 || \ + (major1) == 0 && (major2) < 68 || \ + (major1) == 0 && (major2) == 68 && (minor) <= 1) +#endif /* MIN_TOOL_VERSION_hsc2hs */ + +/* tool hscolour-1.24 */ +#ifndef TOOL_VERSION_hscolour +#define TOOL_VERSION_hscolour "1.24" +#endif /* TOOL_VERSION_hscolour */ +#ifndef MIN_TOOL_VERSION_hscolour +#define MIN_TOOL_VERSION_hscolour(major1,major2,minor) (\ + (major1) < 1 || \ + (major1) == 1 && (major2) < 24 || \ + (major1) == 1 && (major2) == 24 && (minor) <= 0) +#endif /* MIN_TOOL_VERSION_hscolour */ + +/* tool pkg-config-0.29.1 */ +#ifndef TOOL_VERSION_pkg_config +#define TOOL_VERSION_pkg_config "0.29.1" +#endif /* TOOL_VERSION_pkg_config */ +#ifndef MIN_TOOL_VERSION_pkg_config +#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\ + (major1) < 0 || \ + (major1) == 0 && (major2) < 29 || \ + (major1) == 0 && (major2) == 29 && (minor) <= 1) +#endif /* MIN_TOOL_VERSION_pkg_config */ + +/* tool runghc-8.0.2 */ +#ifndef TOOL_VERSION_runghc +#define TOOL_VERSION_runghc "8.0.2" +#endif /* TOOL_VERSION_runghc */ +#ifndef MIN_TOOL_VERSION_runghc +#define MIN_TOOL_VERSION_runghc(major1,major2,minor) (\ + (major1) < 8 || \ + (major1) == 8 && (major2) < 0 || \ + (major1) == 8 && (major2) == 0 && (minor) <= 2) +#endif /* MIN_TOOL_VERSION_runghc */ + +/* tool strip-2.30 */ +#ifndef TOOL_VERSION_strip +#define TOOL_VERSION_strip "2.30" +#endif /* TOOL_VERSION_strip */ +#ifndef MIN_TOOL_VERSION_strip +#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\ + (major1) < 2 || \ + (major1) == 2 && (major2) < 30 || \ + (major1) == 2 && (major2) == 30 && (minor) <= 0) +#endif /* MIN_TOOL_VERSION_strip */ + +#ifndef CURRENT_PACKAGE_KEY +#define CURRENT_PACKAGE_KEY "parser-sandbox-0.1.0.0-inplace" +#endif /* CURRENT_PACKAGE_KEY */ +#ifndef CURRENT_COMPONENT_ID +#define CURRENT_COMPONENT_ID "parser-sandbox-0.1.0.0-inplace" +#endif /* CURRENT_COMPONENT_ID */ +#ifndef CURRENT_PACKAGE_VERSION +#define CURRENT_PACKAGE_VERSION "0.1.0.0" +#endif /* CURRENT_PACKAGE_VERSION */ diff --git a/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/cache/config b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/cache/config new file mode 100644 index 0000000..9882146 Binary files /dev/null and b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/cache/config differ diff --git a/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/package.conf.inplace/package.cache b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/package.conf.inplace/package.cache new file mode 100644 index 0000000..b3cae5c Binary files /dev/null and b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/package.conf.inplace/package.cache differ diff --git a/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/setup-config b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/setup-config new file mode 100644 index 0000000..f4a4203 Binary files /dev/null and b/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/setup-config differ diff --git a/dist-newstyle/cache/compiler b/dist-newstyle/cache/compiler new file mode 100644 index 0000000..25206b8 Binary files /dev/null and b/dist-newstyle/cache/compiler differ diff --git a/dist-newstyle/cache/config b/dist-newstyle/cache/config new file mode 100644 index 0000000..c59721d Binary files /dev/null and b/dist-newstyle/cache/config differ diff --git a/dist-newstyle/cache/elaborated-plan b/dist-newstyle/cache/elaborated-plan new file mode 100644 index 0000000..bc2abcb Binary files /dev/null and b/dist-newstyle/cache/elaborated-plan differ diff --git a/dist-newstyle/cache/improved-plan b/dist-newstyle/cache/improved-plan new file mode 100644 index 0000000..ab53606 Binary files /dev/null and b/dist-newstyle/cache/improved-plan differ diff --git a/dist-newstyle/cache/plan.json b/dist-newstyle/cache/plan.json new file mode 100644 index 0000000..4e47eb1 --- /dev/null +++ b/dist-newstyle/cache/plan.json @@ -0,0 +1 @@ +{"cabal-version":"2.4.1.0","cabal-lib-version":"2.4.1.0","compiler-id":"ghc-8.0.2","os":"linux","arch":"x86_64","install-plan":[{"type":"pre-existing","id":"base-4.9.1.0","pkg-name":"base","pkg-version":"4.9.1.0","depends":["ghc-prim-0.5.0.0","integer-gmp-1.0.0.1","rts"]},{"type":"pre-existing","id":"ghc-prim-0.5.0.0","pkg-name":"ghc-prim","pkg-version":"0.5.0.0","depends":["rts"]},{"type":"pre-existing","id":"integer-gmp-1.0.0.1","pkg-name":"integer-gmp","pkg-version":"1.0.0.1","depends":["ghc-prim-0.5.0.0"]},{"type":"configured","id":"parser-sandbox-0.1.0.0-inplace","pkg-name":"parser-sandbox","pkg-version":"0.1.0.0","flags":{},"style":"local","pkg-src":{"type":"local","path":"/home/me/Projekty/Haskell/parser-sandbox/."},"dist-dir":"/home/me/Projekty/Haskell/parser-sandbox/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0","depends":["base-4.9.1.0"],"exe-depends":[],"component-name":"lib"},{"type":"configured","id":"parser-sandbox-0.1.0.0-inplace-parser-sandbox-exe","pkg-name":"parser-sandbox","pkg-version":"0.1.0.0","flags":{},"style":"local","pkg-src":{"type":"local","path":"/home/me/Projekty/Haskell/parser-sandbox/."},"dist-dir":"/home/me/Projekty/Haskell/parser-sandbox/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/x/parser-sandbox-exe","depends":["base-4.9.1.0","parser-sandbox-0.1.0.0-inplace"],"exe-depends":[],"component-name":"exe:parser-sandbox-exe","bin-file":"/home/me/Projekty/Haskell/parser-sandbox/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/x/parser-sandbox-exe/build/parser-sandbox-exe/parser-sandbox-exe"},{"type":"configured","id":"parser-sandbox-0.1.0.0-inplace-parser-sandbox-test","pkg-name":"parser-sandbox","pkg-version":"0.1.0.0","flags":{},"style":"local","pkg-src":{"type":"local","path":"/home/me/Projekty/Haskell/parser-sandbox/."},"dist-dir":"/home/me/Projekty/Haskell/parser-sandbox/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/t/parser-sandbox-test","depends":["base-4.9.1.0","parser-sandbox-0.1.0.0-inplace"],"exe-depends":[],"component-name":"test:parser-sandbox-test","bin-file":"/home/me/Projekty/Haskell/parser-sandbox/dist-newstyle/build/x86_64-linux/ghc-8.0.2/parser-sandbox-0.1.0.0/t/parser-sandbox-test/build/parser-sandbox-test/parser-sandbox-test"},{"type":"pre-existing","id":"rts","pkg-name":"rts","pkg-version":"1.0","depends":[]}]} \ No newline at end of file diff --git a/dist-newstyle/cache/solver-plan b/dist-newstyle/cache/solver-plan new file mode 100644 index 0000000..33f32df Binary files /dev/null and b/dist-newstyle/cache/solver-plan differ diff --git a/dist-newstyle/cache/source-hashes b/dist-newstyle/cache/source-hashes new file mode 100644 index 0000000..76c5346 Binary files /dev/null and b/dist-newstyle/cache/source-hashes differ diff --git a/dist-newstyle/packagedb/ghc-8.0.2/package.cache b/dist-newstyle/packagedb/ghc-8.0.2/package.cache new file mode 100644 index 0000000..b3cae5c Binary files /dev/null and b/dist-newstyle/packagedb/ghc-8.0.2/package.cache differ diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..fa5df27 --- /dev/null +++ b/package.yaml @@ -0,0 +1,49 @@ +name: parser-sandbox +version: 0.1.0.0 +github: "githubuser/parser-sandbox" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2019 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 +- transformers + +library: + source-dirs: src + +executables: + parser-sandbox-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - parser-sandbox + +tests: + parser-sandbox-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - parser-sandbox diff --git a/src/Lib.hs b/src/Lib.hs new file mode 100644 index 0000000..52b8d6c --- /dev/null +++ b/src/Lib.hs @@ -0,0 +1,221 @@ +{-# OPTIONS_GHC -fno-warn-unused-do-bind #-} +{-# LANGUAGE TypeOperators #-} + +module Lib where + +import Data.Char +import Control.Monad +import Control.Applicative +import Control.Monad.Trans.State +import Control.Monad.Trans.Class + + +newtype Parser a = Parser { parse :: String -> [(a,String)]} + + + + + +runParser :: Parser a -> String -> a +runParser m s = + case parse m s of + [(res,[])] -> res + [(_,rs)] -> error "Parser did not consume entire stream" + _ -> error "Parser error" + + + +item :: Parser Char +item = Parser $ \s -> + case s of + [] -> [] + (c:cs) -> [(c,cs)] + + +bind :: Parser a -> (a -> Parser b) -> Parser b +bind p f = Parser $ \s -> + do + (a1,s1) <- parse p s + parse (f a1) s1 + +unit :: a -> Parser a +unit a = Parser (\s -> [(a,s)]) + + +instance Functor Parser where + fmap f (Parser cs) = Parser $ \s -> [(f a, b) | (a,b) <- cs s] + +instance Applicative Parser where + pure = return + (Parser cs1) <*> (Parser cs2) = Parser (\s -> [(f a, s2) | (f, s1) <- cs1 s, (a, s2) <- cs2 s1]) + +instance Monad Parser where + return = unit + (>>=) = bind + +instance MonadPlus Parser where + mzero = failure + mplus = combine + +instance Alternative Parser where + empty = mzero + (<|>) = option + +failure :: Parser a +failure = Parser $ \cs -> [] + +combine :: Parser a -> Parser a -> Parser a +combine p q = Parser $ \s -> parse p s <> parse q s + + +option :: Parser a -> Parser a -> Parser a +option p q = Parser $ \s -> + case parse p s of + [] -> parse q s + res -> res + +satisfy :: (Char -> Bool) -> Parser Char +satisfy p = + item >>= \c -> + if p c + then unit c + else (Parser (\cs -> [])) + + +oneOf :: [Char] -> Parser Char +oneOf s = satisfy (flip elem s) + +chainl :: Parser a -> Parser (a -> a -> a) -> a -> Parser a +chainl p op a = (p `chainl1` op) <|> return a + +chainl1 :: Parser a -> Parser (a -> a -> a) -> Parser a +chainl1 p op = do { a <- p; rest a} + where rest a = (do + f <- op + b <- p + rest (f a b)) <|> return a + + + + +char :: Char -> Parser Char +char c = satisfy (c ==) + +natural :: Parser Integer +natural = read <$> some (satisfy isDigit) + + +string :: String -> Parser String +string [] = return [] +string (c:cs) = do + char c + string cs + return (c:cs) + +token :: Parser a -> Parser a +token p = do + a <- p + spaces + return a + +reserved :: String -> Parser String +reserved s = token (string s) + +spaces :: Parser String +spaces = many $ oneOf " \n\r" + + +digit :: Parser Char +digit = satisfy isDigit + +number :: Parser Int +number = do + s <- string "-" <|> return [] + cs <- some digit + return $ read $ s ++ cs + +parens :: Parser a -> Parser a +parens m = do + reserved "(" + n <- token m + reserved ")" + return n + + +data Sentence = T + | F + | V Char + | N Sentence + | Sentence `SOR` Sentence + | Sentence `SAND` Sentence + | Sentence `SEQ` Sentence + | Sentence `SIMP` Sentence + deriving (Eq) + + +instance Show Sentence where + show T = "T" + show F = "F" + show (V c) = [c] + show (N s) = "~"++show s + show (SOR a b) = "(" ++ show a ++ " v " ++ show b ++ ")" + show (SAND a b) = "(" ++ show a ++ " ^ " ++ show b ++ ")" + show (SEQ a b) = "(" ++ show a ++ " == " ++ show b ++ ")" + show (SIMP a b) = "(" ++ show a ++ " => " ++ show b ++ ")" + +sentence :: Parser Sentence +sentence = all <|> parens sentence + where + all = t <|> f <|> v <|> neg <|> or <|> and <|> eq <|> imp + t = do + char 'T' + return T + f = do + char 'F' + return F + v = do + i <- oneOf ['a'..'z'] + return $ V i + orOP = reserved "v" >> return SOR + andOP = reserved "^" >> return SOR + eqOP = reserved "==" >> return SEQ + binary op = chainl1 (token $ parens sentence) op + or = binary orOP + and = binary andOP + eq = binary eqOP + imp = do + s1 <- token $ parens sentence + reserved "=>" + s2 <- token $ parens sentence + return $ SIMP s1 s2 + neg = do + char '~' + s1 <- sentence + return $ N s1 + + +tautology :: Sentence -> StateT [(Char,Bool)] [] Bool +tautology T = return True +tautology F = return False +tautology (N s) = not <$> tautology s +tautology (V v) = do + store <- get + case lookup v store of + Nothing -> do + x <- lift [True,False] + modify $ ((v,x):) + return x + Just x -> + return x +tautology (SOR a b) = liftM2 (||) (tautology a) (tautology b) +tautology (SAND a b) = liftM2 (&&) (tautology a) (tautology b) +tautology (SEQ a b) = liftM2 (==) (tautology a) (tautology b) +tautology (SIMP a b) = liftM2 (||) (not <$> tautology a) (tautology b) +checkTautology s = all ((== True) . fst) $ runStateT (tautology s) [] + +go = do + s <- getLine + let s' = runParser sentence s + print s' + print $ checkTautology s' + diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..d0a6794 --- /dev/null +++ b/stack.yaml @@ -0,0 +1,64 @@ +# 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: +# https://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 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-13.19 + +# 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 +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver +# using the same syntax as the packages field. +# (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.9" +# +# 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 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"