Skip to content
Snippets Groups Projects
Commit 83b8573a authored by Henning Glawe's avatar Henning Glawe
Browse files

move gathering of match telementry to match_info

parent a435ed5b
Branches
Tags
No related merge requests found
...@@ -41,31 +41,64 @@ class Annotator(object): ...@@ -41,31 +41,64 @@ class Annotator(object):
self._formatNameWidth = formatNameWidth self._formatNameWidth = formatNameWidth
self._update_annotate_format() self._update_annotate_format()
def annotate(self, match, line, matcher, targetStartEnd): def match_info(self, match, line, matcher, targetStartEnd):
# classify match result = {
full = match and match.start() == 0 and match.end() == len(line) # raw line
local_ignore = False 'line': line,
global_ignore = False # information about SimpleMatcher
matcher_does_nothing = False 'name': matcher.name if matcher.name else 'UNNAMED',
'defFile': matcher.defFile,
'defLine': matcher.defLine,
'matcher_does_nothing': matcher.does_nothing, # matcher without effect
'which_re': 'end' if targetStartEnd else 'start',
# classification of match
'match': 0, # 0 - no, 1 - partial, 2 - full
'coverageIgnore': 0, # 0 - no, 1 - local, 2 - global
# overall span of match
'span': [],
# capture groups
'group': [],
}
if match: if match:
if matcher.coverageIgnore: result['span'] = [match.start(), match.end()]
local_ignore = True if match.start() == 0 and match.end() == len(line):
elif matcher.does_nothing: result['match'] = 2 # full match
matcher_does_nothing = True else:
result['match'] = 1 # partial match
if matcher.coverageIgnore: # matcher is local coverageIgnore
result['coverageIgnore'] = 1
# capture groups
# todo: move this to SimpleMatcher/CompiledMatcher
groupname=['all'] + [ str(num+1) for num in range(match.re.groups)]
for name,num in match.re.groupindex.items():
groupname[num]=name
# extract capture group info
for groupi in range(1, match.re.groups+1):
# Forward compatibility with 'regex' or 're2', which support
# multiple captures per named group:
# span: list of start/end indices
# capture: list of matched strings
result['group'].append({'name': groupname[groupi], 'span': [],
'capture': []})
if match.group(groupi) is not None:
result['group'][-1]['capture'].append(match.group(groupi))
result['group'][-1]['span'].append(match.span(groupi))
else: else:
m2 = self.coverageIgnore.match(line) m_ci = self.coverageIgnore.match(line)
if m2: if m_ci:
global_ignore = True result['coverageIgnore'] = 2 # global coverageIgnore matched
match = m2 result['span'] = [m_ci.start(), m_ci.end()]
return result
def annotate(self, match, line, matcher, targetStartEnd):
minfo = self.match_info(match, line, matcher, targetStartEnd)
# update counters # update counters
self.counter['total'] += 1 self.counter['total'] += 1
if local_ignore or global_ignore: if minfo['coverageIgnore']:
self.counter['ignore'] += 1 self.counter['ignore'] += 1
elif match: elif minfo['match'] > 1:
if full:
self.counter['match'] += 1 self.counter['match'] += 1
else: elif minfo['match']:
self.counter['partial'] += 1 self.counter['partial'] += 1
else: else:
self.counter['unmatched'] += 1 self.counter['unmatched'] += 1
...@@ -76,36 +109,33 @@ class Annotator(object): ...@@ -76,36 +109,33 @@ class Annotator(object):
# setup match label # setup match label
matchlabel = '' matchlabel = ''
if local_ignore: if minfo['coverageIgnore'] == 1:
matchlabel = 'l_ign' matchlabel = 'l_ign'
elif global_ignore: elif minfo['coverageIgnore']:
matchlabel = 'g_ign' matchlabel = 'g_ign'
elif match: elif minfo['match']:
if matcher_does_nothing: if minfo['matcher_does_nothing']:
matchlabel='n_' matchlabel='n_'
if not full: if minfo['match']<2:
matchlabel += 'p_' matchlabel += 'p_'
matchlabel += 'end' if targetStartEnd else 'start' matchlabel += minfo['which_re']
else: else:
matchlabel = 'no' matchlabel = 'no'
# highlight line # highlight line
if local_ignore or global_ignore: if minfo['coverageIgnore']:
highlighted = self.matchHighlighter.highlight( highlighted = self.matchHighlighter.highlight_minfo(
match, line, linecolor=ANSI.FG_BLUE) minfo, linecolor=ANSI.FG_BLUE)
elif matcher_does_nothing: elif minfo['matcher_does_nothing']:
highlighted = self.matchHighlighter.highlight( highlighted = self.matchHighlighter.highlight_minfo(
match, line, linecolor=ANSI.FG_MAGENTA) minfo, linecolor=ANSI.FG_MAGENTA)
elif match: elif minfo['match']:
highlighted = self.matchHighlighter.highlight(match, line) highlighted = self.matchHighlighter.highlight_minfo(minfo)
else: else:
highlighted = line highlighted = line
# set matcher name # shorted matcher- and source file names
if matcher.name: name = minfo['name'][-self._formatNameWidth:]
name=matcher.name[-self._formatNameWidth:] defFile = minfo['defFile'][-self._formatSourceWidth:]
else:
name='UNNAMED'
defFile=matcher.defFile[-self._formatSourceWidth:]
self.annotateFile.write(self._annotate_format % ( self.annotateFile.write(self._annotate_format % (
defFile, matcher.defLine, name, defFile, minfo['defLine'], name,
matchlabel, highlighted, matchlabel, highlighted,
)) ))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment