on develop help sign in
Ensuring smart ctors don't clash with field naming
commitd4d6c9cc7ae82b5c98debc5e188996e4acc79757 authorBrendan Hay <brendan.g.hay@gmail.com> dateFri 2 Oct 2015, 15:12 (11 years ago) parent8983e43
4 files changed+12−5
gen/src/Gen/AST/Solve.hs+4−1 gen/src/Gen/Text.hs+3−1 gen/src/Gen/Types.hs+4−2 gen/src/Gen/Types/Id.hs+1−1
gen/src/Gen/AST/Solve.hs+4−1
@@ -183,7 +183,8 @@ overlap :: (Eq a, Hashable a) => Set a -> Set a -> Bool
183183overlap xs ys = not . Set.null $ Set.intersection xs ys
184184
185185acronymPrefixes :: Global -> [CI Text]
186−acronymPrefixes (global -> g) = map CI.mk (xs ++ map suffix ys ++ zs)
186+acronymPrefixes (global -> g) = filter (/= full) $
187+ map CI.mk (xs ++ map suffix ys ++ zs)
187188 where
188189 -- Take the next char
189190 suffix x = Text.snoc x c
@@ -191,6 +192,8 @@ acronymPrefixes (global -> g) = map CI.mk (xs ++ map suffix ys ++ zs)
191192 c | Text.length x >= 2 = Text.head (Text.drop 1 x)
192193 | otherwise = Text.head x
193194
195+ full = CI.mk g
196+
194197 zs = zipWith (\n x -> Text.snoc x (head (show n))) ([1..] :: [Int]) xs
195198
196199 xs = catMaybes [r1, r2, r3, r4, r5, r6]
gen/src/Gen/Text.hs+3−1
@@ -58,7 +58,7 @@ renameAbbrev = mconcat
5858 . stripSuffix " API"
5959
6060renameField :: Text -> Text
61−renameField = lowerHead . upperAcronym . toCamel
61+renameField = lowerHead . lowerFirstAcronym . upperAcronym . toCamel
6262
6363renameBranch :: Text -> Text
6464renameBranch t
@@ -202,6 +202,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
202202 , ("Apk", "APK")
203203 , ("Os", "OS")
204204 , ("Oob", "OOB")
205+ , ("Jwk", "JWK")
205206
206207 , ("access", "Access")
207208 , ("account", "Account")
@@ -309,4 +310,5 @@ acronyms =
309310 , ("VPN", "Vpn")
310311 , ("XML", "Xml")
311312 , ("ID", "Id")
313+ , ("JWK", "Jwk")
312314 ]
gen/src/Gen/Types.hs+4−2
@@ -39,6 +39,7 @@ import Control.Monad.State.Strict
3939import Data.Aeson hiding (Array, Bool, String)
4040import Data.CaseInsensitive (CI)
4141import qualified Data.CaseInsensitive as CI
42+import Data.Char
4243import Data.Function (on)
4344import qualified Data.HashMap.Strict as Map
4445import qualified Data.HashSet as Set
@@ -49,6 +50,7 @@ import Data.Text (Text)
4950import qualified Data.Text as Text
5051import qualified Data.Text.Lazy as LText
5152import qualified Data.Text.Lazy.Builder as Build
53+import Debug.Trace
5254import qualified Filesystem.Path.CurrentOS as Path
5355import Formatting
5456import Gen.Orphans ()
@@ -266,7 +268,7 @@ data Memo = Memo
266268 }
267269
268270initial :: 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
270272 where
271273 -- Types available in Network.Google.Prelude.
272274 core = Map.fromList
@@ -274,7 +276,7 @@ initial s = Memo s mempty mempty core mempty reserve mempty
274276 ]
275277
276278 -- Reserved sum constructor names.
277− reserve = Map.singleton mempty . Set.fromList $
279+ reserveBranches = Map.singleton mempty . Set.fromList $
278280 map (CI.mk . global) (Map.keys (s ^. dSchemas))
279281
280282makeLenses ''Memo
gen/src/Gen/Types/Id.hs+1−1
@@ -80,7 +80,7 @@ mname abrv (Suffix suf) (Global g) =
8080
8181dname, cname :: Global -> Name
8282dname = name . Text.unpack . upperHead . global
83−cname = name . Text.unpack . renameReserved . lowerHead . global
83+cname = name . Text.unpack . renameReserved . lowerHead . lowerFirstAcronym . global
8484
8585bname :: Prefix -> Text -> Name
8686bname (Prefix p) = name