@@ -17,13 +17,13 @@ pub struct Node {
17
17
#[ derive( Debug , PartialEq ) ]
18
18
pub enum Top {
19
19
Program ( Program ) ,
20
- Statement ( Vec < LocatedStatement > ) ,
20
+ Statement ( Vec < Statement > ) ,
21
21
Expression ( Expression ) ,
22
22
}
23
23
24
24
#[ derive( Debug , PartialEq ) ]
25
25
pub struct Program {
26
- pub statements : Vec < LocatedStatement > ,
26
+ pub statements : Vec < Statement > ,
27
27
}
28
28
29
29
#[ derive( Debug , PartialEq ) ]
@@ -38,12 +38,12 @@ pub struct Located<T> {
38
38
pub node : T ,
39
39
}
40
40
41
- pub type LocatedStatement = Located < Statement > ;
41
+ pub type Statement = Located < StatementType > ;
42
42
43
43
/// Abstract syntax tree nodes for python statements.
44
44
#[ allow( clippy:: large_enum_variant) ]
45
45
#[ derive( Debug , PartialEq ) ]
46
- pub enum Statement {
46
+ pub enum StatementType {
47
47
Break ,
48
48
Continue ,
49
49
Return {
@@ -85,58 +85,58 @@ pub enum Statement {
85
85
} ,
86
86
If {
87
87
test : Expression ,
88
- body : Vec < LocatedStatement > ,
89
- orelse : Option < Vec < LocatedStatement > > ,
88
+ body : Vec < Statement > ,
89
+ orelse : Option < Vec < Statement > > ,
90
90
} ,
91
91
While {
92
92
test : Expression ,
93
- body : Vec < LocatedStatement > ,
94
- orelse : Option < Vec < LocatedStatement > > ,
93
+ body : Vec < Statement > ,
94
+ orelse : Option < Vec < Statement > > ,
95
95
} ,
96
96
With {
97
97
items : Vec < WithItem > ,
98
- body : Vec < LocatedStatement > ,
98
+ body : Vec < Statement > ,
99
99
} ,
100
100
For {
101
101
target : Expression ,
102
102
iter : Expression ,
103
- body : Vec < LocatedStatement > ,
104
- orelse : Option < Vec < LocatedStatement > > ,
103
+ body : Vec < Statement > ,
104
+ orelse : Option < Vec < Statement > > ,
105
105
} ,
106
106
AsyncFor {
107
107
target : Expression ,
108
108
iter : Expression ,
109
- body : Vec < LocatedStatement > ,
110
- orelse : Option < Vec < LocatedStatement > > ,
109
+ body : Vec < Statement > ,
110
+ orelse : Option < Vec < Statement > > ,
111
111
} ,
112
112
Raise {
113
113
exception : Option < Expression > ,
114
114
cause : Option < Expression > ,
115
115
} ,
116
116
Try {
117
- body : Vec < LocatedStatement > ,
117
+ body : Vec < Statement > ,
118
118
handlers : Vec < ExceptHandler > ,
119
- orelse : Option < Vec < LocatedStatement > > ,
120
- finalbody : Option < Vec < LocatedStatement > > ,
119
+ orelse : Option < Vec < Statement > > ,
120
+ finalbody : Option < Vec < Statement > > ,
121
121
} ,
122
122
ClassDef {
123
123
name : String ,
124
- body : Vec < LocatedStatement > ,
124
+ body : Vec < Statement > ,
125
125
bases : Vec < Expression > ,
126
126
keywords : Vec < Keyword > ,
127
127
decorator_list : Vec < Expression > ,
128
128
} ,
129
129
FunctionDef {
130
130
name : String ,
131
131
args : Parameters ,
132
- body : Vec < LocatedStatement > ,
132
+ body : Vec < Statement > ,
133
133
decorator_list : Vec < Expression > ,
134
134
returns : Option < Expression > ,
135
135
} ,
136
136
AsyncFunctionDef {
137
137
name : String ,
138
138
args : Parameters ,
139
- body : Vec < LocatedStatement > ,
139
+ body : Vec < Statement > ,
140
140
decorator_list : Vec < Expression > ,
141
141
returns : Option < Expression > ,
142
142
} ,
@@ -148,8 +148,10 @@ pub struct WithItem {
148
148
pub optional_vars : Option < Expression > ,
149
149
}
150
150
151
+ pub type Expression = Located < ExpressionType > ;
152
+
151
153
#[ derive( Debug , PartialEq ) ]
152
- pub enum Expression {
154
+ pub enum ExpressionType {
153
155
BoolOp {
154
156
a : Box < Expression > ,
155
157
op : BooleanOperator ,
@@ -242,10 +244,10 @@ pub enum Expression {
242
244
impl Expression {
243
245
/// Returns a short name for the node suitable for use in error messages.
244
246
pub fn name ( & self ) -> & ' static str {
245
- use self :: Expression :: * ;
247
+ use self :: ExpressionType :: * ;
246
248
use self :: StringGroup :: * ;
247
249
248
- match self {
250
+ match & self . node {
249
251
BoolOp { .. } | Binop { .. } | Unop { .. } => "operator" ,
250
252
Subscript { .. } => "subscript" ,
251
253
Await { .. } => "await expression" ,
@@ -305,6 +307,7 @@ pub struct Parameter {
305
307
pub annotation : Option < Box < Expression > > ,
306
308
}
307
309
310
+ #[ allow( clippy:: large_enum_variant) ]
308
311
#[ derive( Debug , PartialEq ) ]
309
312
pub enum ComprehensionKind {
310
313
GeneratorExpression { element : Expression } ,
@@ -330,7 +333,7 @@ pub struct Keyword {
330
333
pub struct ExceptHandler {
331
334
pub typ : Option < Expression > ,
332
335
pub name : Option < String > ,
333
- pub body : Vec < LocatedStatement > ,
336
+ pub body : Vec < Statement > ,
334
337
}
335
338
336
339
#[ derive( Debug , PartialEq ) ]
0 commit comments