def _parse(self, txt, linenr=0, directcall=False):
pos = 0
for match in _ALL_DIRECTIVES_REGEXP.finditer(txt):
start, end = match.span()
if start > pos:
endlinenr = linenr + txt.count('\n', pos, start)
self._process_text(txt[pos:start], (linenr, endlinenr))
linenr = endlinenr
endlinenr = linenr + txt.count('\n', start, end)
span = (linenr, endlinenr)
ldirtype, ldir, idirtype, idir = match.groups()
if directcall and (idirtype is None or idirtype != '$'):
msg = 'only inline eval directives allowed in direct calls'
raise FyppFatalError(msg, self._curfile, span)
elif idirtype is not None:
if idir is None:
msg = 'missing inline directive content'
raise FyppFatalError(msg, self._curfile, span)
dirtype = idirtype
content = idir
elif ldirtype is not None:
if ldir is None:
msg = 'missing line directive content'
raise FyppFatalError(msg, self._curfile, span)
dirtype = ldirtype
content = _CONTLINE_REGEXP.sub('', ldir)
else:
# Comment directive
dirtype = None
if dirtype == '$':
self.handle_eval(span, content)
elif dirtype == '#':
self._process_control_dir(content, span)
elif dirtype == '@':
self._process_direct_call(content, span)
else:
self.handle_comment(span)
pos = end
linenr = endlinenr
if pos < len(txt):
endlinenr = linenr + txt.count('\n', pos)
self._process_text(txt[pos:], (linenr, endlinenr))
评论列表
文章目录