summaryrefslogtreecommitdiff
path: root/Coalpit.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-04 07:28:42 +0300
committerdefanor <defanor@uberspace.net>2017-12-04 07:28:42 +0300
commit967ae182b0a6852cc37e77cb88ee53a53526f027 (patch)
tree730395d2dbd046311300af3ac3b654ed0e18f3db /Coalpit.hs
parent95c890dbcd07b7355399e122191a362714cd52b9 (diff)
Be more strict on record selector name parsing
Ambiguity is possible if the parser accepts those optionally, so it should accept them depending on the provided options.
Diffstat (limited to 'Coalpit.hs')
-rw-r--r--Coalpit.hs12
1 files changed, 6 insertions, 6 deletions
diff --git a/Coalpit.hs b/Coalpit.hs
index 99eb1f9..246f036 100644
--- a/Coalpit.hs
+++ b/Coalpit.hs
@@ -87,7 +87,7 @@ data Modifiers = Modifiers { conNameMod :: String -> String
-- ^ Constructor name modifier.
, selNameMod :: String -> String
-- ^ Record selector name modifier.
- , alwaysAddSelName :: Bool
+ , alwaysUseSelName :: Bool
-- ^ Add record selector name always, not
-- just for optional arguments.
}
@@ -189,14 +189,14 @@ instance (Constructor c1, Constructor c2, GToArgs f1, GToArgs f2) =>
instance (GArgParser a, Selector c) => GArgParser (S1 c a) where
gArgParser m = M1 <$> do
- let sname = case selName (undefined :: S1 c a f) of
- "" -> pure ()
- name -> optional (pS (string (selNameMod m name)))
- >> pure ()
+ let sname = case (selName (undefined :: S1 c a f), alwaysUseSelName m) of
+ ("", _) -> pure ()
+ (_, False) -> pure ()
+ (name, True) -> pS (string (selNameMod m name)) >> pure ()
sname *> gArgParser m
instance (GToArgs a, Selector c) => GToArgs (S1 c a) where
- gToArgs m s@(M1 x) = case (selName s, alwaysAddSelName m) of
+ gToArgs m s@(M1 x) = case (selName s, alwaysUseSelName m) of
("", _) -> gToArgs m x
(_, False) -> gToArgs m x
(name, True) -> selNameMod m name : gToArgs m x