From 68362c7b260fb8744086106ba72bd235d19ca1cd Mon Sep 17 00:00:00 2001 From: Igor Bogoslavskyi Date: Tue, 17 Apr 2018 21:04:22 +0200 Subject: [PATCH] Fix regex issues (#453) --- plugin/completion/bin_complete.py | 9 ++++----- plugin/completion/compiler_variant.py | 23 +++++++++++------------ plugin/flags_sources/cmake_file.py | 2 +- plugin/popups/popups.py | 2 +- plugin/tools.py | 8 ++++---- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/plugin/completion/bin_complete.py b/plugin/completion/bin_complete.py index fd39c7fc..14b27311 100644 --- a/plugin/completion/bin_complete.py +++ b/plugin/completion/bin_complete.py @@ -15,7 +15,6 @@ from .base_complete import BaseCompleter from .compiler_variant import ClangCompilerVariant from .compiler_variant import ClangClCompilerVariant -from ..settings.settings_storage import SettingsStorage log = logging.getLogger("ECC") @@ -61,8 +60,8 @@ class Completer(BaseCompleter): PARAM_TAG = "param" TYPE_TAG = "type" - PARAM_CHARS = "\w\s\*\&\<\>:,\(\)\$\{\}!_\." - TYPE_CHARS = "\w\s\*\&\<\>:,\(\)\$\{\}\[\]!" + PARAM_CHARS = r"\w\s\*\&\<\>:,\(\)\$\{\}!_\." + TYPE_CHARS = r"\w\s\*\&\<\>:,\(\)\$\{\}\[\]!" group_params = "(?P<{param_tag}>[{param_chars}]+)".format( param_chars=PARAM_CHARS, param_tag=PARAM_TAG) @@ -72,9 +71,9 @@ class Completer(BaseCompleter): compl_str_mask = "{complete_flag}={file}:{row}:{col}" - compl_regex = re.compile("COMPLETION:\s(?P.*)\s:\s(?P.*)") + compl_regex = re.compile(r"COMPLETION:\s(?P.*)\s:\s(?P.*)") compl_content_regex = re.compile( - "\<#{group_params}#\>|\[#{group_types}#\]".format( + r"\<#{group_params}#\>|\[#{group_types}#\]".format( group_params=group_params, group_types=group_types)) opts_regex = re.compile("{#|#}") diff --git a/plugin/completion/compiler_variant.py b/plugin/completion/compiler_variant.py index 16cd5fc1..788205c8 100644 --- a/plugin/completion/compiler_variant.py +++ b/plugin/completion/compiler_variant.py @@ -18,8 +18,7 @@ class CompilerVariant(object): init_flags = [Flag("-c"), Flag("-fsyntax-only")] def errors_from_output(self, output): - """ - Parse errors received from the compiler. + """Parse errors received from the compiler. Args: output (object): opaque output to be parsed by compiler variant @@ -37,9 +36,9 @@ class ClangCompilerVariant(CompilerVariant): error_regex (re): regex to find contents of an error """ include_prefixes = ["-isystem", "-I", "-isysroot"] - error_regex = re.compile("(?P.*)" + - ":(?P\d+):(?P\d+)" + - ":\s*.*error: (?P.*)") + error_regex = re.compile(r"(?P.*)" + + r":(?P\d+):(?P\d+)" + + r":\s*.*error: (?P.*)") def errors_from_output(self, output): """Parse errors received from clang binary output. @@ -69,9 +68,9 @@ class ClangClCompilerVariant(ClangCompilerVariant): """ need_lang_flags = False include_prefixes = ["-I", "/I", "-msvc", "/msvc"] - error_regex = re.compile("(?P.*)" + - "\((?P\d+),(?P\d+)\)\s*" + - ":\s*.*error: (?P.*)") + error_regex = re.compile(r"(?P.*)" + + r"\((?P\d+),(?P\d+)\)\s*" + + r":\s*.*error: (?P.*)") class LibClangCompilerVariant(ClangCompilerVariant): @@ -81,10 +80,10 @@ class LibClangCompilerVariant(ClangCompilerVariant): pos_regex (re): regex to find position of an error msg_regex (re): regex to find error message """ - pos_regex = re.compile("'(?P.+)'.*" + # file - "line\s(?P\d+), " + # row - "column\s(?P\d+)") # col - msg_regex = re.compile('[b\"|\"]*(?P[^"]+)\"*') + pos_regex = re.compile(r"'(?P.+)'.*" + # file + r"line\s(?P\d+), " + # row + r"column\s(?P\d+)") # col + msg_regex = re.compile(r'[b\"|\"]*(?P[^"]+)\"*') SEVERITY_TAG = 'severity' def errors_from_output(self, output): diff --git a/plugin/flags_sources/cmake_file.py b/plugin/flags_sources/cmake_file.py index 854ad9d2..28c763f7 100644 --- a/plugin/flags_sources/cmake_file.py +++ b/plugin/flags_sources/cmake_file.py @@ -29,7 +29,7 @@ class CMakeFile(FlagsSource): """ _FILE_NAME = 'CMakeLists.txt' _CMAKE_MASK = '{cmake} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON {flags} "{path}"' - _DEP_REGEX = re.compile('\"(.+\..+)\"') + _DEP_REGEX = re.compile(r'\"(.+\..+)\"') def __init__(self, include_prefixes, diff --git a/plugin/popups/popups.py b/plugin/popups/popups.py index ca48ba6f..8dfa1200 100644 --- a/plugin/popups/popups.py +++ b/plugin/popups/popups.py @@ -87,7 +87,7 @@ def info(cursor, cindex, settings): is_type = cursor.kind in type_decl if is_macro: macro_parser = MacroParser(cursor.spelling, cursor.location) - declaration_text += '\#define ' + declaration_text += r'\#define ' else: if cursor.result_type.spelling: result_type = cursor.result_type diff --git a/plugin/tools.py b/plugin/tools.py index 45b6ee2e..c9e0237d 100644 --- a/plugin/tools.py +++ b/plugin/tools.py @@ -31,7 +31,7 @@ '5.1': '3.4', '6.0': '3.5', '6.1': '3.6', - '7.0': '3.8', + '7.0': '3.7', '7.3': '3.8', '8.0': '3.8', '8.1': '3.9', @@ -429,7 +429,7 @@ class Tools: """ - syntax_regex = re.compile("\/([^\/]+)\.(?:tmLanguage|sublime-syntax)") + syntax_regex = re.compile(r"\/([^\/]+)\.(?:tmLanguage|sublime-syntax)") valid_extensions = [".c", ".cc", ".cpp", ".cxx", ".h", ".hpp", ".hxx", ".m", ".mm"] @@ -714,7 +714,7 @@ def get_clang_version_str(cls, clang_binary): @classmethod def _get_regular_clang_version_str(cls, output_text): # now we have the output, and can extract version from it - version_regex = re.compile("\d\.\d\.*\d*") + version_regex = re.compile(r"\d\.\d\.*\d*") match = version_regex.search(output_text) if match: version_str = match.group() @@ -725,7 +725,7 @@ def _get_regular_clang_version_str(cls, output_text): @classmethod def _get_apple_clang_version_str(cls, output_text): - version_regex = re.compile("\d\.\d\.*\d*") + version_regex = re.compile(r"\d\.\d\.*\d*") match = version_regex.search(output_text) if match: version_str = match.group()