aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-06-19 22:02:59 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2016-08-01 20:49:30 +0300
commitb382abdd2c307d0716353013022df5039991ac1f (patch)
treecec45bf951de7b6513dbfb3b70b6220d8b6a5efc
parentd90fcb4048f720a238cbb350164ec8f63d1eec60 (diff)
downloadmeson-b382abdd2c307d0716353013022df5039991ac1f.zip
meson-b382abdd2c307d0716353013022df5039991ac1f.tar.gz
meson-b382abdd2c307d0716353013022df5039991ac1f.tar.bz2
Forbid nested ternary operations.
-rw-r--r--mesonbuild/mparser.py6
-rw-r--r--test cases/failing/30 nested ternary/meson.build3
2 files changed, 9 insertions, 0 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index b3fdba8..2f0eb2d 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -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
diff --git a/test cases/failing/30 nested ternary/meson.build b/test cases/failing/30 nested ternary/meson.build
new file mode 100644
index 0000000..f9c2e5f
--- /dev/null
+++ b/test cases/failing/30 nested ternary/meson.build
@@ -0,0 +1,3 @@
+project('nested ternary', 'c')
+
+x = true ? (false ? 1 : 0) : 2