Commit 8d3dfef1 authored by Paul Ogris's avatar Paul Ogris
Browse files

Implement basic CLI and I/O

parent 70d797cd
......@@ -2,5 +2,28 @@
-- and only use it in the executable. Doing so allows others to use what you
-- wrote in their libraries.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
import Language.LARS
import Relax
import Options.Generic
import qualified Data.Text.IO as T
data CLI = CLI
{
input :: FilePath <?> "Input file"
} deriving (Show, Generic)
instance ParseRecord CLI
main :: IO ()
main = putStrLn "Hello World"
main = do
cli <- getRecord "lars-relax"
inp <- T.readFile (unHelpful $ input cli)
case parse program (unHelpful $ input cli) inp of
Left e -> error (show e)
Right x -> T.putStrLn $ prettyProgram (relax x)
......@@ -10,6 +10,7 @@ module Language.LARS
-- * Pretty Printing
prettyOneLine,
prettyProgram,
-- * Parsing
parse,
......@@ -18,7 +19,8 @@ module Language.LARS
relation,
signedAtom,
rule,
bodyElement
bodyElement,
program
)
where
......@@ -70,6 +72,9 @@ instance Pretty SignedAtom where
prettyOneLine :: Pretty a => a -> Text
prettyOneLine = PP.displayTStrict . PP.renderOneLine . PP.pretty
prettyProgram :: [Statement] -> Text
prettyProgram = PP.displayTStrict . PP.renderCompact . PP.vcat . map PP.pretty
type Parser = Parsec Void Text
-- | Space Consumer
......@@ -119,3 +124,6 @@ relation = lexeme $ takeWhileP Nothing (\x -> x `notElem` [',','.'])
stmt :: Parser Statement
stmt = StmtRule <$> rule
program :: Parser [Statement]
program = some stmt
......@@ -34,6 +34,8 @@ executables:
dependencies:
- base
- lars-relax
- optparse-generic
- text
ghc-options:
- -rtsopts
- -threaded
......
a :- b, not c.
b. c.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment