From 0f2616a5523ec828290b4542b6e584ba9c27e375 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 23 Dec 2013 08:48:24 +0000 Subject: [PATCH] Update paren module to handle ternary conditional operator --- PBot/VERSION.pm | 4 ++-- modules/paren/paren.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 62c26d9e..ae9b6d30 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 476, - BUILD_DATE => "2013-12-01", + BUILD_REVISION => 477, + BUILD_DATE => "2013-12-23", }; 1; diff --git a/modules/paren/paren.py b/modules/paren/paren.py index 6ec0a860..e7da2bbd 100755 --- a/modules/paren/paren.py +++ b/modules/paren/paren.py @@ -51,6 +51,12 @@ class CGenerator(c_generator.CGenerator): else: return n.op + operand + def visit_TernaryOp(self, n): + return '({0}) ? ({1}) : ({2})'.format( + self.visit(n.cond), + self.visit(n.iftrue), + self.visit(n.iffalse)) + def visit_Assignment(self, n): return '%s %s %s' % (self.visit(n.lvalue), n.op, self._parenthesize_unless_simple(n.rvalue)) @@ -68,7 +74,7 @@ def parenthesize(source): if __name__ == "__main__": if len(sys.argv) > 2: - parenthesize(' '.join(sys.argv[2:])) + parenthesize(' '.join(sys.argv[2:]).rstrip(';')) elif len(sys.argv) == 2: print(sys.argv[1] + ': ' + "Usage: paren ") else: