Skip to content

Commit 2db365e

Browse files
author
Troy Melhase
committed
Applied patches and added tests for empty array declarations, trailing F on floats, and additional variable-keyword subsitutions. See issue natural#27, issue natural#28, and issue natural#29.
1 parent 5bff734 commit 2db365e

File tree

5 files changed

+66
-1
lines changed

5 files changed

+66
-1
lines changed

java2python/lib/defaultconfig.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,21 @@
105105
'Vector':'[]',
106106
'boolean':'False',
107107
'str':'""',
108+
'[':'None',
108109
}
109110

110111
## method name mapping. user-defined configuration modules can
111112
## replace and/or augment this with their own.
112113
renameMethodMap = {
113114
'equals':'__eq__',
115+
'and':'and_',
116+
'del':'del_',
117+
'elif':'elif_',
118+
'in':'in_',
114119
'is':'is_',
120+
'not':'not_',
121+
'or':'or_',
122+
'print':'print_',
115123
}
116124

117125
## generic name mapping. user-defined configuration modules can
@@ -121,7 +129,14 @@
121129
'null':'None',
122130
'false':'False',
123131
'true':'True',
132+
'and':'and_',
133+
'del':'del_',
134+
'elif':'elif_',
135+
'in':'in_',
124136
'is':'is_',
137+
'not':'not_',
138+
'or':'or_',
139+
'print':'print_',
125140
'str':'strval',
126141
}
127142

@@ -152,7 +167,14 @@
152167

153168
variableNameMapping = {
154169
'str':'strval',
170+
'and':'and_',
171+
'del':'del_',
172+
'elif':'elif_',
173+
'in':'in_',
155174
'is':'is_',
175+
'not':'not_',
176+
'or':'or_',
177+
'print':'print_',
156178
}
157179

158180

java2python/lib/walker.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ returns [value]
810810
: i0:NUM_INT {value = i0.getText()}
811811
| c0:CHAR_LITERAL {value = c0.getText()}
812812
| s0:STRING_LITERAL {value = s0.getText()}
813-
| f0:NUM_FLOAT {value = f0.getText()}
813+
| f0:NUM_FLOAT {value = f0.getText().rstrip("fF")}
814814
| d0:NUM_DOUBLE {value = d0.getText()}
815815
| l0:NUM_LONG {value = l0.getText()}
816816
;

java2python/tests/EmptyArray.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class EmptyArray {
2+
int [] b;
3+
public static void main(String[] args) {
4+
}
5+
6+
}

java2python/tests/FloatFix.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class FloatFix {
2+
public static void main(String[] args) {
3+
float b = 1.2f;
4+
System.out.println(b);
5+
}
6+
}

java2python/tests/Keywords.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Keywords {
2+
public static void main(String[] args) {
3+
String and = "this is and";
4+
System.out.println(and);
5+
6+
String del = "this is del";
7+
System.out.println(del);
8+
9+
String elif = "this is elif";
10+
System.out.println(elif);
11+
12+
String in = "this is in";
13+
System.out.println(in);
14+
15+
String is = "this is is";
16+
System.out.println(is);
17+
18+
String not = "this is not";
19+
System.out.println(not);
20+
21+
String or = "this is or";
22+
System.out.println(or);
23+
24+
String print = "this is print";
25+
System.out.println(print);
26+
27+
String str = "this is str";
28+
System.out.println(str);
29+
30+
}
31+
}

0 commit comments

Comments
 (0)