mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 03:02:47 +01:00
Update paren module to handle ternary conditional operator
This commit is contained in:
parent
8adc766dc4
commit
0f2616a552
@ -13,8 +13,8 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 476,
|
BUILD_REVISION => 477,
|
||||||
BUILD_DATE => "2013-12-01",
|
BUILD_DATE => "2013-12-23",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -51,6 +51,12 @@ class CGenerator(c_generator.CGenerator):
|
|||||||
else:
|
else:
|
||||||
return n.op + operand
|
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):
|
def visit_Assignment(self, n):
|
||||||
return '%s %s %s' % (self.visit(n.lvalue), n.op, self._parenthesize_unless_simple(n.rvalue))
|
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 __name__ == "__main__":
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
parenthesize(' '.join(sys.argv[2:]))
|
parenthesize(' '.join(sys.argv[2:]).rstrip(';'))
|
||||||
elif len(sys.argv) == 2:
|
elif len(sys.argv) == 2:
|
||||||
print(sys.argv[1] + ': ' + "Usage: paren <expression>")
|
print(sys.argv[1] + ': ' + "Usage: paren <expression>")
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user