on develop help sign in
Tweaking repeated parameter types
commitb8f5fd59dc2160e133927b6dab295bd34b854592 authorBrendan Hay <brendan.g.hay@gmail.com> dateSun 4 Oct 2015, 14:21 (11 years ago) parent3d31cd7
3 files changed+19−14
gen/src/Gen/AST/Solve.hs+15−14 gen/src/Gen/Syntax.hs+2 gen/src/Gen/Text.hs+2
gen/src/Gen/AST/Solve.hs+15−14
@@ -89,25 +89,26 @@ getType :: Global -> AST TType
8989getType g = loc "getType" g $ memo typed g go
9090 where
9191 go s = case s of
92− SAny {} -> may (TType "JSONValue")
93− SRef _ r -> unmay <$> getType (ref r)
92+ SAny {} -> res (TType "JSONValue")
93+ SRef _ r -> req <$> getType (ref r)
9494 --- FIXME: add natural/numeric manipulations
95− SLit i l -> may (lit i l)
96− SEnm {} -> may (TType g)
97− SArr _ (Arr e) -> (TList <$> (getType e)) >>= may
98− SObj {} -> may (TType g)
95+ SLit i l -> res (TLit l)
96+ SEnm {} -> res (TType g)
97+ SArr _ (Arr e) -> (TList <$> (getType e)) >>= pure . may
98+ SObj {} -> res (TType g)
9999 where
100− lit i l
101− | i ^. iRepeated = TList (TLit l)
102− | otherwise = TLit l
100+ res = pure . may . rep
103101
104− may | required s = pure
105− | defaulted s = pure
106− | otherwise = pure . TMaybe
102+ may | required s = id
103+ | defaulted s = id
104+ | otherwise = TMaybe
107105
108− unmay (TMaybe x)
106+ req (TMaybe x)
109107 | required s = x
110− unmay x = x
108+ req x = x
109+
110+ rep | s ^. iRepeated = TList
111+ | otherwise = id
111112
112113getDerive :: Global -> AST [Derive]
113114getDerive g = loc "getDerive" g $ memo derived g go
gen/src/Gen/Syntax.hs+2
@@ -205,9 +205,11 @@ googleRequestDecl g n assoc alt p api url fields m pat prec =
205205 where
206206 go l = case Map.lookup l ps of
207207 Just p | _pLocation p == Query
208+ , not (required p)
208209 , p ^. iRepeated -> infixApp (v l) "^." (var "_Default")
209210
210211 Just p | _pLocation p == Query
212+ , not (p ^. iRepeated)
211213 , parameter p || defaulted p -> app (var "Just") (v l)
212214
213215 _ -> v l
gen/src/Gen/Text.hs+2
@@ -209,6 +209,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
209209 , ("Dto", "DTO")
210210 , ("Sku", "SKU")
211211 , ("Cse$", "CSE")
212+ , ("Gan$", "GAN")
212213
213214 , ("access", "Access")
214215 , ("account", "Account")
@@ -251,6 +252,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
251252 , ("crawl", "Crawl")
252253 , ("error", "Error")
253254 , ("sample", "Sample")
255+ , ("session", "Session")
254256 ]
255257
256258acronyms :: [(String, String)]