-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
41 lines (35 loc) · 1.35 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
module Main where
import Control.Lens ((%~))
import Control.Monad (foldM_)
import Data.Function ((&))
import SNEK.Check (checkVE, emptyE, eKSs, eTSs, eVSs, runCheck, veT)
import SNEK.Parse (parseVE)
import SNEK.PHP (runPHPGen, ve2PHPM)
import SNEK.Read (readData)
import SNEK.Symbol (KS(..), TS(..), VS(..))
import SNEK.Type ((~->~), K(..), prettyT, T(..))
import System.Directory (makeAbsolute)
import System.Environment (getArgs)
import qualified Data.Map as Map
main :: IO ()
main = do
sourceFiles <- getArgs >>= mapM makeAbsolute
foldM_ go Map.empty sourceFiles
where go ts file = do
text <- readFile file
let [datum] = fromJust $ readData text
let ast = fromRight $ parseVE datum
let tast = fromRight $ check ast
let t = veT tast
putStrLn $ runPHPGen (ve2PHPM tast)
return $ Map.insert file t ts
where check e = runCheck (checkVE e) env
env = emptyE file ts
& eKSs %~ Map.insert "*" (KS TypeK)
& eKSs %~ Map.insert "->" (KS FuncK)
& eTSs %~ Map.insert "bool" (TS BoolT)
& eTSs %~ Map.insert "->" (TS FuncT)
fromRight (Right x) = x
fromRight (Left x) = error (show x)
fromJust (Just x) = x
fromJust _ = error "nein"