simplify astprinter by using operator value

pull/13040/merge
Charles Brunet 1 year ago committed by Dylan Baker
parent 0bc51d5221
commit 728fcdaab3
  1. 11
      mesonbuild/ast/printer.py

@ -11,13 +11,6 @@ from .visitor import AstVisitor, FullAstVisitor
import re import re
import typing as T import typing as T
arithmic_map = {
'add': '+',
'sub': '-',
'mod': '%',
'mul': '*',
'div': '/'
}
class AstPrinter(AstVisitor): class AstPrinter(AstVisitor):
def __init__(self, indent: int = 2, arg_newline_cutoff: int = 5, update_ast_line_nos: bool = False): def __init__(self, indent: int = 2, arg_newline_cutoff: int = 5, update_ast_line_nos: bool = False):
@ -126,7 +119,7 @@ class AstPrinter(AstVisitor):
def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None: def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None:
node.left.accept(self) node.left.accept(self)
self.append_padded(arithmic_map[node.operation], node) self.append_padded(node.operator.value, node)
node.lineno = self.curr_line or node.lineno node.lineno = self.curr_line or node.lineno
node.right.accept(self) node.right.accept(self)
@ -379,7 +372,7 @@ class AstJSONPrinter(AstVisitor):
def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None: def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None:
self._accept('left', node.left) self._accept('left', node.left)
self._accept('right', node.right) self._accept('right', node.right)
self.current['op'] = arithmic_map[node.operation] self.current['op'] = node.operator.value
self.setbase(node) self.setbase(node)
def visit_NotNode(self, node: mparser.NotNode) -> None: def visit_NotNode(self, node: mparser.NotNode) -> None:

Loading…
Cancel
Save