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

move gathering of match telementry to match_info

parent 957445fc
Branches
Tags
No related merge requests found
......@@ -41,31 +41,64 @@ class Annotator(object):
self._formatNameWidth = formatNameWidth
self._update_annotate_format()
def annotate(self, match, line, matcher, targetStartEnd):
# classify match
full = match and match.start() == 0 and match.end() == len(line)
local_ignore = False
global_ignore = False
matcher_does_nothing = False
def match_info(self, match, line, matcher, targetStartEnd):
result = {
# raw line
'line': line,
# information about SimpleMatcher
'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 matcher.coverageIgnore:
local_ignore = True
elif matcher.does_nothing:
matcher_does_nothing = True
result['span'] = [match.start(), match.end()]
if match.start() == 0 and match.end() == len(line):
result['match'] = 2 # full match
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:
m2 = self.coverageIgnore.match(line)
if m2:
global_ignore = True
match = m2
m_ci = self.coverageIgnore.match(line)
if m_ci:
result['coverageIgnore'] = 2 # global coverageIgnore matched
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
self.counter['total'] += 1
if local_ignore or global_ignore:
if minfo['coverageIgnore']:
self.counter['ignore'] += 1
elif match:
if full:
elif minfo['match'] > 1:
self.counter['match'] += 1
else:
elif minfo['match']:
self.counter['partial'] += 1
else:
self.counter['unmatched'] += 1
......@@ -76,36 +109,33 @@ class Annotator(object):
# setup match label
matchlabel = ''
if local_ignore:
if minfo['coverageIgnore'] == 1:
matchlabel = 'l_ign'
elif global_ignore:
elif minfo['coverageIgnore']:
matchlabel = 'g_ign'
elif match:
if matcher_does_nothing:
elif minfo['match']:
if minfo['matcher_does_nothing']:
matchlabel='n_'
if not full:
if minfo['match']<2:
matchlabel += 'p_'
matchlabel += 'end' if targetStartEnd else 'start'
matchlabel += minfo['which_re']
else:
matchlabel = 'no'
# highlight line
if local_ignore or global_ignore:
highlighted = self.matchHighlighter.highlight(
match, line, linecolor=ANSI.FG_BLUE)
elif matcher_does_nothing:
highlighted = self.matchHighlighter.highlight(
match, line, linecolor=ANSI.FG_MAGENTA)
elif match:
highlighted = self.matchHighlighter.highlight(match, line)
if minfo['coverageIgnore']:
highlighted = self.matchHighlighter.highlight_minfo(
minfo, linecolor=ANSI.FG_BLUE)
elif minfo['matcher_does_nothing']:
highlighted = self.matchHighlighter.highlight_minfo(
minfo, linecolor=ANSI.FG_MAGENTA)
elif minfo['match']:
highlighted = self.matchHighlighter.highlight_minfo(minfo)
else:
highlighted = line
# set matcher name
if matcher.name:
name=matcher.name[-self._formatNameWidth:]
else:
name='UNNAMED'
defFile=matcher.defFile[-self._formatSourceWidth:]
# shorted matcher- and source file names
name = minfo['name'][-self._formatNameWidth:]
defFile = minfo['defFile'][-self._formatSourceWidth:]
self.annotateFile.write(self._annotate_format % (
defFile, matcher.defLine, name,
defFile, minfo['defLine'], name,
matchlabel, highlighted,
))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment