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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
module CPP.ICode.Parser.SQL.Converter
( parseSQL, readParserInfo, ParserInfo )
where
import Control.Monad (when)
import System.IO (openFile, IOMode(..), hGetContents)
import CPP.ICode.ParseTypes
import CPP.ICode.Parser.SQL.Consistency
import CPP.ICode.Parser.SQL.Namer
import CPP.ICode.Parser.SQL.Parser
import CPP.ICode.Parser.SQL.ParserInfoType
import CPP.ICode.Parser.SQL.Scanner
import CPP.ICode.Parser.SQL.Translator
import CPP.ICode.Parser.SQL.Typer
parseSQL :: Bool -> Either String ParserInfo -> LangParser
parseSQL withrundb parserInfo pos code =
case parserInfo of
Left err -> return (throwPM pos err)
Right pi -> processCompilation withrundb pi pos code
readParserInfo :: Int -> String -> IO (Either String ParserInfo)
readParserInfo verb filename = do
when (verb > 0) $ putStrLn $
"Reading SQL model info file '" ++ filename ++ "'..."
handle <- openFile filename ReadMode
contents <- hGetContents handle
case reads contents of
[] -> return (Left "ParserInfo file not found or corrupted.")
((a,_):_) -> return (Right a)
checkResult :: PM a -> Either (PM String) (PM a)
checkResult (PM (WM (Errors err) ws)) = Left (PM $ WM (throwPR err) ws)
checkResult pm@(PM (WM (OK _ ) _)) = Right pm
processCompilation :: Bool -> ParserInfo -> LangParser
processCompilation withrundb parserInfo pos code =
let parsedCode = parseTkLs pos (scan code)
in case checkResult parsedCode of
Left pm -> return pm
Right _ -> callNamer parsedCode
where callNamer res =
let namedCode = nameStatements res pos
in case checkResult namedCode of
Left pm -> return pm
Right _ -> callConsistency namedCode
callConsistency res =
let consCheckedCode = checkConsistency res
parserInfo
pos
in case checkResult consCheckedCode of
Left pm -> return pm
Right _ -> callTyper consCheckedCode
callTyper res =
let typeCheckedCode = checkTypes res
(getTypes parserInfo)
pos
in case checkResult typeCheckedCode of
Left pm -> return pm
Right _ -> return (translate typeCheckedCode
withrundb
(cdbiModule parserInfo)
pos)
|