Skip to content

Commit 01f0402

Browse files
emarzionMirceaS
andauthored
adding match for And (#2435)
* adding match for And * Format with stylish-haskell * trigger build * adding unit tests * fix merge * moving matchAnd after matchEqualHeads Co-authored-by: emarzion <[email protected]> Co-authored-by: Octavian Mircea Sebe <[email protected]>
1 parent b49fdd3 commit 01f0402

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

kore/src/Kore/Step/Axiom/Matcher.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ matchOne
176176
matchOne pair =
177177
( matchVariable pair
178178
<|> matchEqualHeads pair
179+
<|> matchAnd pair
179180
<|> matchExists pair
180181
<|> matchForall pair
181182
<|> matchApplication pair
@@ -443,6 +444,15 @@ matchDefined (Pair term1 term2)
443444
| Defined_ def2 <- term2 = push (Pair term1 def2)
444445
| otherwise = empty
445446

447+
matchAnd
448+
:: (MatchingVariable variable, MonadSimplify simplifier)
449+
=> Pair (TermLike variable)
450+
-> MaybeT (MatcherT variable simplifier) ()
451+
matchAnd (Pair term1 term2)
452+
| And_ _ conj1 conj2 <- term1 =
453+
push (Pair conj1 term2) >> push (Pair conj2 term2)
454+
| otherwise = empty
455+
446456
-- * Implementation
447457

448458
type MatchingVariable variable = InternalVariable variable

kore/test/Test/Kore/Step/Axiom/Matcher.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Test.Kore.Step.Axiom.Matcher
1515
, test_matching_Exists
1616
, test_matching_Forall
1717
, test_matching_Equals
18+
, test_matching_And
1819
, test_matcherOverloading
1920
, match
2021
, MatchResult
@@ -778,6 +779,32 @@ test_matching_Pair =
778779
[(inject xInt, mkElemVar zInt), (inject yInt, mkElemVar zInt)]
779780
]
780781

782+
test_matching_And :: [TestTree]
783+
test_matching_And =
784+
[ matches "and(x, x) matches x"
785+
(mkAnd (mkElemVar xInt) (mkElemVar xInt))
786+
(mkElemVar xInt)
787+
[]
788+
, matches "and(x, y) matches y"
789+
(mkAnd (mkElemVar xInt) (mkElemVar yInt))
790+
(mkElemVar yInt)
791+
[(inject xInt, mkElemVar yInt)]
792+
, matches "and(y, x) matches y"
793+
(mkAnd (mkElemVar yInt) (mkElemVar xInt))
794+
(mkElemVar yInt)
795+
[(inject xInt, mkElemVar yInt)]
796+
, matches "and(x, y) matches z"
797+
(mkAnd (mkElemVar xInt) (mkElemVar yInt))
798+
(mkElemVar zInt)
799+
[(inject xInt, mkElemVar zInt), (inject yInt, mkElemVar zInt)]
800+
, doesn'tMatch "and(x, 1) does not match 2"
801+
(mkAnd (mkElemVar xInt) (mkInt 1))
802+
(mkInt 2)
803+
, doesn'tMatch "and(1, x) does not match 2"
804+
(mkAnd (mkInt 1) (mkElemVar xInt))
805+
(mkInt 2)
806+
]
807+
781808
mkPair
782809
:: TermLike RewritingVariableName
783810
-> TermLike RewritingVariableName

0 commit comments

Comments
 (0)