@@ -3,102 +3,71 @@ use crate::converter::common::Convertible;
33use crate :: converter:: common:: ConvertibleIn ;
44use crate :: converter:: common:: { DimContext , ExprContext } ;
55use crate :: converter:: statement:: { assignment, const_rules} ;
6+ use crate :: core:: NameContext ;
67use crate :: core:: { LintError , LintErrorPos } ;
7- use crate :: core:: { LintPosResult , NameContext } ;
88use rusty_common:: * ;
9- use rusty_parser:: { ExitObject , Statement , StatementPos , Statements } ;
9+ use rusty_parser:: { ExitObject , Statement } ;
1010
11- impl Convertible < Option < Self > > for StatementPos {
12- fn convert ( self , ctx : & mut Context ) -> Result < Option < Self > , LintErrorPos > {
13- let Self {
14- element : statement,
15- pos,
16- } = self ;
17- statement
18- . convert_in ( ctx, pos)
19- . map ( |opt_statement| opt_statement. map ( |s| s. at_pos ( pos) ) )
20- . patch_err_pos ( & pos)
21- }
22- }
23-
24- impl ConvertibleIn < Position , Option < Self > > for Statement {
25- fn convert_in ( self , ctx : & mut Context , pos : Position ) -> Result < Option < Self > , LintErrorPos > {
11+ impl ConvertibleIn < Position > for Statement {
12+ fn convert_in ( self , ctx : & mut Context , pos : Position ) -> Result < Self , LintErrorPos > {
2613 match self {
27- Self :: Assignment ( n, e) => assignment:: on_assignment ( n, e, ctx, pos) . map ( Some ) ,
14+ Self :: Assignment ( n, e) => assignment:: on_assignment ( n, e, ctx, pos) ,
2815 // CONST is mapped to None and is filtered out
29- Self :: Const ( n, e) => const_rules:: on_const ( ctx, n, e) . map ( |_| None ) ,
30- Self :: SubCall ( n, args) => ctx. sub_call ( n, args) . map ( Some ) ,
16+ Self :: Const ( n, e) => const_rules:: on_const ( ctx, n, e) ,
17+ Self :: SubCall ( n, args) => ctx. sub_call ( n, args) ,
3118 Self :: BuiltInSubCall ( built_in_sub, args) => {
3219 let converted_args = args. convert_in ( ctx, ExprContext :: Argument ) ?;
33- Ok ( Self :: BuiltInSubCall ( built_in_sub, converted_args) ) . map ( Some )
20+ Ok ( Self :: BuiltInSubCall ( built_in_sub, converted_args) )
3421 }
35- Self :: IfBlock ( i) => i. convert ( ctx) . map ( Statement :: IfBlock ) . map ( Some ) ,
36- Self :: SelectCase ( s) => s. convert ( ctx) . map ( Statement :: SelectCase ) . map ( Some ) ,
37- Self :: ForLoop ( f) => f. convert ( ctx) . map ( Statement :: ForLoop ) . map ( Some ) ,
38- Self :: While ( c) => c. convert ( ctx) . map ( Statement :: While ) . map ( Some ) ,
39- Self :: DoLoop ( do_loop) => do_loop. convert ( ctx) . map ( Statement :: DoLoop ) . map ( Some ) ,
22+ Self :: IfBlock ( i) => i. convert ( ctx) . map ( Statement :: IfBlock ) ,
23+ Self :: SelectCase ( s) => s. convert ( ctx) . map ( Statement :: SelectCase ) ,
24+ Self :: ForLoop ( f) => f. convert ( ctx) . map ( Statement :: ForLoop ) ,
25+ Self :: While ( c) => c. convert ( ctx) . map ( Statement :: While ) ,
26+ Self :: DoLoop ( do_loop) => do_loop. convert ( ctx) . map ( Statement :: DoLoop ) ,
4027 Self :: Return ( opt_label) => {
4128 if opt_label. is_some ( ) && ctx. is_in_subprogram ( ) {
4229 // cannot have RETURN with explicit label inside subprogram
4330 Err ( LintError :: IllegalInSubFunction . at_no_pos ( ) )
4431 } else {
45- Ok ( Self :: Return ( opt_label) ) . map ( Some )
32+ Ok ( Self :: Return ( opt_label) )
4633 }
4734 }
4835 Self :: Resume ( resume_option) => {
4936 if ctx. is_in_subprogram ( ) {
5037 Err ( LintError :: IllegalInSubFunction . at_no_pos ( ) )
5138 } else {
52- Ok ( Self :: Resume ( resume_option) ) . map ( Some )
39+ Ok ( Self :: Resume ( resume_option) )
5340 }
5441 }
5542 Self :: Exit ( exit_object) => match ctx. names . get_name_context ( ) {
5643 NameContext :: Global => Err ( LintError :: IllegalOutsideSubFunction . at_no_pos ( ) ) ,
5744 NameContext :: Sub => {
5845 if exit_object == ExitObject :: Sub {
59- Ok ( Self :: Exit ( exit_object) ) . map ( Some )
46+ Ok ( Self :: Exit ( exit_object) )
6047 } else {
6148 Err ( LintError :: IllegalInSubFunction . at_no_pos ( ) )
6249 }
6350 }
6451 NameContext :: Function => {
6552 if exit_object == ExitObject :: Function {
66- Ok ( Self :: Exit ( exit_object) ) . map ( Some )
53+ Ok ( Self :: Exit ( exit_object) )
6754 } else {
6855 Err ( LintError :: IllegalInSubFunction . at_no_pos ( ) )
6956 }
7057 }
7158 } ,
72- Self :: Dim ( dim_list) => dim_list
73- . convert_in_default ( ctx)
74- . map ( Statement :: Dim )
75- . map ( Some ) ,
59+ Self :: Dim ( dim_list) => dim_list. convert_in_default ( ctx) . map ( Statement :: Dim ) ,
7660 Self :: Redim ( dim_list) => dim_list
7761 . convert_in ( ctx, DimContext :: Redim )
78- . map ( Statement :: Redim )
79- . map ( Some ) ,
80- Self :: Print ( print) => print. convert ( ctx) . map ( Statement :: Print ) . map ( Some ) ,
62+ . map ( Statement :: Redim ) ,
63+ Self :: Print ( print) => print. convert ( ctx) . map ( Statement :: Print ) ,
8164 Self :: OnError ( _)
8265 | Self :: Label ( _)
8366 | Self :: GoTo ( _)
8467 | Self :: GoSub ( _)
8568 | Self :: Comment ( _)
8669 | Self :: End
87- | Self :: System => Ok ( self ) . map ( Some ) ,
70+ | Self :: System => Ok ( self ) ,
8871 }
8972 }
9073}
91-
92- impl Convertible for Statements {
93- fn convert ( self , ctx : & mut Context ) -> Result < Self , LintErrorPos > {
94- self . into_iter ( )
95- . map ( |s| s. convert ( ctx) )
96- . map ( |res| match res {
97- Ok ( Some ( s) ) => Some ( Ok ( s) ) ,
98- Err ( e) => Some ( Err ( e) ) ,
99- Ok ( None ) => None ,
100- } )
101- . flat_map ( |opt| opt. into_iter ( ) )
102- . collect ( )
103- }
104- }
0 commit comments