Fix parsing of $1,$2,...
authorJoachim Breitner <mail@joachim-breitner.de>
Sat, 25 Jan 2014 22:18:51 +0000 (22:18 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sat, 25 Jan 2014 22:18:51 +0000 (22:18 +0000)
parsing should _not_ swallow the following space. This fixes #4, and adds a test case.

src/Categorize.hs
tests/issue4.cfg [new file with mode: 0644]
tests/test.hs

index 27410b5..2862dd3 100644 (file)
@@ -355,7 +355,7 @@ parseCondPrim = choice
             ) <?> "list of regular expressions"
             ])
         , char '$' >> choice 
-             [ do backref <- natural lang
+             [ do backref <- read <$> many1 digit
                   return $ CondString (getBackref backref)
              , do varname <- identifier lang 
                   choice 
@@ -482,7 +482,7 @@ parseTagPart :: Parser (Ctx -> Maybe Text)
 parseTagPart = do parts <- many1 (choice
                         [ do char '$'
                              (replaceForbidden . ) <$> choice
-                               [ do num <- natural lang
+                               [ do num <- read <$> many1 digit
                                     return $ getBackref num
                                , do varname <- many1 (letter <|> oneOf ".")
                                     return $ getVar varname
diff --git a/tests/issue4.cfg b/tests/issue4.cfg
new file mode 100644 (file)
index 0000000..42869a7
--- /dev/null
@@ -0,0 +1,5 @@
+-- Firefox
+current window $program == "program" ==>
+if current window $title =~ /^(aaa)/ then tag Cat:$1 else
+if current window $title =~ /^(aa)/  then tag Cat:$1 else
+if current window $title =~ /^(a)/   then tag Cat:$1 else tag None
index 6fc49b3..d65c441 100644 (file)
@@ -23,7 +23,13 @@ tests = testGroup "Tests" [goldenTests, regressionTests]
 
 regressionTests :: TestTree
 regressionTests = testGroup "Regression tests"
-    [ testCase "Issue #5" $ do
+    [ testCase "Issue #4" $ do
+        cat <- readCategorizer "tests/issue4.cfg"
+        let sample = TimeLogEntry undefined 0 (CaptureData [(True, "aa", "program")] 0 "")
+        let [TimeLogEntry _ _ (_,acts)] = cat [sample]
+        [Activity (Just "Cat") "aa"] @=? acts
+        return ()
+    , testCase "Issue #5" $ do
         cat <- readCategorizer "tests/issue5.cfg"
         let sample = TimeLogEntry undefined 0 (CaptureData [(True, "aa", "program")] 0 "")
         let [TimeLogEntry _ _ (_,acts)] = cat [sample]