-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyAst.hs
125 lines (90 loc) · 3.49 KB
/
PyAst.hs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{-# OPTIONS_GHC -XDeriveDataTypeable #-}
module PyAst
(Module(..),
Stmt(..),
Expr(..),
ExprContext(..),
Slice(..),
BoolOperator(..),
Operator(..),
UnaryOp(..),
CmpOp(..),
Comprehension(..),
ExceptHandler(..),
Arguments(..),
Keyword(..),
Alias(..),
Identifier(..),
Pos(..))
where
import Data.Generics
data Pos = Pos Int Int deriving (Show, Data, Typeable, Eq)
data Module =
Module [Stmt] Pos
| Interactive [Stmt] Pos
| Expression Expr Pos
deriving (Show, Data, Typeable, Eq)
data Stmt =
FunctionDef Identifier Arguments [Stmt] [Expr] Pos
| ClassDef Identifier [Expr] [Stmt] [Expr] Pos
| Return (Maybe Expr) Pos
| Delete [Expr] Pos
| Assign [Expr] Expr Pos
| AugAssign Expr Operator Expr Pos
| Print (Maybe Expr) [Expr] Bool Pos
| For Expr Expr [Stmt] [Stmt] Pos
| While Expr [Stmt] [Stmt] Pos
| If Expr [Stmt] [Stmt] Pos
| With Expr (Maybe Expr) [Stmt] Pos
| Raise (Maybe Expr) (Maybe Expr) (Maybe Expr) Pos
| TryExcept [Stmt] [ExceptHandler] [Stmt] Pos
| TryFinally [Stmt] [Stmt] Pos
| Assert Expr (Maybe Expr) Pos
| Import [Alias] Pos
| ImportFrom (Maybe Identifier) [Alias] (Maybe Int) Pos
| Exec Expr (Maybe Expr) (Maybe Expr) Pos
| Global [Identifier] Pos
| Expr Expr Pos
| Pass Pos | Break Pos | Continue Pos
deriving (Show, Data, Typeable, Eq)
data Expr = BoolOp BoolOperator [Expr]
| BinOP Expr Operator Expr
| UnaryOp UnaryOp Expr
| Lambda Arguments Expr
| IfExp Expr Expr Expr
| Dict [Expr] [Expr]
| Set [Expr]
| ListComp Expr [Comprehension]
| SetComp Expr [Comprehension]
| DictComp Expr Expr [Comprehension]
| GeneratorsExpr Expr [Comprehension]
| Yield (Maybe Expr)
| Compare Expr [CmpOp] [Expr]
| Call Expr [Expr] [Keyword] (Maybe Expr) (Maybe Expr)
| Repr Expr
| Num Float
| Str String
| Attribute Expr Identifier ExprContext
| Subscript Expr Slice ExprContext
| Name Identifier ExprContext
| List [Expr] ExprContext
| Tuple [Expr] ExprContext
deriving (Show, Data, Typeable, Eq)
data ExprContext = Load | Store | Del | AugLoad | AugStore | Param deriving (Eq, Show, Data, Typeable)
data Slice = Ellipsis
| Slice (Maybe Expr) (Maybe Expr) (Maybe Expr)
| ExtSlice [Slice]
| Index Expr
deriving (Show, Data, Typeable, Eq)
data BoolOperator = And | Or deriving (Show, Data, Typeable, Eq)
data Operator = Add | Sub | Mult | Div | Mod | Pow | LShift
| RShift | BitOr | BitXor | BitAnd | FloorDiv
deriving (Show, Data, Typeable, Eq)
data UnaryOp = Invert | Not | UAdd | USub deriving (Show, Data, Typeable, Eq)
data CmpOp = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn deriving (Show, Data, Typeable, Eq)
data Comprehension = Comprehension Expr Expr [Expr] deriving (Show, Data, Typeable, Eq)
data ExceptHandler = ExceptHandler (Maybe Expr) (Maybe Expr) [Stmt] deriving (Show, Data, Typeable, Eq)
data Arguments = Arguments [Expr] (Maybe Identifier) (Maybe Identifier) [Expr] deriving (Show, Data, Typeable, Eq)
data Keyword = Keyword Identifier Expr deriving (Show, Data, Typeable, Eq)
data Alias = Alias Identifier (Maybe Identifier) deriving (Show, Data, Typeable, Eq)
type Identifier = String