Skip to content

Commit

Permalink
Fix regex issues (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
niosus authored Apr 17, 2018
1 parent 01c4729 commit 68362c7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
9 changes: 4 additions & 5 deletions plugin/completion/bin_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand All @@ -72,9 +71,9 @@ class Completer(BaseCompleter):

compl_str_mask = "{complete_flag}={file}:{row}:{col}"

compl_regex = re.compile("COMPLETION:\s(?P<name>.*)\s:\s(?P<content>.*)")
compl_regex = re.compile(r"COMPLETION:\s(?P<name>.*)\s:\s(?P<content>.*)")
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("{#|#}")
Expand Down
23 changes: 11 additions & 12 deletions plugin/completion/compiler_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<file>.*)" +
":(?P<row>\d+):(?P<col>\d+)" +
":\s*.*error: (?P<error>.*)")
error_regex = re.compile(r"(?P<file>.*)" +
r":(?P<row>\d+):(?P<col>\d+)" +
r":\s*.*error: (?P<error>.*)")

def errors_from_output(self, output):
"""Parse errors received from clang binary output.
Expand Down Expand Up @@ -69,9 +68,9 @@ class ClangClCompilerVariant(ClangCompilerVariant):
"""
need_lang_flags = False
include_prefixes = ["-I", "/I", "-msvc", "/msvc"]
error_regex = re.compile("(?P<file>.*)" +
"\((?P<row>\d+),(?P<col>\d+)\)\s*" +
":\s*.*error: (?P<error>.*)")
error_regex = re.compile(r"(?P<file>.*)" +
r"\((?P<row>\d+),(?P<col>\d+)\)\s*" +
r":\s*.*error: (?P<error>.*)")


class LibClangCompilerVariant(ClangCompilerVariant):
Expand All @@ -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>.+)'.*" + # file
"line\s(?P<row>\d+), " + # row
"column\s(?P<col>\d+)") # col
msg_regex = re.compile('[b\"|\"]*(?P<error>[^"]+)\"*')
pos_regex = re.compile(r"'(?P<file>.+)'.*" + # file
r"line\s(?P<row>\d+), " + # row
r"column\s(?P<col>\d+)") # col
msg_regex = re.compile(r'[b\"|\"]*(?P<error>[^"]+)\"*')
SEVERITY_TAG = 'severity'

def errors_from_output(self, output):
Expand Down
2 changes: 1 addition & 1 deletion plugin/flags_sources/cmake_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plugin/popups/popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions plugin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 68362c7

Please sign in to comment.