on develop help sign in
Overriding operator naming
b45ca71Brendan Hay
gen/annex/plus.json+2−1
@@ -1,4 +1,5 @@
1{
1{
2− "library": "plus"
2+ "library": "plus",
3+ "canonicalName": "Plus"
3}
4}
4
5
gen/annex/plusdomains.json+2−1
@@ -1,4 +1,5 @@
1{
1{
2− "library": "plus-domains"
2+ "library": "plus-domains",
3+ "canonicalName": "PlusDomains"
3}
4}
4
5
gen/src/Gen/Text.hs+14−1
@@ -17,6 +17,7 @@ import Control.Error
17import Data.Bifunctor
17import Data.Bifunctor
18import Data.Char
18import Data.Char
19import qualified Data.Foldable as Fold
19import qualified Data.Foldable as Fold
20+import qualified Data.HashMap.Strict as Map
20import qualified Data.HashSet as Set
21import qualified Data.HashSet as Set
21import Data.Monoid
22import Data.Monoid
22import Data.String
23import Data.String
@@ -60,7 +61,9 @@ renameField :: Text -> Text
60renameField = lowerHead . toCamel
61renameField = lowerHead . toCamel
61
62
62renameBranch :: Text -> Text
63renameBranch :: Text -> Text
64+renameBranch t
65+ | Just o <- operator t = o
63−renameBranch = renameReserved . go
66+ | otherwise = renameReserved (go t)
64 where
67 where
65 go x | Text.length x <= 2 = Text.toUpper x
68 go x | Text.length x <= 2 = Text.toUpper x
66 | otherwise = upperAcronym . cat $ split x
69 | otherwise = upperAcronym . cat $ split x
@@ -76,6 +79,16 @@ renameBranch = renameReserved . go
76 | Text.all isUpper x = toPascal (Text.toLower x)
79 | Text.all isUpper x = toPascal (Text.toLower x)
77 | otherwise = toPascal x
80 | otherwise = toPascal x
78
81
82+ operator x = Map.lookup x $
83+ Map.fromList
84+ [ ("!=", "NotEqual")
85+ , ("==", "Equal")
86+ , ("<", "Less")
87+ , ("<=", "LessOrEqual")
88+ , (">", "Greater")
89+ , (">=", "GreaterEqual")
90+ ]
91+
79separator :: Char -> Bool
92separator :: Char -> Bool
80separator x =
93separator x =
81 x == '\\'
94 x == '\\'