From c5ae44f284aa982cc0cc3ff86f33b079f8d1a65d Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Mon, 15 Sep 2014 16:24:04 -0400 Subject: [PATCH] Add support for colons (':') in identifier names, like foo:bar = 1. --- Data/Configurator.hs | 4 ++-- Data/Configurator/Parser.hs | 2 +- tests/Test.hs | 9 +++++++++ tests/resources/pathological.cfg | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Data/Configurator.hs b/Data/Configurator.hs index 96b88f3..a8c3744 100644 --- a/Data/Configurator.hs +++ b/Data/Configurator.hs @@ -416,8 +416,8 @@ empty = Config "" $ unsafePerformIO $ do -- > HerList = [1, "foo", off] -- -- A name must begin with a Unicode letter, which is followed by zero --- or more of a Unicode alphanumeric code point, hyphen \"@-@\", or --- underscore \"@_@\". +-- or more of a Unicode alphanumeric code point, hyphen \"@-@\", +-- underscore \"@_@\", or colon \"@:@\". -- -- Bindings are created or overwritten in the order in which they are -- encountered. It is legitimate for a name to be bound multiple diff --git a/Data/Configurator/Parser.hs b/Data/Configurator/Parser.hs index 1eafeb6..7f86769 100644 --- a/Data/Configurator/Parser.hs +++ b/Data/Configurator/Parser.hs @@ -75,7 +75,7 @@ ident = do throw (ParseError "" $ "reserved word (" ++ show n ++ ") used as identifier") return n where - isCont c = isAlphaNum c || c == '_' || c == '-' + isCont c = isAlphaNum c || c == '_' || c == '-' || c == ':' value :: Parser Value value = mconcat [ diff --git a/tests/Test.hs b/tests/Test.hs index c52cd70..081b67c 100644 --- a/tests/Test.hs +++ b/tests/Test.hs @@ -105,6 +105,15 @@ loadTest = deep <- lookup cfg "ag.q-e.i_u9.a" assertEqual "deep bool" deep (Just False :: Maybe Bool) + adcolon <- lookup cfg "a:d" + assertEqual "colon identifiers" adcolon (Just False :: Maybe Bool) + + abc <- lookup cfg "a:b:c" + assertEqual "multiple colon identifiers" abc (Just "hello" :: Maybe Text) + + c <- lookup cfg "c:" + assertEqual "colon identifiers without suffix or space" c (Just 1 :: Maybe Int) + typesTest :: Assertion typesTest = withLoad "pathological.cfg" $ \cfg -> do diff --git a/tests/resources/pathological.cfg b/tests/resources/pathological.cfg index 77188e5..5b275fe 100644 --- a/tests/resources/pathological.cfg +++ b/tests/resources/pathological.cfg @@ -37,3 +37,7 @@ ba = "$(HOME)" xs = [1,2,3] c = "x" + +a:d = false +a:b:c = "hello" +c:=1 \ No newline at end of file