From 8a93d6136b0a32cc6543d4761fb4fd5c5ff9a428 Mon Sep 17 00:00:00 2001 From: Ryan Carsten Schmidt Date: Tue, 23 Jan 2024 09:38:23 -0600 Subject: [PATCH] Use raw strings in preproc.py Avoids "SyntaxWarning: invalid escape sequence" with Python 3.12. --- scripts/preproc.py | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/scripts/preproc.py b/scripts/preproc.py index 1fca5bef..14269c26 100755 --- a/scripts/preproc.py +++ b/scripts/preproc.py @@ -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