Commits

Eric Rochester committed 97ff59f

Added link to rule body from reference to rule.

  • Participants
  • Parent commits 2d02acd

Comments (0)

Files changed (2)

File Test/SequiturUnit.hs

 test_abcdbc = TestCase (do
     let compressed = Seq.compress "abcdbc"
     testRule compressed 0 [ Seq.Literal 'a'
-                          , Seq.Rule 1
+                          , Seq.Rule 1 S.empty
                           , Seq.Literal 'd'
-                          , Seq.Rule 1
+                          , Seq.Rule 1 S.empty
                           ]
     testRule compressed 1 [ Seq.Literal 'b', Seq.Literal 'c' ])
 
 test_abcdbcabcdbc = TestCase (do
     let compressed = Seq.compress "abcdbcabcdbc"
-    testRule compressed 0 [ Seq.Rule 1, Seq.Rule 1 ]
+    testRule compressed 0 [ Seq.Rule 1 S.empty, Seq.Rule 1 S.empty ]
     testRule compressed 1 [ Seq.Literal 'a'
-                          , Seq.Rule 2
+                          , Seq.Rule 2 S.empty
                           , Seq.Literal 'd'
-                          , Seq.Rule 2
+                          , Seq.Rule 2 S.empty
                           ]
     testRule compressed 2 [ Seq.Literal 'b', Seq.Literal 'c' ])
 
 test_aabaaab = TestCase (do
     let compressed = Seq.compress "aabaaab"
     case (toList $ Seq.rule compressed 0) of
-        [ Seq.Rule 1, Seq.Literal 'a', Seq.Rule 1 ] ->
+        [ Seq.Rule 1 e1, Seq.Literal 'a', Seq.Rule 1 e2 ] | e1 == S.empty && e2 == S.empty ->
             testRule compressed 1 [ Seq.Literal 'a'
                                   , Seq.Literal 'a'
                                   , Seq.Literal 'b' ]
-        [ Seq.Rule 1, Seq.Literal 'b', Seq.Rule 1, Seq.Literal 'a', Seq.Literal 'b' ] ->
+        [ Seq.Rule 1 e1, Seq.Literal 'b', Seq.Rule 1 e2, Seq.Literal 'a', Seq.Literal 'b' ] | e1 == S.empty && e2 == S.empty ->
             testRule compressed 1 [ Seq.Literal 'a', Seq.Literal 'a' ]
         _ ->
             assertFailure "aabbaaab not compressed correctly."
     -- abcdbc
     let c6 = Seq.feed c5 'c'
     testRule c6 0 [ Seq.Literal 'a'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   , Seq.Literal 'd'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   ]
     testRule c6 1 [ Seq.Literal 'b', Seq.Literal 'c' ]
     assertEqual "rule count" 2 $ Seq.ruleCount c6
     -- abcdbca
     let c7 = Seq.feed c6 'a'
     testRule c7 0 [ Seq.Literal 'a'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   , Seq.Literal 'd'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   , Seq.Literal 'a'
                   ]
     testRule c7 1 [ Seq.Literal 'b', Seq.Literal 'c' ]
     -- abcdbcab
     let c8 = Seq.feed c7 'b'
     testRule c8 0 [ Seq.Literal 'a'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   , Seq.Literal 'd'
-                  , Seq.Rule 1
+                  , Seq.Rule 1 S.empty
                   , Seq.Literal 'a'
                   , Seq.Literal 'b'
                   ]
 
     -- abcdbcabc
     let c9 = Seq.feed c8 'b'
-    testRule c9 0 [ Seq.Rule 2
+    testRule c9 0 [ Seq.Rule 2 S.empty
                   , Seq.Literal 'd'
-                  , Seq.Rule 1
-                  , Seq.Rule 2
+                  , Seq.Rule 1 S.empty
+                  , Seq.Rule 2 S.empty
                   ]
     testRule c9 1 [ Seq.Literal 'b', Seq.Literal 'c' ]
-    testRule c9 2 [ Seq.Literal 'a', Seq.Rule 1 ]
+    testRule c9 2 [ Seq.Literal 'a', Seq.Rule 1 S.empty ]
     assertEqual "rule count" 3 $ Seq.ruleCount c9
 
     -- abcdbcabcd
     let c10 = Seq.feed c9 'd'
-    testRule c10 0 [ Seq.Rule 3
-                   , Seq.Rule 1
-                   , Seq.Rule 3
+    testRule c10 0 [ Seq.Rule 3 S.empty
+                   , Seq.Rule 1 S.empty
+                   , Seq.Rule 3 S.empty
                    ]
     testRule c10 1 [ Seq.Literal 'b', Seq.Literal 'c' ]
-    testRule c10 3 [ Seq.Literal 'a', Seq.Rule 1, Seq.Literal 'd' ]
+    testRule c10 3 [ Seq.Literal 'a', Seq.Rule 1 S.empty, Seq.Literal 'd' ]
     assertEqual "rule count" 3 $ Seq.ruleCount c10
     )
 
 
 test_ababcabcdabcdeabcdef = TestCase (do
     let compress = Seq.compress "ababcabcdabcdeabcdef"
-    testRule compress 0 [ Seq.Rule 1
-                        , Seq.Rule 2
-                        , Seq.Rule 3
-                        , Seq.Rule 4
-                        , Seq.Rule 4
+    testRule compress 0 [ Seq.Rule 1 S.empty
+                        , Seq.Rule 2 S.empty
+                        , Seq.Rule 3 S.empty
+                        , Seq.Rule 4 S.empty
+                        , Seq.Rule 4 S.empty
                         , Seq.Literal 'f'
                         ]
     testRule compress 1 [ Seq.Literal 'a', Seq.Literal 'b' ]
-    testRule compress 2 [ Seq.Rule 1, Seq.Literal 'c' ]
-    testRule compress 3 [ Seq.Rule 2, Seq.Literal 'd' ]
-    testRule compress 4 [ Seq.Rule 3, Seq.Literal 'e' ])
+    testRule compress 2 [ Seq.Rule 1 S.empty, Seq.Literal 'c' ]
+    testRule compress 3 [ Seq.Rule 2 S.empty, Seq.Literal 'd' ]
+    testRule compress 4 [ Seq.Rule 3 S.empty, Seq.Literal 'e' ])
 
 test_yzxyzwxyzvwxy = TestCase (do
     let compress = Seq.compress "yzxyzwxyzvwxy"
-    testRule compress 0 [ Seq.Rule 1
-                        , Seq.Rule 2
+    testRule compress 0 [ Seq.Rule 1 S.empty
+                        , Seq.Rule 2 S.empty
                         , Seq.Literal 'w'
-                        , Seq.Rule 2
+                        , Seq.Rule 2 S.empty
                         , Seq.Literal 'v'
                         , Seq.Literal 'w'
                         , Seq.Literal 'x'
                         , Seq.Literal 'y'
                         ]
     testRule compress 1 [ Seq.Literal 'y', Seq.Literal 'z' ]
-    testRule compress 2 [ Seq.Literal 'x', Seq.Rule 1 ])
+    testRule compress 2 [ Seq.Literal 'x', Seq.Rule 1 S.empty ])
 
 
 tests = TestList [ TestLabel "test: abcdbc" test_abcdbc

File src/Data/Sequitur.hs

 
 -- | This is a Symbol in a rule.
 data Symbol a =
-      Literal a         -- A literal input symbol.
-    | Rule Integer      -- A rule.
+      Literal a                 -- A literal input symbol.
+    | Rule Integer (RuleBody a) -- A rule.
     deriving (Show, Eq)
 
 -- | This is a rule's body