From 967ae182b0a6852cc37e77cb88ee53a53526f027 Mon Sep 17 00:00:00 2001 From: defanor Date: Mon, 4 Dec 2017 07:28:42 +0300 Subject: 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. --- Coalpit.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Coalpit.hs') 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 -- cgit v1.2.3