@@ -52,7 +52,7 @@ pub fn parse_program(source: &String) -> Result<ast::Program, String> {
5252 }
5353}
5454
55- pub fn parse_statement ( source : & String ) -> Result < ast:: Statement , String > {
55+ pub fn parse_statement ( source : & String ) -> Result < ast:: LocatedStatement , String > {
5656 let lxr = lexer:: Lexer :: new ( & source) ;
5757 match python:: StatementParser :: new ( ) . parse ( lxr) {
5858 Err ( why) => Err ( String :: from ( format ! ( "{:?}" , why) ) ) ,
@@ -88,9 +88,9 @@ mod tests {
8888 assert_eq ! (
8989 parse_ast,
9090 ast:: Program {
91- statements: vec![ ast:: Statement {
91+ statements: vec![ ast:: LocatedStatement {
9292 location: ast:: Location :: new( 1 , 1 ) ,
93- statement : ast:: StatementType :: Expression {
93+ node : ast:: Statement :: Expression {
9494 expression: ast:: Expression :: Call {
9595 function: Box :: new( ast:: Expression :: Identifier {
9696 name: String :: from( "print" ) ,
@@ -112,9 +112,9 @@ mod tests {
112112 assert_eq ! (
113113 parse_ast,
114114 ast:: Program {
115- statements: vec![ ast:: Statement {
115+ statements: vec![ ast:: LocatedStatement {
116116 location: ast:: Location :: new( 1 , 1 ) ,
117- statement : ast:: StatementType :: Expression {
117+ node : ast:: Statement :: Expression {
118118 expression: ast:: Expression :: Call {
119119 function: Box :: new( ast:: Expression :: Identifier {
120120 name: String :: from( "print" ) ,
@@ -140,37 +140,37 @@ mod tests {
140140 let parse_ast = parse_statement ( & source) . unwrap ( ) ;
141141 assert_eq ! (
142142 parse_ast,
143- ast:: Statement {
143+ ast:: LocatedStatement {
144144 location: ast:: Location :: new( 1 , 1 ) ,
145- statement : ast:: StatementType :: If {
145+ node : ast:: Statement :: If {
146146 test: ast:: Expression :: Number {
147147 value: ast:: Number :: Integer { value: 1 } ,
148148 } ,
149- body: vec![ ast:: Statement {
149+ body: vec![ ast:: LocatedStatement {
150150 location: ast:: Location :: new( 1 , 7 ) ,
151- statement : ast:: StatementType :: Expression {
151+ node : ast:: Statement :: Expression {
152152 expression: ast:: Expression :: Number {
153153 value: ast:: Number :: Integer { value: 10 } ,
154154 }
155155 } ,
156156 } , ] ,
157- orelse: Some ( vec![ ast:: Statement {
157+ orelse: Some ( vec![ ast:: LocatedStatement {
158158 location: ast:: Location :: new( 2 , 1 ) ,
159- statement : ast:: StatementType :: If {
159+ node : ast:: Statement :: If {
160160 test: ast:: Expression :: Number {
161161 value: ast:: Number :: Integer { value: 2 } ,
162162 } ,
163- body: vec![ ast:: Statement {
163+ body: vec![ ast:: LocatedStatement {
164164 location: ast:: Location :: new( 2 , 9 ) ,
165- statement : ast:: StatementType :: Expression {
165+ node : ast:: Statement :: Expression {
166166 expression: ast:: Expression :: Number {
167167 value: ast:: Number :: Integer { value: 20 } ,
168168 } ,
169169 } ,
170170 } , ] ,
171- orelse: Some ( vec![ ast:: Statement {
171+ orelse: Some ( vec![ ast:: LocatedStatement {
172172 location: ast:: Location :: new( 3 , 7 ) ,
173- statement : ast:: StatementType :: Expression {
173+ node : ast:: Statement :: Expression {
174174 expression: ast:: Expression :: Number {
175175 value: ast:: Number :: Integer { value: 30 } ,
176176 } ,
@@ -189,9 +189,9 @@ mod tests {
189189 let parse_ast = parse_statement ( & source) ;
190190 assert_eq ! (
191191 parse_ast,
192- Ok ( ast:: Statement {
192+ Ok ( ast:: LocatedStatement {
193193 location: ast:: Location :: new( 1 , 1 ) ,
194- statement : ast:: StatementType :: Expression {
194+ node : ast:: Statement :: Expression {
195195 expression: ast:: Expression :: Lambda {
196196 args: vec![ String :: from( "x" ) , String :: from( "y" ) ] ,
197197 body: Box :: new( ast:: Expression :: Binop {
@@ -214,19 +214,19 @@ mod tests {
214214 let source = String :: from ( "class Foo(A, B):\n def __init__(self):\n pass\n " ) ;
215215 assert_eq ! (
216216 parse_statement( & source) ,
217- Ok ( ast:: Statement {
217+ Ok ( ast:: LocatedStatement {
218218 location: ast:: Location :: new( 1 , 1 ) ,
219- statement : ast:: StatementType :: ClassDef {
219+ node : ast:: Statement :: ClassDef {
220220 name: String :: from( "Foo" ) ,
221221 args: vec![ String :: from( "A" ) , String :: from( "B" ) ] ,
222- body: vec![ ast:: Statement {
222+ body: vec![ ast:: LocatedStatement {
223223 location: ast:: Location :: new( 2 , 2 ) ,
224- statement : ast:: StatementType :: FunctionDef {
224+ node : ast:: Statement :: FunctionDef {
225225 name: String :: from( "__init__" ) ,
226226 args: vec![ String :: from( "self" ) ] ,
227- body: vec![ ast:: Statement {
227+ body: vec![ ast:: LocatedStatement {
228228 location: ast:: Location :: new( 3 , 3 ) ,
229- statement : ast:: StatementType :: Pass ,
229+ node : ast:: Statement :: Pass ,
230230 } ] ,
231231 }
232232 } ] ,
0 commit comments