From 47f34e0cffc2da3ae0dfdf6cba95f7f9d992eb2f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 28 Mar 2024 22:57:38 +0100 Subject: [PATCH] doc: use raw strings for regular expressions in python --- doc/manual/markdown2tex.py | 12 +++--- doc/manual/markdown_create_apis.py | 22 +++++----- doc/manual/markdown_create_examples.py | 42 +++++++++---------- ...rkdown_create_gatt_services_and_clients.py | 18 ++++---- doc/manual/markdown_create_ports.py | 10 ++--- doc/manual/markdown_update_references.py | 16 +++---- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/doc/manual/markdown2tex.py b/doc/manual/markdown2tex.py index 89b7bdefe..77719453b 100755 --- a/doc/manual/markdown2tex.py +++ b/doc/manual/markdown2tex.py @@ -18,20 +18,20 @@ figures = { def fix_empty_href(line): - corr = re.match('.*(href{}).*',line) + corr = re.match(r'.*(href{}).*',line) if corr: line = line.replace(corr.group(1), "path") return line def fix_listing_after_section(line): - corr = re.match('.*begin{lstlisting}',line) + corr = re.match(r'.*begin{lstlisting}',line) if corr: line = "\leavevmode" + line return line def fix_listing_hyperref_into_ref(line): - corr = re.match('(.*\\\\)hyperref\[(lst:.*)\]{.*}(.*)',line) + corr = re.match(r'.*\\)hyperref\[(lst:.*)\]{.*}(.*)',line) if corr: line = corr.group(1)+"ref{" + corr.group(2) +"} " + corr.group(3) return line @@ -40,14 +40,14 @@ def fix_listing_hyperref_into_ref(line): def fix_figure_width_and_type(line): global figures for name, width in figures.items(): - corr = re.match('(.*includegraphics)(.*'+name+'.*)',line) + corr = re.match(r'(.*includegraphics)(.*'+name+'.*)',line) if corr: line = corr.group(1) + '[width='+width+'\\textwidth]' + corr.group(2).replace('png','pdf') return line def fix_appendix_pagebreak(line): - corr = re.match('.*section{APIs}.*',line) + corr = re.match(r'.*section{APIs}.*',line) if corr: line = "\leavevmode\pagebreak\n" + line return line @@ -67,7 +67,7 @@ def postprocess_file(markdown_filepath, fout, title): # remove path from section reference # e.g. [the SPP Counter example](examples/generated/#sec:sppcounterExample) # replace with [the SPP Counter example](#sec:sppcounterExample) - section_ref = re.match('.*\(((.*)(#sec:.*))\).*',line) + section_ref = re.match(r'.*\(((.*)(#sec:.*))\).*',line) if section_ref: line = line.replace(section_ref.group(2),"") fout.write(line) diff --git a/doc/manual/markdown_create_apis.py b/doc/manual/markdown_create_apis.py index cb1ba872e..35af02112 100755 --- a/doc/manual/markdown_create_apis.py +++ b/doc/manual/markdown_create_apis.py @@ -38,13 +38,13 @@ api_description = """ code_ref = """GITHUB/FPATH#LLINENR""" def isEndOfComment(line): - return re.match('\s*\*/.*', line) + return re.match(r'\s*\*/.*', line) def isStartOfComment(line): - return re.match('\s*\/\*/.*', line) + return re.match(r'\s*\/\*/.*', line) def isTypedefStart(line): - return re.match('.*typedef\s+struct.*', line) + return re.match(r'.*typedef\s+struct.*', line) def codeReference(fname, githuburl, filename_without_extension, filepath, linenr): global code_ref @@ -54,11 +54,11 @@ def codeReference(fname, githuburl, filename_without_extension, filepath, linenr return ref def isTagAPI(line): - return re.match('(.*)(-\s*\')(APIs).*',line) + return re.match(r'(.*)(-\s*\')(APIs).*',line) def getSecondLevelIdentation(line): indentation = "" - parts = re.match('(.*)(-\s*\')(APIs).*',line) + parts = re.match(r'(.*)(-\s*\')(APIs).*',line) if parts: # return double identation for the submenu indentation = parts.group(1) + parts.group(1) + "- " @@ -132,19 +132,19 @@ def createIndex(fin, filename, api_filepath, api_title, api_label, githuburl): # search typedef struct end if typedefFound: - typedef = re.match('}\s*(.*);\n', line) + typedef = re.match(r'}\s*(.*);\n', line) if typedef: typedefFound = 0 typedefs[typedef.group(1)] = codeReference(typedef.group(1), githuburl, filename, api_filepath, linenr) continue - ref_function = re.match('.*typedef\s+void\s+\(\s*\*\s*(.*?)\)\(.*', line) + ref_function = re.match(r'.*typedef\s+void\s+\(\s*\*\s*(.*?)\)\(.*', line) if ref_function: functions[ref_function.group(1)] = codeReference(ref_function.group(1), githuburl, filename, api_filepath, linenr) continue - one_line_function_definition = re.match('(.*?)\s*\(.*\(*.*;\n', line) + one_line_function_definition = re.match(r'(.*?)\s*\(.*\(*.*;\n', line) if one_line_function_definition: parts = one_line_function_definition.group(1).split(" "); name = parts[len(parts)-1] @@ -154,7 +154,7 @@ def createIndex(fin, filename, api_filepath, api_title, api_label, githuburl): functions[name] = codeReference( name, githuburl, filename, api_filepath, linenr) continue - multi_line_function_definition = re.match('.(.*?)\s*\(.*\(*.*', line) + multi_line_function_definition = re.match(r'.(.*?)\s*\(.*\(*.*', line) if multi_line_function_definition: parts = multi_line_function_definition.group(1).split(" "); @@ -176,7 +176,7 @@ def findTitle(fin): if isStartOfComment(line): continue - parts = re.match('.*(@title)(.*)', line) + parts = re.match(r'.*(@title)(.*)', line) if parts: title = parts.group(2).strip() state = State.SearchEndTitle @@ -187,7 +187,7 @@ def findTitle(fin): state = State.DoneAPI break - parts = re.match('(\s*\*\s*)(.*\n)',line) + parts = re.match(r'(\s*\*\s*)(.*\n)',line) if parts: desc = desc + parts.group(2) return [title, desc] diff --git a/doc/manual/markdown_create_examples.py b/doc/manual/markdown_create_examples.py index 6d5a6a372..fec6f98bf 100755 --- a/doc/manual/markdown_create_examples.py +++ b/doc/manual/markdown_create_examples.py @@ -101,40 +101,40 @@ def latexText(text, ref_prefix): return "" brief = text.replace(" in the BTstack manual","") - refs = re.match('.*(Listing\s+)(\w+).*',brief) + refs = re.match(r'.*(Listing\s+)(\w+).*',brief) if refs: brief = brief.replace(refs.group(2), "[here](#lst:"+ref_prefix + refs.group(2)+")") return brief def isEmptyCommentLine(line): - return re.match('(\s*\*\s*)\n',line) + return re.match(r'(\s*\*\s*)\n',line) def isCommentLine(line): - return re.match('(\s*\*\s*).*',line) + return re.match(r'(\s*\*\s*).*',line) def isEndOfComment(line): - return re.match('\s*\*/.*', line) + return re.match(r'\s*\*/.*', line) def isNewItem(line): - return re.match('(\s*\*\s*\-\s*)(.*)',line) + return re.match(r'(\s*\*\s*\-\s*)(.*)',line) def isTextTag(line): - return re.match('.*(@text).*', line) + return re.match(r'.*(@text).*', line) def isItemizeTag(line): - return re.match("(\s+\*\s+)(-\s)(.*)", line) + return re.match(r'(\s+\*\s+)(-\s)(.*)', line) def processTextLine(line, ref_prefix): if isTextTag(line): - text_line_parts = re.match(".*(@text)(.*)", line) + text_line_parts = re.match(r'.*(@text)(.*)', line) return " " + latexText(text_line_parts.group(2), ref_prefix) if isItemizeTag(line): - text_line_parts = re.match("(\s*\*\s*\-\s*)(.*)", line) + text_line_parts = re.match(r'(\s*\*\s*\-\s*)(.*)', line) return "\n- " + latexText(text_line_parts.group(2), ref_prefix) - text_line_parts = re.match("(\s+\*\s+)(.*)", line) + text_line_parts = re.match(r'(\s+\*\s+)(.*)', line) if text_line_parts: return " " + latexText(text_line_parts.group(2), ref_prefix) return "" @@ -143,9 +143,9 @@ def getExampleTitle(example_path): example_title = '' with open(example_path, 'r') as fin: for line in fin: - parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line) + parts = re.match(r'.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line) if parts: - example_title = parts.group(3).replace("_","\_") + example_title = parts.group(3).replace("_",r'\_') continue return example_title @@ -184,7 +184,7 @@ def writeListings(aout, infile_name, ref_prefix, git_branch_name): with open(infile_name, 'r') as fin: for line in fin: if state == State.SearchExampleStart: - parts = re.match('.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line) + parts = re.match(r'.*(EXAMPLE_START)\((.*)\):\s*(.*)(\*/)?\n',line) if parts: label = parts.group(2).replace("_","") title = latexText(parts.group(2), ref_prefix) @@ -194,13 +194,13 @@ def writeListings(aout, infile_name, ref_prefix, git_branch_name): continue # detect @section - section_parts = re.match('.*(@section)\s*(.*)(:?\s*.?)\*?/?\n',line) + section_parts = re.match(r'.*(@section)\s*(.*)(:?\s*.?)\*?/?\n',line) if section_parts: aout.write("\n" + example_subsection.replace("SECTION_TITLE", section_parts.group(2))) continue # detect @subsection - subsection_parts = re.match('.*(@section)\s*(.*)(:?\s*.?)\*?/?\n',line) + subsection_parts = re.match(r'.*(@section)\s*(.*)(:?\s*.?)\*?/?\n',line) if section_parts: subsubsection = example_subsection.replace("SECTION_TITLE", section_parts.group(2)).replace('section', 'subsection') aout.write("\n" + subsubsection) @@ -245,7 +245,7 @@ def writeListings(aout, infile_name, ref_prefix, git_branch_name): #continue if state == State.SearchListingStart: - parts = re.match('.*(LISTING_START)\((.*)\):\s*(.*)(\s+\*/).*',line) + parts = re.match(r'.*(LISTING_START)\((.*)\):\s*(.*)(\s+\*/).*',line) if parts: lst_label = parts.group(2).replace("_","") @@ -257,9 +257,9 @@ def writeListings(aout, infile_name, ref_prefix, git_branch_name): continue if state == State.SearchListingEnd: - parts_end = re.match('.*(LISTING_END).*',line) - parts_pause = re.match('.*(LISTING_PAUSE).*',line) - end_comment_parts = re.match('.*(\*/)\s*\n', line); + parts_end = re.match(r'.*(LISTING_END).*',line) + parts_pause = re.match(r'.*(LISTING_PAUSE).*',line) + end_comment_parts = re.match(r'.*(\*/)\s*\n', line); if parts_end: aout.write(code_in_listing) @@ -278,12 +278,12 @@ def writeListings(aout, infile_name, ref_prefix, git_branch_name): continue if state == State.SearchListingResume: - parts = re.match('.*(LISTING_RESUME).*',line) + parts = re.match(r'.*(LISTING_RESUME).*',line) if parts: state = State.SearchListingEnd continue - parts = re.match('.*(EXAMPLE_END).*',line) + parts = re.match(r'.*(EXAMPLE_END).*',line) if parts: if state != State.SearchListingStart: print("Formating error detected") diff --git a/doc/manual/markdown_create_gatt_services_and_clients.py b/doc/manual/markdown_create_gatt_services_and_clients.py index a3aff7637..7edba06f8 100755 --- a/doc/manual/markdown_create_gatt_services_and_clients.py +++ b/doc/manual/markdown_create_gatt_services_and_clients.py @@ -33,22 +33,22 @@ See [NAME API](../appendix/apis/#REFERENCE). """ def isEmptyCommentLine(line): - return re.match('(\s*\*\s*)\n',line) + return re.match(r'(\s*\*\s*)\n',line) def isCommentLine(line): - return re.match('(\s*\*\s*).*',line) + return re.match(r'(\s*\*\s*).*',line) def isEndOfComment(line): - return re.match('\s*\*/.*', line) + return re.match(r'\s*\*/.*', line) def isNewItem(line): - return re.match('(\s*\*\s*\-\s*)(.*)',line) + return re.match(r'(\s*\*\s*\-\s*)(.*)',line) def isTextTag(line): - return re.match('.*(@text).*', line) + return re.match(r'.*(@text).*', line) def isItemizeTag(line): - return re.match("(\s+\*\s+)(-\s)(.*)", line) + return re.match(r'(\s+\*\s+)(-\s)(.*)', line) def processTextLine(line): if isEmptyCommentLine(line): @@ -57,17 +57,17 @@ def processTextLine(line): line.rstrip() if isTextTag(line): - text_line_parts = re.match(".*(@text\s*)(.*)", line) + text_line_parts = re.match(r'.*(@text\s*)(.*)', line) return text_line_parts.group(2).lstrip() + " " if isItemizeTag(line): - text_line_parts = re.match("(\s*\*\s*\-\s*)(.*)", line) + text_line_parts = re.match(r'(\s*\*\s*\-\s*)(.*)', line) return "- " + text_line_parts.group(2) if isEmptyCommentLine(line): return "\n" - text_line_parts = re.match("(\s+\*\s+)(.*)", line) + text_line_parts = re.match(r'(\s+\*\s+)(.*)', line) if text_line_parts: return text_line_parts.group(2) + " " return "" diff --git a/doc/manual/markdown_create_ports.py b/doc/manual/markdown_create_ports.py index 23f3c06c9..325154a3a 100755 --- a/doc/manual/markdown_create_ports.py +++ b/doc/manual/markdown_create_ports.py @@ -11,7 +11,7 @@ def get_readme_title(example_path): title = '' with open(example_path, 'r') as fin: for line in fin: - parts = re.match('(##\s)(.*)\n',line) + parts = re.match(r'(##\s)(.*)\n',line) if parts: title = parts.group(2) continue @@ -43,7 +43,7 @@ def process_readmes(intro_file, port_folder, ports_file, ports_folder): with open(readme_file, 'r') as fin: for line in fin: # find title, add reference - title_parts = re.match('(#\s+)(.*)\n',line) + title_parts = re.match(r'(#\s+)(.*)\n',line) if title_parts: title = title_parts.group(2) ports.write(port_item.replace("PORT_TITLE", title).replace("PORT_LABEL", readme_dir)) @@ -55,10 +55,10 @@ def process_readmes(intro_file, port_folder, ports_file, ports_folder): with open(readme_file, 'r') as fin: for line in fin: #increase level of indentation - parts = re.match('#(.*)\n',line) + parts = re.match(r'#(.*)\n',line) - title_parts_level1 = re.match('(#\s+)(.*)\n',line) - title_parts_level2 = re.match('(##\s+)(.*)\n',line) + title_parts_level1 = re.match(r'(#\s+)(.*)\n',line) + title_parts_level2 = re.match(r'(##\s+)(.*)\n',line) if parts and title_parts_level1: ports.write("## " + title_parts_level1.group(2) + " {" + "#sec:" + readme_dir + "Port}\n" ) diff --git a/doc/manual/markdown_update_references.py b/doc/manual/markdown_update_references.py index f7a4ade25..c3d90bdc0 100755 --- a/doc/manual/markdown_update_references.py +++ b/doc/manual/markdown_update_references.py @@ -16,7 +16,7 @@ def insert_reference(mdout, text, link): mdout.write("") def process_source_file_link(mdin, mdout, githuburl, line): - parts = re.match('.*(GITHUB_URL).*\n',line) + parts = re.match(r'.*(GITHUB_URL).*\n',line) if parts: line_with_source_file_link = line.replace("GITHUB_URL", githuburl) mdout.write(line_with_source_file_link) @@ -25,7 +25,7 @@ def process_source_file_link(mdin, mdout, githuburl, line): # handlers for various elements def process_section(mdin, mdout, line): - section = re.match('(#+.*){#(sec:.*)}',line) + section = re.match(r'(#+.*){#(sec:.*)}',line) if section: insert_anchor(mdout, section.group(2)) mdout.write(section.group(1)+"\n") @@ -34,7 +34,7 @@ def process_section(mdin, mdout, line): def process_figure(mdin, mdout, line): # detect figure - figure = re.match('\s*(\!.*)({#(fig:.*)})',line) + figure = re.match(r'\s*(\!.*)({#(fig:.*)})',line) if figure: insert_anchor(mdout, figure.group(3)) mdout.write(figure.group(1)+"\n") @@ -43,7 +43,7 @@ def process_figure(mdin, mdout, line): def process_fig_ref(mdin, mdout, line): # detect figure reference - figure_ref = re.match('.*({@(fig:.*)})',line) + figure_ref = re.match(r'.*({@(fig:.*)})',line) if figure_ref: md_reference = "[below](#"+figure_ref.group(2)+")" line = line.replace(figure_ref.group(1), md_reference) @@ -53,7 +53,7 @@ def process_fig_ref(mdin, mdout, line): def process_table(mdin, mdout, line): # detect table - table = re.match('\s*(Table:.*)({#(tbl:.*)})',line) + table = re.match(r'\s*(Table:.*)({#(tbl:.*)})',line) if table: insert_anchor(mdout, table.group(3)) mdout.write(table.group(1)+"\n") @@ -61,7 +61,7 @@ def process_table(mdin, mdout, line): return line def process_tbl_ref(mdin, mdout, line): - table_ref = re.match('.*({@(tbl:.*)})',line) + table_ref = re.match(r'.*({@(tbl:.*)})',line) if table_ref: md_reference = "[below](#"+table_ref.group(2)+")" line = line.replace(table_ref.group(1), md_reference) @@ -70,8 +70,8 @@ def process_tbl_ref(mdin, mdout, line): return line def process_listing(mdin, mdout, line): - listing_start = re.match('.*{#(lst:.*)\s+.c\s+.*',line) - listing_end = re.match('\s*~~~~\s*\n',line) + listing_start = re.match(r'.*{#(lst:.*)\s+.c\s+.*',line) + listing_end = re.match(r'\s*~~~~\s*\n',line) if listing_start: insert_anchor(mdout, listing_start.group(1)) line = ''