on develop help sign in
Overriding operator naming
commitb45ca7100969c081b693980859291b2a8c2e4f87 authorBrendan Hay <brendan.g.hay@gmail.com> dateSat 26 Sep 2015, 16:25 (11 years ago) parent4e0ee3c
3 files changed+18−3
gen/annex/plus.json+2−1 gen/annex/plusdomains.json+2−1 gen/src/Gen/Text.hs+14−1
gen/annex/plus.json+2−1
@@ -1,4 +1,5 @@
11{
2− "library": "plus"
2+ "library": "plus",
3+ "canonicalName": "Plus"
34}
45
gen/annex/plusdomains.json+2−1
@@ -1,4 +1,5 @@
11{
2− "library": "plus-domains"
2+ "library": "plus-domains",
3+ "canonicalName": "PlusDomains"
34}
45
gen/src/Gen/Text.hs+14−1
@@ -17,6 +17,7 @@ import Control.Error
1717import Data.Bifunctor
1818import Data.Char
1919import qualified Data.Foldable as Fold
20+import qualified Data.HashMap.Strict as Map
2021import qualified Data.HashSet as Set
2122import Data.Monoid
2223import Data.String
@@ -60,7 +61,9 @@ renameField :: Text -> Text
6061renameField = lowerHead . toCamel
6162
6263renameBranch :: Text -> Text
63−renameBranch = renameReserved . go
64+renameBranch t
65+ | Just o <- operator t = o
66+ | otherwise = renameReserved (go t)
6467 where
6568 go x | Text.length x <= 2 = Text.toUpper x
6669 | otherwise = upperAcronym . cat $ split x
@@ -76,6 +79,16 @@ renameBranch = renameReserved . go
7679 | Text.all isUpper x = toPascal (Text.toLower x)
7780 | otherwise = toPascal x
7881
82+ operator x = Map.lookup x $
83+ Map.fromList
84+ [ ("!=", "NotEqual")
85+ , ("==", "Equal")
86+ , ("<", "Less")
87+ , ("<=", "LessOrEqual")
88+ , (">", "Greater")
89+ , (">=", "GreaterEqual")
90+ ]
91+
7992separator :: Char -> Bool
8093separator x =
8194 x == '\\'