-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMain.hs
52 lines (45 loc) · 1.36 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE RecordWildCards #-}
module Main where
import WangsAlgorithm.Prover
import WangsAlgorithm.LaTeX (latexProof)
import qualified WangsAlgorithm.Parser as P
import Options.Applicative
import Data.Semigroup ((<>))
data Backend =
Text
| LaTeX
deriving (Show, Eq, Read, Enum, Bounded)
allBackends :: [Backend]
allBackends = enumFrom minBound
data Input = Input
{ sequentStr :: String
, backend :: Backend
}
getInput :: Parser Input
getInput = Input
<$> strOption
( long "sequent"
<> short 's'
<> metavar "SEQUENT"
<> help "The propositional logic sequent to be proved" )
<*> option auto
( long "backend"
<> short 'b'
<> value Text
<> help ("Select one of " ++ show allBackends))
run :: Input -> IO ()
run Input{..} = case P.readSequent sequentStr of
Left err -> error $ "Cannot be parsed: " ++ show err
Right sequent -> case prove sequent of
Nothing -> error "No possible moves."
Just pf -> case backend of
Text -> putStrLn $ showProof pf
LaTeX -> putStrLn $ latexProof pf
main :: IO ()
main = run =<< execParser opts
where
opts = info (getInput <**> helper)
( fullDesc
<> progDesc ("Enter your sequent in the following format: "
++ "[a|b, a&c, ~b, c->d] |- [b,c]")
<> header "A propositional theorem prover for LK using Wang's Algorithm")