diff --git a/XMonad/Prompt/OrgMode.hs b/XMonad/Prompt/OrgMode.hs index e26eec16..fd2e9ba8 100644 --- a/XMonad/Prompt/OrgMode.hs +++ b/XMonad/Prompt/OrgMode.hs @@ -401,6 +401,14 @@ pDate = skipSpaces *> choice , pPrefix "su" "nday" Sunday ] + numWithoutColon :: Parser Int + numWithoutColon = do + str <- num + c <- get + if c == ':' + then pfail + else pure str + pDate' :: Parser (Int, Maybe Int, Maybe Integer) pDate' = (,,) <$> num @@ -411,6 +419,7 @@ pDate = skipSpaces *> choice , pPrefix "jul" "y" 7 , pPrefix "au" "gust" 8 , pPrefix "s" "eptember" 9 , pPrefix "o" "ctober" 10 , pPrefix "n" "ovember" 11, pPrefix "d" "ecember" 12 + , numWithoutColon ]) <*> optional (skipSpaces *> num >>= \i -> guard (i >= 25) $> i) diff --git a/XMonad/Util/Parser.hs b/XMonad/Util/Parser.hs index 044f2ef9..d5fb422e 100644 --- a/XMonad/Util/Parser.hs +++ b/XMonad/Util/Parser.hs @@ -52,6 +52,7 @@ module XMonad.Util.Parser ( endBy1, munch, munch1, + pfail ) where import XMonad.Prelude @@ -136,6 +137,10 @@ instance Alternative Parser where runParser :: Parser a -> String -> Maybe a runParser (Parser p) = fmap fst . listToMaybe . ReadP.readP_to_S p +-- | Always fails +pfail :: Parser a +pfail = Parser $ ReadP.pfail + -- | Consume and return the next character. Fails if there is no input -- left. get :: Parser Char diff --git a/tests/OrgMode.hs b/tests/OrgMode.hs index 6db8cad5..3b4cd32a 100644 --- a/tests/OrgMode.hs +++ b/tests/OrgMode.hs @@ -22,6 +22,29 @@ spec = do prop "prop_encodeLinearity" prop_encodeLinearity prop "prop_decodeLinearity" prop_decodeLinearity + describe "pInput" $ do + it "works with todo +d 22 january 2021" $ do + pInput "todo +d 22 ja 2021" + `shouldBe` Just + ( Deadline + "todo" + (Time {date = Date (22, Just 1, Just 2021), tod = Nothing}) + ) + it "works with todo +d 22 01 2022" $ do + pInput "todo +d 22 01 2022" + `shouldBe` Just + ( Deadline + "todo" + (Time {date = Date (22, Just 1, Just 2022), tod = Nothing}) + ) + it "works with todo +d 1 01:01" $ do + pInput "todo +d 1 01:01" + `shouldBe` Just + ( Deadline + "todo" + (Time {date = Date (1, Nothing, Nothing), tod = Just $ TimeOfDay 1 1}) + ) + -- Checking for regressions context "+d +d f" $ do it "encode" $ prop_encodeLinearity (OrgMsg "+d +d f")