module Language.EO.Phi (
defaultMain,
normalize,
parseProgram,
unsafeParseObject,
unsafeParseProgram,
module Language.EO.Phi.Syntax,
) where
import System.Exit (exitFailure)
import Language.EO.Phi.Syntax.Abs qualified as Phi
import Language.EO.Phi.Syntax.Par qualified as Phi
import Language.EO.Phi.Normalize
import Language.EO.Phi.Syntax
parseProgram :: String -> Either String Phi.Program
parseProgram :: String -> Either String Program
parseProgram String
input = [Token] -> Either String Program
Phi.pProgram [Token]
tokens
where
tokens :: [Token]
tokens = String -> [Token]
Phi.myLexer String
input
parseObject :: String -> Either String Phi.Object
parseObject :: String -> Either String Object
parseObject = [Token] -> Either String Object
Phi.pObject ([Token] -> Either String Object)
-> (String -> [Token]) -> String -> Either String Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Token]
Phi.myLexer
unsafeParseProgram :: String -> Phi.Program
unsafeParseProgram :: String -> Program
unsafeParseProgram String
input =
case String -> Either String Program
parseProgram String
input of
Left String
parseError -> String -> Program
forall a. HasCallStack => String -> a
error String
parseError
Right Program
program -> Program
program
unsafeParseObject :: String -> Phi.Object
unsafeParseObject :: String -> Object
unsafeParseObject = (String -> Object)
-> (Object -> Object) -> Either String Object -> Object
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> Object
forall a. HasCallStack => String -> a
error Object -> Object
forall a. a -> a
id (Either String Object -> Object)
-> (String -> Either String Object) -> String -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Either String Object
parseObject
defaultMain :: IO ()
defaultMain :: IO ()
defaultMain = do
String
input <- IO String
getContents
let tokens :: [Token]
tokens = String -> [Token]
Phi.myLexer String
input
case [Token] -> Either String Program
Phi.pProgram [Token]
tokens of
Left String
parseError -> do
String -> IO ()
putStrLn String
parseError
IO ()
forall a. IO a
exitFailure
Right Program
program -> do
String -> IO ()
putStrLn (Program -> String
forall a. Print a => a -> String
printTree (Program -> Program
normalize Program
program))