Skip to content

Commit

Permalink
fix #204: fix removal of duplicate matches
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Jun 30, 2024
1 parent 37ff460 commit 762c03b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/asm/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,20 @@ pub fn match_instr(
.collect::<Vec<_>>();


// Identical duplicate matches are already sorted consecutively
matches.dedup_by(|a, b| a.is_same(b));
// Remove duplicate matches
for i in (0..matches.len()).rev()
{
let mut duplicate = false;
for j in 0..i
{
duplicate |= matches[i].is_same(&matches[j]);
}

if duplicate
{
matches.remove(i);
}
}


// Calculate recursive "exact" pattern-part count for
Expand Down
21 changes: 21 additions & 0 deletions tests/issue204/ok.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ruledef foo
{
f{e:u4} => e
f{e:u4}+{m:foo} => e @ m
}

#ruledef bar
{
|{f:foo}| => 0xa @ f
){f:foo}( => 0xb @ f
]{f:foo}[ => 0xc @ f
({f:foo}) => 0xd @ f
[{f:foo}] => 0xe @ f
}

f1+f2+f3+f4 ; = 0x1234
|f1+f2+f3+f4| ; = 0xa1234
)f1+f2+f3+f4( ; = 0xb1234
]f1+f2+f3+f4[ ; = 0xc1234
(f1+f2+f3+f4) ; = 0xd1234
[f1+f2+f3+f4] ; = 0xe1234

0 comments on commit 762c03b

Please sign in to comment.