-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrange_operator.py
More file actions
46 lines (40 loc) · 1.33 KB
/
range_operator.py
File metadata and controls
46 lines (40 loc) · 1.33 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
#!/usr/bin/python
# coding: utf8
"""
Contains:
- operators: python ast operator node
- logical operators: python ast comparison operator
- comparison sign: comparison operator sign
- opposite comparison: comparison operator associated to its opposite operator
"""
import ast
import operator
operators = {ast.Add: operator.add,
ast.Sub: operator.sub,
ast.Mult: operator.mul,
ast.Div: operator.truediv,
ast.Pow: operator.pow,
ast.BitXor: operator.xor,
ast.USub: operator.neg
}
logical_operators = {ast.Eq: operator.eq,
ast.NotEq: operator.ne,
ast.Lt: operator.lt,
ast.LtE: operator.lt,
ast.Gt: operator.gt,
ast.GtE: operator.ge
}
comparison_sign = {ast.Eq: "==",
ast.NotEq: "!=",
ast.Lt: "<",
ast.LtE: "<=",
ast.Gt: ">",
ast.GtE: ">="
}
opposite_comparison = {ast.Eq: ast.NotEq,
ast.NotEq: ast.Eq,
ast.Lt: ast.GtE,
ast.LtE: ast.Gt,
ast.Gt: ast.LtE,
ast.GtE: ast.Lt
}