Use raw strings in preproc.py

Avoids "SyntaxWarning: invalid escape sequence" with Python 3.12.
This commit is contained in:
Ryan Carsten Schmidt 2024-01-23 09:38:23 -06:00 committed by GitHub
parent b08c785c1d
commit 8a93d6136b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 28 deletions

View File

@ -59,13 +59,13 @@ import sys
def solve_statement(condition): def solve_statement(condition):
defrex = re.compile('defined[ \t]*\(([^\)]+)\)') defrex = re.compile(r'defined[ \t]*\(([^\)]+)\)')
orrex = re.compile('(.+)\|\|(.+)') orrex = re.compile(r'(.+)\|\|(.+)')
andrex = re.compile('(.+)&&(.+)') andrex = re.compile(r'(.+)&&(.+)')
notrex = re.compile('!([^&\|]+)') notrex = re.compile(r'!([^&\|]+)')
parenrex = re.compile('\(([^\)]+)\)') parenrex = re.compile(r'\(([^\)]+)\)')
leadspacerex = re.compile('^[ \t]+(.*)') leadspacerex = re.compile(r'^[ \t]+(.*)')
endspacerex = re.compile('(.*)[ \t]+$') endspacerex = re.compile(r'(.*)[ \t]+$')
matchfound = True matchfound = True
while matchfound: while matchfound:
@ -165,24 +165,24 @@ def sortkeys(keys):
def runpp(keys, keyrex, defines, ccomm, incdirs, inputfile, ofile): def runpp(keys, keyrex, defines, ccomm, incdirs, inputfile, ofile):
includerex = re.compile('^[ \t]*#include[ \t]+"*([^ \t\n\r"]+)') includerex = re.compile(r'^[ \t]*#include[ \t]+"*([^ \t\n\r"]+)')
definerex = re.compile('^[ \t]*#define[ \t]+([^ \t]+)[ \t]+(.+)') definerex = re.compile(r'^[ \t]*#define[ \t]+([^ \t]+)[ \t]+(.+)')
paramrex = re.compile('^([^\(]+)\(([^\)]+)\)') paramrex = re.compile(r'^([^\(]+)\(([^\)]+)\)')
defrex = re.compile('^[ \t]*#define[ \t]+([^ \t\n\r]+)') defrex = re.compile(r'^[ \t]*#define[ \t]+([^ \t\n\r]+)')
undefrex = re.compile('^[ \t]*#undef[ \t]+([^ \t\n\r]+)') undefrex = re.compile(r'^[ \t]*#undef[ \t]+([^ \t\n\r]+)')
ifdefrex = re.compile('^[ \t]*#ifdef[ \t]+(.+)') ifdefrex = re.compile(r'^[ \t]*#ifdef[ \t]+(.+)')
ifndefrex = re.compile('^[ \t]*#ifndef[ \t]+(.+)') ifndefrex = re.compile(r'^[ \t]*#ifndef[ \t]+(.+)')
ifrex = re.compile('^[ \t]*#if[ \t]+(.+)') ifrex = re.compile(r'^[ \t]*#if[ \t]+(.+)')
elseifrex = re.compile('^[ \t]*#elseif[ \t]+(.+)') elseifrex = re.compile(r'^[ \t]*#elseif[ \t]+(.+)')
elserex = re.compile('^[ \t]*#else') elserex = re.compile(r'^[ \t]*#else')
endifrex = re.compile('^[ \t]*#endif') endifrex = re.compile(r'^[ \t]*#endif')
commentrex = re.compile('^###[^#]*$') commentrex = re.compile(r'^###[^#]*$')
ccstartrex = re.compile('/\*') # C-style comment start ccstartrex = re.compile(r'/\*') # C-style comment start
ccendrex = re.compile('\*/') # C-style comment end ccendrex = re.compile(r'\*/') # C-style comment end
contrex = re.compile('.*\\\\$') # Backslash continuation line contrex = re.compile(r'.*\\$') # Backslash continuation line
badifrex = re.compile('^[ \t]*#if[ \t]*.*') badifrex = re.compile(r'^[ \t]*#if[ \t]*.*')
badelserex = re.compile('^[ \t]*#else[ \t]*.*') badelserex = re.compile(r'^[ \t]*#else[ \t]*.*')
# This code is not designed to operate on huge files. Neither is it designed to be # This code is not designed to operate on huge files. Neither is it designed to be
# efficient. # efficient.
@ -414,16 +414,16 @@ def runpp(keys, keyrex, defines, ccomm, incdirs, inputfile, ofile):
# parentheses; e.g., "def(a, b, (c1,c2))". This is NOT # parentheses; e.g., "def(a, b, (c1,c2))". This is NOT
# handled. # handled.
pcondition = condition + '\(' pcondition = condition + r'\('
for param in parameters[0:-1]: for param in parameters[0:-1]:
pcondition += '(.*),' pcondition += r'(.*),'
pcondition += '(.*)\)' pcondition += r'(.*)\)'
# Generate the substitution string with group substitutions # Generate the substitution string with group substitutions
pvalue = pmatch.group(2) pvalue = pmatch.group(2)
idx = 1 idx = 1
for param in parameters: for param in parameters:
pvalue = pvalue.replace(param, '\g<' + str(idx) + '>') pvalue = pvalue.replace(param, r'\g<' + str(idx) + r'>')
idx = idx + 1 idx = idx + 1
defines[condition] = pvalue defines[condition] = pvalue