use parsec for the parser
[clean-tests.git] / datatype / Language / GenDSL.hs
index 69dff4b..47a6b29 100644 (file)
@@ -19,11 +19,14 @@ stringName (Name occ _) = occString occ
 numberedArgs :: [a] -> Q [Name]
 numberedArgs = zipWithM (\i _->newName $ "f" ++ show i) [0 :: Int ..]
 
+adtFieldName :: Name -> Int -> Name
+adtFieldName consName idx = mkName $ map toLower (stringName consName) ++ "f" ++ show idx
+
 data Field = Field { fname :: Name, ffresh :: Name, ftype :: Type }
 
 toNameType :: Con -> Q [Field]
 toNameType (NormalC consName fs) = numberedArgs fs
-    >>= \nfs->pure [Field (mkName $ map toLower (stringName consName) ++ "f" ++ show i) nf t | (_, t) <- fs | nf <- nfs | i <- [0 :: Int ..]]
+    >>= \nfs->pure [Field (adtFieldName consName i) nf t | (_, t) <- fs | nf <- nfs | i <- [0 :: Int ..]]
 toNameType (RecC _ fs) = numberedArgs fs
     >>= \nfs->pure [Field n nf t | (n, _, t)<-fs | nf <- nfs]
 toNameType c = fail $ "Unsupported constructor type: " ++ show c