Skip to content

Commit

Permalink
fix shortcut patsubs with empty pattern
Browse files Browse the repository at this point in the history
oops; forgot to commit the actual fix last commit
  • Loading branch information
linuxlizard committed Jun 26, 2023
1 parent c345abe commit 591c2c4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pymake/symtablemk.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,15 @@ def _parse_abbrev_patsubst(self, key):
def _eval_abbrev_patsubst(self, key):
# allow exception(s) to propagate
varname, pat1, pat2 = self._parse_abbrev_patsubst(key)
# logger.debug("abbrev varname=%r pat1=%r pat2=%4", varname, pat1, pat2)

pat1_len = len(pat1)
def maybe_replace(s,pat1,pat2):
if s.endswith(pat1):
return s[:-pat1_len] + pat2
return s
value = self.fetch(varname)
new_value = " ".join([maybe_replace(s,pat1,pat2) for s in value.split()])
if pat1_len == 0:
# pat1 empty so it's a simple append operation
return " ".join([s+pat2 for s in value.split()])

new_value = " ".join([s[:-pat1_len] + pat2 if s.endswith(pat1) else s for s in value.split()])
return new_value

def fetch(self, key, pos=None):
Expand Down

0 comments on commit 591c2c4

Please sign in to comment.