| 1 | """
|
| 2 | typed_arith_abbrev.py - Abbreviations for pretty-printing typed_arith.asdl.
|
| 3 | """
|
| 4 |
|
| 5 | from asdl import runtime
|
| 6 | from _devbuild.gen.hnode_asdl import hnode
|
| 7 |
|
| 8 | def _arith_expr__Unary(obj):
|
| 9 | # type: (arith_expr__Unary) -> hnode.Record
|
| 10 |
|
| 11 | p_node = runtime.NewRecord('U')
|
| 12 | p_node.abbrev = True
|
| 13 | n = runtime.NewLeaf(str(obj.op), color_e.StringConst)
|
| 14 | p_node.unnamed_fields.append(n)
|
| 15 | p_node.unnamed_fields.append(obj.a.AbbreviatedTree()) # type: ignore
|
| 16 | return p_node
|
| 17 |
|
| 18 |
|
| 19 | def _arith_expr__Binary(obj):
|
| 20 | # type: (arith_expr__Binary) -> Optional[hnode.Record]
|
| 21 |
|
| 22 | if obj.op == '=': # test for fallback
|
| 23 | return None
|
| 24 |
|
| 25 | p_node = runtime.NewRecord('B')
|
| 26 | p_node.abbrev = True
|
| 27 | n = runtime.NewLeaf(str(obj.op), color_e.StringConst)
|
| 28 | p_node.unnamed_fields.append(n)
|
| 29 | p_node.unnamed_fields.append(obj.left.AbbreviatedTree()) # type: ignore
|
| 30 | p_node.unnamed_fields.append(obj.right.AbbreviatedTree()) # type: ignore
|
| 31 | return p_node
|
| 32 |
|
| 33 |
|
| 34 | def _arith_expr__Const(obj):
|
| 35 | # type: (arith_expr__Const) -> hnode.Record
|
| 36 | p_node = runtime.NewRecord('')
|
| 37 | p_node.abbrev = True
|
| 38 | n = runtime.NewLeaf(str(obj.i), color_e.OtherConst)
|
| 39 | p_node.unnamed_fields.append(n)
|
| 40 | return p_node
|
| 41 |
|
| 42 |
|
| 43 | def _arith_expr__Var(obj):
|
| 44 | # type: (arith_expr__Var) -> hnode.Record
|
| 45 | p_node = runtime.NewRecord('$')
|
| 46 | p_node.abbrev = True
|
| 47 | n = runtime.NewLeaf(str(obj.name), color_e.StringConst)
|
| 48 | p_node.unnamed_fields.append(n)
|
| 49 | return p_node
|
| 50 |
|