ast.py 文件源码

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

项目:monasca-analytics 作者: openstack 项目源码 文件源码
def make_span(s, l, t):

    def compute_hi(init_loc, tokens):
        hi = init_loc
        for tok in tokens:
            if isinstance(tok, ASTNode):
                hi = max(hi, tok.span.hi)
            elif isinstance(tok, basestring):
                hi += len(tok)
            elif isinstance(tok, p.ParseResults):
                hi = max(hi, compute_hi(init_loc, tok))
            else:
                raise exception.BananaGrammarBug(
                    "Couldn't create span for: {}".format(tok)
                )
        return hi

    if len(t) > 0:
        span_hi = compute_hi(l, t)
        return Span(s, l, span_hi)
    else:
        return Span(s, l, 2)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号