Skip to content

A peer-to-peer stack for code collaboration

Fix issue #16, in which identifiers with numeric prefixes are generated

Luke Palmer27664c822419
diff --git a/src/Radicle/Internal.hs b/src/Radicle/Internal.hs
index 6a4f2bb..2c3e690 100644
--- a/src/Radicle/Internal.hs
+++ b/src/Radicle/Internal.hs
@@ -23,9 +23,9 @@ import qualified Text.Megaparsec as M
-- | Smart constructor for Ident.
mkIdent :: Text -> Maybe Ident
-mkIdent t = case runIdentity (M.runParserT identP "" t) of
- Left _ -> Nothing
- Right v -> pure v
+mkIdent t = case runIdentity (M.runParserT valueP "" t) of
+ Right (Atom i) -> pure i
+ _ -> Nothing
-- | A quasiquoter that checks that an identifier is valid at compile-time.
ident :: QuasiQuoter
diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hs
index a5cb56a..9663b8b 100644
--- a/test/spec/Radicle/Tests.hs
+++ b/test/spec/Radicle/Tests.hs
@@ -538,6 +538,11 @@ test_parser =
, testCase "a dict litteral with an odd number of forms is a syntax error" $
assertBool "succesfully parsed a dict with 3 forms" (isLeft $ parseTest "{:foo 3 4}")
+
+ , testCase "mkIdent does not accept identifiers with numeric prefixes" $ do
+ assertBool "not for -93G" (isNothing (mkIdent "-93G"))
+ assertBool "not for +0X, no sir" (isNothing (mkIdent "+0X"))
+ assertBool "5 is right out" (isNothing (mkIdent "5"))
]
where
x ~~> y = parseTest x @?= Right y