Add ParenthesizedNode

pull/12152/head
JCWasmx86 2 years ago committed by Charles Brunet
parent bd3341f808
commit 79ed2415e9
  1. 4
      mesonbuild/ast/visitor.py
  2. 2
      mesonbuild/interpreterbase/interpreterbase.py
  3. 11
      mesonbuild/mparser.py
  4. 2
      mesonbuild/optinterpreter.py

@ -144,3 +144,7 @@ class AstVisitor:
for key, val in node.kwargs.items():
key.accept(self)
val.accept(self)
def visit_ParenthesizedNode(self, node: mparser.ParenthesizedNode) -> None:
self.visit_default_func(node)
node.inner.accept(self)

@ -239,6 +239,8 @@ class InterpreterBase:
raise ContinueRequest()
elif isinstance(cur, mparser.BreakNode):
raise BreakRequest()
elif isinstance(cur, mparser.ParenthesizedNode):
return self.evaluate_statement(cur.inner)
elif isinstance(cur, mparser.TestCaseClauseNode):
return self.evaluate_testcase(cur)
else:

@ -577,6 +577,15 @@ class TernaryNode(BaseNode):
self.trueblock = trueblock
self.falseblock = falseblock
@dataclass(unsafe_hash=True)
class ParenthesizedNode(BaseNode):
inner: BaseNode
def __init__(self, inner: BaseNode, lineno: int, colno: int, end_lineno: int, end_colno: int):
super().__init__(lineno, colno, inner.filename, end_lineno=end_lineno, end_colno=end_colno)
self.inner = inner
if T.TYPE_CHECKING:
COMPARISONS = Literal['==', '!=', '<', '<=', '>=', '>', 'in', 'notin']
@ -778,7 +787,7 @@ class Parser:
if self.accept('lparen'):
e = self.statement()
self.block_expect('rparen', block_start)
return e
return ParenthesizedNode(e, block_start.lineno, block_start.colno, self.current.lineno, self.current.colno)
elif self.accept('lbracket'):
args = self.args()
self.block_expect('rbracket', block_start)

@ -113,6 +113,8 @@ class OptionInterpreter:
def reduce_single(self, arg: T.Union[str, mparser.BaseNode]) -> 'TYPE_var':
if isinstance(arg, str):
return arg
if isinstance(arg, mparser.ParenthesizedNode):
return self.reduce_single(arg.inner)
elif isinstance(arg, (mparser.StringNode, mparser.BooleanNode,
mparser.NumberNode)):
return arg.value

Loading…
Cancel
Save