Add common code for CS325 madness
This commit is contained in:
15
code/cs325-langs/src/Common.hs
Normal file
15
code/cs325-langs/src/Common.hs
Normal file
@@ -0,0 +1,15 @@
|
||||
module Common where
|
||||
import PythonAst
|
||||
import PythonGen
|
||||
import Text.Parsec
|
||||
|
||||
compile :: (String -> String -> Either ParseError p) -> (p -> [PyStmt]) -> String -> IO ()
|
||||
compile p t f = do
|
||||
let inputName = f ++ ".lang"
|
||||
let outputName = f ++ ".py"
|
||||
file <- readFile inputName
|
||||
let either = p inputName file
|
||||
case either of
|
||||
Right prog -> writeFile outputName (translate $ t prog)
|
||||
Left e -> print e
|
||||
|
||||
Reference in New Issue
Block a user