Forbid nested ternary operations.

pull/605/head
Jussi Pakkanen 9 years ago
parent d90fcb4048
commit b382abdd2c
  1. 6
      mesonbuild/mparser.py
  2. 3
      test cases/failing/30 nested ternary/meson.build

@ -353,6 +353,7 @@ class Parser:
def __init__(self, code):
self.stream = Lexer().lex(code)
self.getsym()
self.in_ternary = False
def getsym(self):
try:
@ -393,9 +394,14 @@ class Parser:
left.lineno, left.colno)
return AssignmentNode(left.lineno, left.colno, left.value, value)
elif self.accept('questionmark'):
if self.in_ternary:
raise ParseException('Nested ternary operators are not allowed.',
left.lineno, left.colno)
self.in_ternary = True
trueblock = self.e1()
self.expect('colon')
falseblock = self.e1()
self.in_ternary = False
return TernaryNode(left.lineno, left.colno, left, trueblock, falseblock)
return left

@ -0,0 +1,3 @@
project('nested ternary', 'c')
x = true ? (false ? 1 : 0) : 2
Loading…
Cancel
Save