Skip to content

Commit ec8567f

Browse files
committed
Fix the quirk
1 parent b18f149 commit ec8567f

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

‎addons/cppcheckdata.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ class CompiledPattern:
15991599
failed The MatchResult returned when the pattern does not match
16001600
"""
16011601

1602-
_literal_atoms = frozenset(['!', '|', '||', '%', '!=', '*'])
1602+
_literal_atoms = frozenset(['!', '|', '||', '|=', '%', '!=', '*'])
16031603
_link_open = frozenset(['(', '[', '<', '{'])
16041604

16051605
def __init__(self, pattern):
@@ -1641,7 +1641,7 @@ def compile_atom(cls, p):
16411641
if p in patterns:
16421642
return patterns[p]
16431643
if '|' in p:
1644-
return cls._match_alternatives(p, [cls.compile_atom(x) for x in p.split('|')])
1644+
return cls._match_alternatives([cls.compile_atom(x) for x in p.split('|')])
16451645
if p.startswith('!!'):
16461646
return cls._match_negation(cls.compile_atom(p[2:]))
16471647
if p.startswith('**'):
@@ -1659,11 +1659,8 @@ def m(tok):
16591659
return m
16601660

16611661
@staticmethod
1662-
def _match_alternatives(p, alternatives):
1662+
def _match_alternatives(alternatives):
16631663
def m(tok):
1664-
# a token whose str contains '|' (such as '|=') matches the whole word
1665-
if tok.str == p:
1666-
return tok
16671664
for a in alternatives:
16681665
t = a(tok)
16691666
if t:

‎test/addon/test_cppcheckdata.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ def test_literal_or_assign(self, match_cfg):
559559
assert cppcheckdata.match(or_assign.previous, '%var% |= %var% ;')
560560
assert cppcheckdata.match(or_assign, '%assign%')
561561
assert not cppcheckdata.match(find_token(match_cfg, '|'), '|=')
562-
# quirk, shared with the C++ Token::Match: the '|' in '|=' is also
563-
# read as an alternation of '' and '=', so a '=' token matches too
564-
assert cppcheckdata.match(find_token(match_cfg, '='), '|=')
562+
# '|=' is a literal, not an alternation of '' and '='
563+
# (unlike the C++ Token::Match, which also matches a '=' token here)
564+
assert not cppcheckdata.match(find_token(match_cfg, '='), '|=')
565565

566566
def test_whitespace_only_pattern(self, match_cfg):
567567
calc_def = find_token(match_cfg, 'calc')

0 commit comments

Comments
 (0)