@@ -18,7 +18,8 @@ GNU Affero General Public License for more details.
18
18
You should have received a copy of the GNU Affero General Public License
19
19
along with this program. If not, see <https://www.gnu.org/licenses/>.
20
20
-}
21
- module Language.CQL.Parser where
21
+
22
+ module Language.CQL.Parser.Program where
22
23
23
24
import Data.List
24
25
import Data.Map as Map hiding ((\\) )
@@ -34,21 +35,21 @@ import Language.CQL.Parser.Typeside as T'
34
35
import Language.CQL.Program as P
35
36
import Text.Megaparsec
36
37
37
- parseCqlProgram :: String -> Err Prog
38
- parseCqlProgram s = case runParser parseCqlProgram ' " " s of
39
- Left err -> Left $ " Parse error: " ++ parseErrorPretty err
40
- Right (o, x ) -> if length (fst $ unzip x ) == length (nub $ fst $ unzip x )
41
- then pure $ toProg o x
42
- else Left $ " Duplicate definition: " ++ show (nub (fmap fst x \\ nub (fmap fst x )))
38
+ parseProgram :: String -> Err Prog
39
+ parseProgram s = case runParser parseProgram ' " " s of
40
+ Left err -> Left $ " Parse error: " ++ parseErrorPretty err
41
+ Right (opts, prog ) -> if length (fst $ unzip prog ) == length (nub $ fst $ unzip prog )
42
+ then Right $ toProg opts prog
43
+ else Left $ " Duplicate definition: " ++ show (nub (fmap fst prog \\ nub (fmap fst prog )))
43
44
44
- -- | Returns a list of config options and programs.
45
- parseCqlProgram ' :: Parser ([(String , String )], [(String , Exp )])
46
- parseCqlProgram ' =
45
+ -- | Returns a list of config option key-value paired with programs.
46
+ parseProgram ' :: Parser ([(String , String )], [(String , Exp )])
47
+ parseProgram ' =
47
48
between spaceConsumer eof configsAndProgs
48
49
where
49
50
configsAndProgs = do
50
51
opts <- optional (constant " options" *> many optionParser)
51
- progs <- many parseSection
52
+ progs <- many parseExp
52
53
return (fromMaybe [] opts, progs)
53
54
54
55
toProg :: [(String , String )] -> [(String , Exp )] -> Prog
@@ -63,17 +64,17 @@ toProg opts ((v,e):p) = case e of
63
64
where
64
65
KindCtx t s i m q tr _ = toProg opts p
65
66
66
- parseSection :: Parser (String , Exp )
67
- parseSection =
68
- section " typeside" typesideExpParser ExpTy <|>
69
- section " schema" schemaExpParser ExpS <|>
70
- section " instance" instExpParser ExpI <|>
71
- section " mapping" mapExpParser ExpM <|>
72
- section " transform" transExpParser ExpT
67
+ parseExp :: Parser (String , Exp )
68
+ parseExp =
69
+ go " typeside" typesideExpParser ExpTy <|>
70
+ go " schema" schemaExpParser ExpS <|>
71
+ go " instance" instExpParser ExpI <|>
72
+ go " mapping" mapExpParser ExpM <|>
73
+ go " transform" transExpParser ExpT
73
74
where
74
- section sectionKindName bodyParser ctor = do
75
- _ <- constant sectionKindName
76
- sectionName <- identifier
75
+ go expKindName bodyParser ctor = do
76
+ _ <- constant expKindName
77
+ expName <- identifier
77
78
_ <- constant " ="
78
79
body <- bodyParser
79
- return (sectionName , ctor body)
80
+ return (expName , ctor body)
0 commit comments