on develop help sign in
Ensuring numeric nullary sum branches are prefixed by default
commit4db6a1ee4b85970e39e167f432868a2cf855947b authorBrendan Hay <brendan.g.hay@gmail.com> dateFri 2 Oct 2015, 09:38 (11 years ago) parent03c6efc
2 files changed+9−5
gen/src/Gen/AST/Solve.hs+8−4 gen/src/Gen/Text.hs+1−1
gen/src/Gen/AST/Solve.hs+8−4
@@ -29,6 +29,7 @@ import Control.Lens hiding (enum)
2929import Control.Monad.Except
3030import Data.CaseInsensitive (CI)
3131import qualified Data.CaseInsensitive as CI
32+import Data.Char (isDigit)
3233import Data.Hashable
3334import qualified Data.HashMap.Strict as Map
3435import qualified Data.HashSet as Set
@@ -141,15 +142,18 @@ getPrefix g = loc "getPrefix" g $ memo prefixed g go
141142 _ -> pure mempty
142143
143144 field rs = do
144− let ls = Map.keys rs
145− ks = Set.fromList (map (CI.mk . local) ls)
146145 p <- uniq fields (acronymPrefixes g) ks
147146 pure (Prefix p)
147+ where
148+ ls = Map.keys rs
149+ ks = Set.fromList (map (CI.mk . local) ls)
148150
149151 branch vs = do
150− p <- uniq branches ("" : acronymPrefixes g) $
151− Set.fromList (map CI.mk vs)
152+ p <- uniq branches ps (Set.fromList (map CI.mk vs))
152153 pure (Prefix p)
154+ where
155+ ps | any (isDigit . Text.head) vs = acronymPrefixes g
156+ | otherwise = "" : acronymPrefixes g
153157
154158 uniq :: Lens' Memo Seen
155159 -> [CI Text]
gen/src/Gen/Text.hs+1−1
@@ -220,7 +220,7 @@ upperAcronym x = Fold.foldl' (flip (uncurry RE.replaceAll)) x xs
220220 , ("info", "Info")
221221 , ("library", "Library")
222222 , ("list", "List")
223− , ("([^pn]load", "$1Load")
223+ , ("([^pn])load", "$1Load")
224224 , ("manager", "Manager")
225225 , ("model", "Model")
226226 , ("monitor", "Monitor")