@@ -10,7 +10,7 @@ use crate::{
10
10
Label , LetStatement , Lifetime , LifetimeParam , Literal , LiteralKind , Mod , Param , Path ,
11
11
PathSegment , Pattern , Safety , SelfParam , SimplePath , SimplePathSegment , Spanned , Statement ,
12
12
StructCtor , StructField , StructKind , TraitDef , TupleCtor , TupleField , Type , TypeParam ,
13
- UnaryOp , UserType , UserTypeBody , Visibility , WhereClause ,
13
+ UnaryOp , UserType , UserTypeBody , Visibility , WhereClause , IfBlock , CondBlock ,
14
14
} ,
15
15
interning:: Symbol ,
16
16
lex:: {
@@ -754,10 +754,56 @@ pub fn do_item_user_type(
754
754
} )
755
755
}
756
756
757
+ pub fn do_if_block (
758
+ tree : & mut PeekMoreIterator < impl Iterator < Item = Lexeme > > ,
759
+ ) -> Result < Spanned < IfBlock > > {
760
+ let mut tree = tree. into_rewinder ( ) ;
761
+ let span_start = do_lexeme_class ( & mut tree, LexemeClass :: Keyword ( Keyword :: If ) ) ?. span ;
762
+ let cond = Box :: new ( do_expression_without_constructor ( & mut tree) ?) ;
763
+ let block = do_block ( & mut tree) ?;
764
+ let mut span_end = block. span ;
765
+ let mut elseifs = Vec :: new ( ) ;
766
+ let mut elseblock = None ;
767
+ while let Ok ( Lexeme { span : else_span, .. } ) = do_lexeme_class ( & mut tree, LexemeClass :: Keyword ( Keyword :: Else ) ) {
768
+ match do_lexeme_class ( & mut tree, LexemeClass :: Keyword ( Keyword :: If ) ) {
769
+ Ok ( Lexeme { span : if_span, .. } ) => {
770
+ let cond = Box :: new ( do_expression_without_constructor ( & mut tree) ?) ;
771
+ let block = do_block ( & mut tree) ?;
772
+ span_end = block. span ;
773
+ let span = Span :: between ( if_span, block. span ) ;
774
+ elseifs. push ( Spanned {
775
+ body : CondBlock {
776
+ cond,
777
+ block,
778
+ } ,
779
+ span,
780
+ } ) ;
781
+ }
782
+ Err ( _) => {
783
+ let block = do_block ( & mut tree) ?;
784
+ span_end = block. span ;
785
+ elseblock = Some ( block) ;
786
+ break ;
787
+ }
788
+ }
789
+ }
790
+ tree. accept ( ) ;
791
+ let span = Span :: between ( span_start, span_end) ;
792
+ Ok ( Spanned {
793
+ body : IfBlock { cond, block, elseifs, elseblock } ,
794
+ span,
795
+ } )
796
+ }
797
+
757
798
pub fn do_compound_block (
758
799
tree : & mut PeekMoreIterator < impl Iterator < Item = Lexeme > > ,
759
800
) -> Result < Spanned < CompoundBlock > > {
760
- // TODO: support more than `unsafe` and `loop`
801
+ if let Ok ( if_block) = do_if_block ( tree) {
802
+ return Ok ( Spanned {
803
+ span : if_block. span ,
804
+ body : CompoundBlock :: If ( if_block) ,
805
+ } ) ;
806
+ }
761
807
let mut tree = tree. into_rewinder ( ) ;
762
808
let (
763
809
Lexeme {
0 commit comments