on develop help sign in
Ensuring smart ctors don't clash with field naming
d4d6c9cBrendan Hay
gen/src/Gen/AST/Solve.hs+4−1
@@ -183,7 +183,8 @@ overlap :: (Eq a, Hashable a) => Set a -> Set a -> Bool
183overlap xs ys = not . Set.null $ Set.intersection xs ys
183overlap xs ys = not . Set.null $ Set.intersection xs ys
184
184
185acronymPrefixes :: Global -> [CI Text]
185acronymPrefixes :: Global -> [CI Text]
186+acronymPrefixes (global -> g) = filter (/= full) $
186−acronymPrefixes (global -> g) = map CI.mk (xs ++ map suffix ys ++ zs)
187+ map CI.mk (xs ++ map suffix ys ++ zs)
187 where
188 where
188 -- Take the next char
189 -- Take the next char
189 suffix x = Text.snoc x c
190 suffix x = Text.snoc x c
@@ -191,6 +192,8 @@ acronymPrefixes (global -> g) = map CI.mk (xs ++ map suffix ys ++ zs)
191 c | Text.length x >= 2 = Text.head (Text.drop 1 x)
192 c | Text.length x >= 2 = Text.head (Text.drop 1 x)
192 | otherwise = Text.head x
193 | otherwise = Text.head x
193
194
195+ full = CI.mk g
196+
194 zs = zipWith (\n x -> Text.snoc x (head (show n))) ([1..] :: [Int]) xs
197 zs = zipWith (\n x -> Text.snoc x (head (show n))) ([1..] :: [Int]) xs
195
198
196 xs = catMaybes [r1, r2, r3, r4, r5, r6]
199 xs = catMaybes [r1, r2, r3, r4, r5, r6]
gen/src/Gen/Text.hs+3−1
@@ -58,7 +58,7 @@ renameAbbrev = mconcat
58 . stripSuffix " API"
58 . stripSuffix " API"
59
59
60renameField :: Text -> Text
60renameField :: Text -> Text
61−renameField = lowerHead . upperAcronym . toCamel
61+renameField = lowerHead . lowerFirstAcronym . upperAcronym . toCamel
62
62
63renameBranch :: Text -> Text
63renameBranch :: Text -> Text
64renameBranch t
64renameBranch t
@@ -202,6 +202,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
202 , ("Apk", "APK")
202 , ("Apk", "APK")
203 , ("Os", "OS")
203 , ("Os", "OS")
204 , ("Oob", "OOB")
204 , ("Oob", "OOB")
205+ , ("Jwk", "JWK")
205
206
206 , ("access", "Access")
207 , ("access", "Access")
207 , ("account", "Account")
208 , ("account", "Account")
@@ -309,4 +310,5 @@ acronyms =
309 , ("VPN", "Vpn")
310 , ("VPN", "Vpn")
310 , ("XML", "Xml")
311 , ("XML", "Xml")
311 , ("ID", "Id")
312 , ("ID", "Id")
313+ , ("JWK", "Jwk")
312 ]
314 ]
gen/src/Gen/Types.hs+4−2
@@ -39,6 +39,7 @@ import Control.Monad.State.Strict
39import Data.Aeson hiding (Array, Bool, String)
39import Data.Aeson hiding (Array, Bool, String)
40import Data.CaseInsensitive (CI)
40import Data.CaseInsensitive (CI)
41import qualified Data.CaseInsensitive as CI
41import qualified Data.CaseInsensitive as CI
42+import Data.Char
42import Data.Function (on)
43import Data.Function (on)
43import qualified Data.HashMap.Strict as Map
44import qualified Data.HashMap.Strict as Map
44import qualified Data.HashSet as Set
45import qualified Data.HashSet as Set
@@ -49,6 +50,7 @@ import Data.Text (Text)
49import qualified Data.Text as Text
50import qualified Data.Text as Text
50import qualified Data.Text.Lazy as LText
51import qualified Data.Text.Lazy as LText
51import qualified Data.Text.Lazy.Builder as Build
52import qualified Data.Text.Lazy.Builder as Build
53+import Debug.Trace
52import qualified Filesystem.Path.CurrentOS as Path
54import qualified Filesystem.Path.CurrentOS as Path
53import Formatting
55import Formatting
54import Gen.Orphans ()
56import Gen.Orphans ()
@@ -266,7 +268,7 @@ data Memo = Memo
266 }
268 }
267
269
268initial :: Service (Fix Schema) -> Memo
270initial :: Service (Fix Schema) -> Memo
269−initial s = Memo s mempty mempty core mempty reserve mempty
271+initial s = Memo s mempty mempty core mempty reserveBranches mempty
270 where
272 where
271 -- Types available in Network.Google.Prelude.
273 -- Types available in Network.Google.Prelude.
272 core = Map.fromList
274 core = Map.fromList
@@ -274,7 +276,7 @@ initial s = Memo s mempty mempty core mempty reserve mempty
274 ]
276 ]
275
277
276 -- Reserved sum constructor names.
278 -- Reserved sum constructor names.
277− reserve = Map.singleton mempty . Set.fromList $
279+ reserveBranches = Map.singleton mempty . Set.fromList $
278 map (CI.mk . global) (Map.keys (s ^. dSchemas))
280 map (CI.mk . global) (Map.keys (s ^. dSchemas))
279
281
280makeLenses ''Memo
282makeLenses ''Memo
gen/src/Gen/Types/Id.hs+1−1
@@ -80,7 +80,7 @@ mname abrv (Suffix suf) (Global g) =
80
80
81dname, cname :: Global -> Name
81dname, cname :: Global -> Name
82dname = name . Text.unpack . upperHead . global
82dname = name . Text.unpack . upperHead . global
83−cname = name . Text.unpack . renameReserved . lowerHead . global
83+cname = name . Text.unpack . renameReserved . lowerHead . lowerFirstAcronym . global
84
84
85bname :: Prefix -> Text -> Name
85bname :: Prefix -> Text -> Name
86bname (Prefix p) = name
86bname (Prefix p) = name