Skip to content

Commit

Permalink
fix: use raw strings for regex (#82)
Browse files Browse the repository at this point in the history
Closes #66
  • Loading branch information
StoneyJackson authored Nov 21, 2023
1 parent 3940c1a commit 33577a4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/plcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def lex(nxt):
# turn off when all flags have been processed
flagSwitch = True # turn off after all the flags have been processed
for line in nxt:
line = re.sub('\s+#.*', '', line) # remove trailing comments ...
line = re.sub(r'\s+#.*', '', line) # remove trailing comments ...
# NOTE: a token that has a substring like this ' #' will mistakenly be
# considered as a comment. Use '[ ]#' instead
line = line.strip()
Expand Down Expand Up @@ -174,7 +174,7 @@ def qsub(match):
jpat = match.group(1)
# print('>>> match found: jpat={}'.format(jpat))
return ''
pat = "\s'(.*)'$"
pat = r"\s'(.*)'$"
# print('>>> q1 pat={}'.format(pat))
line = re.sub(pat, qsub, line)
if jpat:
Expand All @@ -184,7 +184,7 @@ def qsub(match):
# print('>>> q1 match found: line={} jpat={}'.format(line,jpat))
pass
else:
pat = '\s"(.*)"$'
pat = r'\s"(.*)"$'
# print('>>> q2 pat={}'.format(pat))
line = re.sub(pat, qsub, line)
if jpat:
Expand Down Expand Up @@ -1208,19 +1208,19 @@ def defangRHS(item):
return (tnt, field)

def isID(item):
return re.match('[a-z]\w*#?$', item)
return re.match(r'[a-z]\w*#?$', item)

def isNonterm(nt):
debug('[isNonterm] nt={}'.format(nt))
if nt == 'void' or len(nt) == 0:
return False
return re.match('[a-z]\w*#?$', nt)
return re.match(r'[a-z]\w*#?$', nt)

def isClass(cls):
return re.match('[A-Z][\$\w]*$', cls) or cls == 'void'
return re.match(r'[A-Z][\$\w]*$', cls) or cls == 'void'

def isTerm(term):
return re.match('[A-Z][A-Z\d_$]*$', term) or term == '$LINE'
return re.match(r'[A-Z][A-Z\d_$]*$', term) or term == '$LINE'

def nt2cls(nt):
# return the class name of the nonterminal nt
Expand Down

0 comments on commit 33577a4

Please sign in to comment.