Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7a3d54

Browse files
committed
don't put L suffix on literals
1 parent 153da8b commit a7a3d54

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

java2python/config/default.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
(Type('TRUE'), transform.true2True),
151151
(Type('IDENT'), transform.keywordSafeIdent),
152152

153+
(Type('DECIMAL_LITERAL'), transform.syntaxSafeDecimalLiteral),
153154
(Type('FLOATING_POINT_LITERAL'), transform.syntaxSafeFloatLiteral),
154155

155156
(Type('TYPE') > Type('BOOLEAN'), transform.typeSub),

java2python/mod/transform.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,21 @@ def xform(node, config):
4848
true2True = makeConst('True')
4949

5050

51+
def syntaxSafeDecimalLiteral(node, config):
52+
""" Ensures a Java decimal literal is a valid Python decimal literal. """
53+
value = node.token.text
54+
if value.endswith(('l', 'L')):
55+
value = value[:-1]
56+
node.token.text = value
57+
58+
5159
def syntaxSafeFloatLiteral(node, config):
5260
""" Ensures a Java float literal is a valid Python float literal. """
5361
value = node.token.text
5462
if value.startswith('.'):
5563
value = '0' + value
5664
if value.lower().endswith(('f', 'd')):
5765
value = value[:-1]
58-
elif value.endswith(('l', 'L')):
59-
value = value[:-1] + 'L'
6066
node.token.text = value
6167

6268

0 commit comments

Comments
 (0)