-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathExprAdapter.java
More file actions
49 lines (43 loc) · 1.27 KB
/
ExprAdapter.java
File metadata and controls
49 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.python.antlr.adapter;
import java.util.ArrayList;
import java.util.List;
import org.python.antlr.ast.Num;
import org.python.antlr.ast.Str;
import org.python.antlr.base.expr;
import org.python.core.Py;
import org.python.core.PyComplex;
import org.python.core.PyFloat;
import org.python.core.PyInteger;
import org.python.core.PyLong;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.core.PyUnicode;
public class ExprAdapter implements AstAdapter {
public Object py2ast(PyObject o) {
if (o instanceof expr) {
return o;
}
if (o instanceof PyInteger || o instanceof PyLong || o instanceof PyFloat || o instanceof PyComplex) {
return new Num(o);
}
if (o instanceof PyString || o instanceof PyUnicode) {
return new Str(o);
}
return null;
}
public PyObject ast2py(Object o) {
if (o == null) {
return Py.None;
}
return (PyObject)o;
}
public List iter2ast(PyObject iter) {
List<expr> exprs = new ArrayList<expr>();
if (iter != Py.None) {
for(Object o : (Iterable)iter) {
exprs.add((expr)py2ast((PyObject)o));
}
}
return exprs;
}
}