-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathFutureFeature.java
More file actions
109 lines (97 loc) · 2.68 KB
/
FutureFeature.java
File metadata and controls
109 lines (97 loc) · 2.68 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.python.core;
import org.python.antlr.ParseException;
public enum FutureFeature implements Pragma {
/**
* Enables nested scopes.
*/
nested_scopes(CodeFlag.CO_NESTED),
/**
* Makes integer / integer division return float.
*/
division(CodeFlag.CO_FUTURE_DIVISION),
/**
* Enables generators.
*/
generators(CodeFlag.CO_GENERATOR_ALLOWED),
/**
* Enables absolute imports.
*/
absolute_import(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT),
/**
* Enables the with statement.
*/
with_statement(CodeFlag.CO_FUTURE_WITH_STATEMENT),
/**
* Enables the print function.
*/
print_function(CodeFlag.CO_FUTURE_PRINT_FUNCTION),
/**
* Enables unicode literals.
*/
unicode_literals(CodeFlag.CO_FUTURE_UNICODE_LITERALS),
/**
* Use braces for block delimiters instead of indentation.
*/
braces {
@Override
public void addTo(PragmaReceiver features) {
throw new ParseException("not a chance");
}
},
/**
* Enable the Global Interpreter Lock in Jython.
*/
GIL {
@Override
public void addTo(PragmaReceiver features) {
throw new ParseException("Never going to happen!");
}
},
/**
* Enable the Global Interpreter Lock in Jython.
*/
global_interpreter_lock {
@Override
public void addTo(PragmaReceiver features) {
GIL.addTo(features);
}
};
public static final String MODULE_NAME = "__future__";
public static final PragmaModule PRAGMA_MODULE = new PragmaModule(
MODULE_NAME) {
@Override
public Pragma getPragma(String name) {
return getFeature(name);
}
@Override
public Pragma getStarPragma() {
throw new ParseException("future feature * is not defined");
}
};
private final CodeFlag flag;
private FutureFeature(CodeFlag flag) {
this.flag = flag;
}
private FutureFeature() {
this(null);
}
public void addTo(PragmaReceiver features) {
features.add(this);
}
public static void addFeature(String featureName, PragmaReceiver features) {
getFeature(featureName).addTo(features);
}
private static FutureFeature getFeature(String featureName) {
try {
return valueOf(featureName);
} catch (IllegalArgumentException ex) {
throw new ParseException("future feature " + featureName
+ " is not defined");
}
}
public void setFlag(CompilerFlags cflags) {
if (flag != null) {
cflags.setFlag(flag);
}
}
}