fypp.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fypp 作者: aradi 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号