aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mparser.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-06-19 21:56:09 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2016-08-01 20:46:40 +0300
commitd90fcb4048f720a238cbb350164ec8f63d1eec60 (patch)
treeac64eb1624beed298bacf50b27cdca0cc57d454b /mesonbuild/mparser.py
parent4f6be39d2668713c6c5b9d7bba06a58553f68887 (diff)
downloadmeson-d90fcb4048f720a238cbb350164ec8f63d1eec60.zip
meson-d90fcb4048f720a238cbb350164ec8f63d1eec60.tar.gz
meson-d90fcb4048f720a238cbb350164ec8f63d1eec60.tar.bz2
Created ternary operator. Closes #538.
Diffstat (limited to 'mesonbuild/mparser.py')
-rw-r--r--mesonbuild/mparser.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index fd720fb..b3fdba8 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -67,6 +67,7 @@ class Lexer:
('lt', re.compile(r'<')),
('ge', re.compile(r'>=')),
('gt', re.compile(r'>')),
+ ('questionmark', re.compile(r'\?')),
]
def lex(self, code):
@@ -282,6 +283,14 @@ class IfNode():
self.condition = condition
self.block = block
+class TernaryNode():
+ def __init__(self, lineno, colno, condition, trueblock, falseblock):
+ self.lineno = lineno
+ self.colno = colno
+ self.condition = condition
+ self.trueblock = trueblock
+ self.falseblock = falseblock
+
class ArgumentNode():
def __init__(self, token):
self.lineno = token.lineno
@@ -383,6 +392,11 @@ class Parser:
raise ParseException('Assignment target must be an id.',
left.lineno, left.colno)
return AssignmentNode(left.lineno, left.colno, left.value, value)
+ elif self.accept('questionmark'):
+ trueblock = self.e1()
+ self.expect('colon')
+ falseblock = self.e1()
+ return TernaryNode(left.lineno, left.colno, left, trueblock, falseblock)
return left
def e2(self):