def visit_infix_expression(node, operators={}):
def interleave(*iterables):
for values in itertools.zip_longest(*iterables, fillvalue=UnboundLocalError):
for index, value in enumerate(values):
if value != UnboundLocalError:
yield index, value
tokens = [
visit_node(operand_or_operator)
if index == 0
else operators.get(operand_or_operator, operand_or_operator)
for index, operand_or_operator in interleave(node['operands'], node['operators'])
]
# Transform product expressions into a lazy "and" expression in order to prevent a division by 0:
if node['type'] == 'product_expression':
tokens = concatv(
interpose(
el='and',
seq=map(visit_node, node['operands']),
),
['and'],
tokens,
)
return '({})'.format(' '.join(map(str, tokens)))
# Main visitor
python_source_visitors.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录