Use raw strings in preproc.py
Avoids "SyntaxWarning: invalid escape sequence" with Python 3.12.
This commit is contained in:
parent
b08c785c1d
commit
8a93d6136b
|
|
@ -59,13 +59,13 @@ import sys
|
|||
|
||||
def solve_statement(condition):
|
||||
|
||||
defrex = re.compile('defined[ \t]*\(([^\)]+)\)')
|
||||
orrex = re.compile('(.+)\|\|(.+)')
|
||||
andrex = re.compile('(.+)&&(.+)')
|
||||
notrex = re.compile('!([^&\|]+)')
|
||||
parenrex = re.compile('\(([^\)]+)\)')
|
||||
leadspacerex = re.compile('^[ \t]+(.*)')
|
||||
endspacerex = re.compile('(.*)[ \t]+$')
|
||||
defrex = re.compile(r'defined[ \t]*\(([^\)]+)\)')
|
||||
orrex = re.compile(r'(.+)\|\|(.+)')
|
||||
andrex = re.compile(r'(.+)&&(.+)')
|
||||
notrex = re.compile(r'!([^&\|]+)')
|
||||
parenrex = re.compile(r'\(([^\)]+)\)')
|
||||
leadspacerex = re.compile(r'^[ \t]+(.*)')
|
||||
endspacerex = re.compile(r'(.*)[ \t]+$')
|
||||
|
||||
matchfound = True
|
||||
while matchfound:
|
||||
|
|
@ -165,24 +165,24 @@ def sortkeys(keys):
|
|||
|
||||
def runpp(keys, keyrex, defines, ccomm, incdirs, inputfile, ofile):
|
||||
|
||||
includerex = re.compile('^[ \t]*#include[ \t]+"*([^ \t\n\r"]+)')
|
||||
definerex = re.compile('^[ \t]*#define[ \t]+([^ \t]+)[ \t]+(.+)')
|
||||
paramrex = re.compile('^([^\(]+)\(([^\)]+)\)')
|
||||
defrex = re.compile('^[ \t]*#define[ \t]+([^ \t\n\r]+)')
|
||||
undefrex = re.compile('^[ \t]*#undef[ \t]+([^ \t\n\r]+)')
|
||||
ifdefrex = re.compile('^[ \t]*#ifdef[ \t]+(.+)')
|
||||
ifndefrex = re.compile('^[ \t]*#ifndef[ \t]+(.+)')
|
||||
ifrex = re.compile('^[ \t]*#if[ \t]+(.+)')
|
||||
elseifrex = re.compile('^[ \t]*#elseif[ \t]+(.+)')
|
||||
elserex = re.compile('^[ \t]*#else')
|
||||
endifrex = re.compile('^[ \t]*#endif')
|
||||
commentrex = re.compile('^###[^#]*$')
|
||||
ccstartrex = re.compile('/\*') # C-style comment start
|
||||
ccendrex = re.compile('\*/') # C-style comment end
|
||||
contrex = re.compile('.*\\\\$') # Backslash continuation line
|
||||
includerex = re.compile(r'^[ \t]*#include[ \t]+"*([^ \t\n\r"]+)')
|
||||
definerex = re.compile(r'^[ \t]*#define[ \t]+([^ \t]+)[ \t]+(.+)')
|
||||
paramrex = re.compile(r'^([^\(]+)\(([^\)]+)\)')
|
||||
defrex = re.compile(r'^[ \t]*#define[ \t]+([^ \t\n\r]+)')
|
||||
undefrex = re.compile(r'^[ \t]*#undef[ \t]+([^ \t\n\r]+)')
|
||||
ifdefrex = re.compile(r'^[ \t]*#ifdef[ \t]+(.+)')
|
||||
ifndefrex = re.compile(r'^[ \t]*#ifndef[ \t]+(.+)')
|
||||
ifrex = re.compile(r'^[ \t]*#if[ \t]+(.+)')
|
||||
elseifrex = re.compile(r'^[ \t]*#elseif[ \t]+(.+)')
|
||||
elserex = re.compile(r'^[ \t]*#else')
|
||||
endifrex = re.compile(r'^[ \t]*#endif')
|
||||
commentrex = re.compile(r'^###[^#]*$')
|
||||
ccstartrex = re.compile(r'/\*') # C-style comment start
|
||||
ccendrex = re.compile(r'\*/') # C-style comment end
|
||||
contrex = re.compile(r'.*\\$') # Backslash continuation line
|
||||
|
||||
badifrex = re.compile('^[ \t]*#if[ \t]*.*')
|
||||
badelserex = re.compile('^[ \t]*#else[ \t]*.*')
|
||||
badifrex = re.compile(r'^[ \t]*#if[ \t]*.*')
|
||||
badelserex = re.compile(r'^[ \t]*#else[ \t]*.*')
|
||||
|
||||
# This code is not designed to operate on huge files. Neither is it designed to be
|
||||
# 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
|
||||
# handled.
|
||||
|
||||
pcondition = condition + '\('
|
||||
pcondition = condition + r'\('
|
||||
for param in parameters[0:-1]:
|
||||
pcondition += '(.*),'
|
||||
pcondition += '(.*)\)'
|
||||
pcondition += r'(.*),'
|
||||
pcondition += r'(.*)\)'
|
||||
|
||||
# Generate the substitution string with group substitutions
|
||||
pvalue = pmatch.group(2)
|
||||
idx = 1
|
||||
for param in parameters:
|
||||
pvalue = pvalue.replace(param, '\g<' + str(idx) + '>')
|
||||
pvalue = pvalue.replace(param, r'\g<' + str(idx) + r'>')
|
||||
idx = idx + 1
|
||||
|
||||
defines[condition] = pvalue
|
||||
|
|
|
|||
Loading…
Reference in New Issue