1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
From 38a54af87bf29f9a830d1b2636d28018a7a7a527 Mon Sep 17 00:00:00 2001
From: Mike Swanson <mikeonthecomputer@gmail.com>
Date: Sat, 3 Aug 2024 10:20:21 -0700
Subject: [PATCH] man/docgen: Use raw string literals for regular expressions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Regular expressions use the \ character frequently as part of their
normal operations, but Python tries to interpret them in standard
strings as escape sequences. It especially complained about “invalid
escape sequence” \s, \S, and \#. Using raw strings forces Python to
make no attempt to parse escape sequences and they instead get passed
directly into the re library.
---
man/docgen | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/man/docgen b/man/docgen
index 19e3b4bca..dffc1d6ab 100755
--- a/man/docgen
+++ b/man/docgen
@@ -36,7 +36,7 @@ import glob
import getopt
TEXT_WRAP_WIDTH = 78
-INCLUDE_STATEMENT_RE = re.compile("@include\s+(\S+)")
+INCLUDE_STATEMENT_RE = re.compile(r"@include\s+(\S+)")
# Use appropriate stdout function for Python 2 or 3
@@ -209,7 +209,7 @@ class Parameter:
if len(text) <= 0:
pass
elif text[0] == "@":
- match = re.match('@(\S+)\s*(.*)', text)
+ match = re.match(r'@(\S+)\s*(.*)', text)
if not match:
raise "Malformed option line: %s" % text
@@ -253,7 +253,7 @@ class Parameter:
if self.platform:
result += "[%s only] " % self.platform
- escaped = re.sub('\\\\', '\\\\\\\\', self.text)
+ escaped = re.sub(r'\\', r'\\\\', self.text)
result += escaped + self._games_only_text() + "\n"
@@ -315,7 +315,7 @@ class Parameter:
# Build the complete text for the argument
# Split the description into words and add a word at a time
result = ""
- words = [word for word in re.split('\s+', description) if word]
+ words = [word for word in re.split(r'\s+', description) if word]
maxlen = TEXT_WRAP_WIDTH - indent
outlines = [[]]
for word in words:
@@ -345,7 +345,7 @@ def read_wikipages():
for line in f:
line = line.rstrip()
- line = re.sub('\#.*$', '', line)
+ line = re.sub(r'\#.*$', '', line)
if not re.match(r'^\s*$', line):
wikipages.append(line)
@@ -378,7 +378,7 @@ def add_parameter(param, line, config_file):
# Is this documenting a command line parameter?
- match = re.search('(M_CheckParm(WithArgs)|M_ParmExists)?\s*\(\s*"(.*?)"',
+ match = re.search(r'(M_CheckParm(WithArgs)|M_ParmExists)?\s*\(\s*"(.*?)"',
line)
if match:
@@ -389,7 +389,7 @@ def add_parameter(param, line, config_file):
# Documenting a configuration file variable?
- match = re.search('CONFIG_VARIABLE_\S+\s*\(\s*(\S+?)\),', line)
+ match = re.search(r'CONFIG_VARIABLE_\S+\s*\(\s*(\S+?)\),', line)
if match:
param.name = match.group(1)
@@ -413,7 +413,7 @@ def process_file(filename):
# Ignore empty lines
- if re.match('\s*$', line):
+ if re.match(r'\s*$', line):
continue
# Currently reading a doc comment?
@@ -421,7 +421,7 @@ def process_file(filename):
if param:
# End of doc comment
- if not re.match('\s*//', line):
+ if not re.match(r'\s*//', line):
waiting_for_checkparm = True
# The first non-empty line after the documentation comment
@@ -433,14 +433,14 @@ def process_file(filename):
else:
# More documentation text
- munged_line = re.sub('\s*\/\/\s*', '', line, 1)
- munged_line = re.sub('\s*$', '', munged_line)
+ munged_line = re.sub(r'\s*\/\/\s*', '', line, 1)
+ munged_line = re.sub(r'\s*$', '', munged_line)
param.add_text(munged_line)
# Check for start of a doc comment
if re.search("//!", line):
- match = re.search("@begin_config_file\s*(\S+)", line)
+ match = re.search(r"@begin_config_file\s*(\S+)", line)
if match:
# Beginning a configuration file
--
2.46.0
|