@@ -5,7 +5,7 @@ use std::mem;
5
5
use mbe:: { SyntheticToken , SyntheticTokenId , TokenMap } ;
6
6
use rustc_hash:: FxHashMap ;
7
7
use syntax:: {
8
- ast:: { self , AstNode } ,
8
+ ast:: { self , AstNode , HasLoopBody } ,
9
9
match_ast, SyntaxElement , SyntaxKind , SyntaxNode , TextRange ,
10
10
} ;
11
11
use tt:: Subtree ;
@@ -142,6 +142,46 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
142
142
] ) ;
143
143
}
144
144
} ,
145
+ ast:: WhileExpr ( it) => {
146
+ println!( "Found while" ) ;
147
+ if it. condition( ) . is_none( ) {
148
+ println!( "Found no condition" ) ;
149
+ // insert placeholder token after the while token
150
+ let while_token = match it. while_token( ) {
151
+ Some ( t) => t,
152
+ None => continue ,
153
+ } ;
154
+ append. insert( while_token. into( ) , vec![
155
+ SyntheticToken {
156
+ kind: SyntaxKind :: IDENT ,
157
+ text: "__ra_fixup" . into( ) ,
158
+ range: end_range,
159
+ id: EMPTY_ID ,
160
+ } ,
161
+ ] ) ;
162
+ } else {
163
+ println!( "Found condition: {:?}" , it. condition( ) )
164
+ }
165
+ if it. loop_body( ) . is_none( ) {
166
+ println!( "Found no body" ) ;
167
+ append. insert( node. clone( ) . into( ) , vec![
168
+ SyntheticToken {
169
+ kind: SyntaxKind :: L_CURLY ,
170
+ text: "{" . into( ) ,
171
+ range: end_range,
172
+ id: EMPTY_ID ,
173
+ } ,
174
+ SyntheticToken {
175
+ kind: SyntaxKind :: R_CURLY ,
176
+ text: "}" . into( ) ,
177
+ range: end_range,
178
+ id: EMPTY_ID ,
179
+ } ,
180
+ ] ) ;
181
+ } else {
182
+ println!( "Found loop body: {:?}" , it. loop_body( ) )
183
+ }
184
+ } ,
145
185
// FIXME: foo::
146
186
// FIXME: for, loop, match etc.
147
187
_ => ( ) ,
@@ -376,6 +416,47 @@ fn foo() {
376
416
// the {} gets parsed as the condition, I think?
377
417
expect ! [ [ r#"
378
418
fn foo () {if {} {}}
419
+ "# ] ] ,
420
+ )
421
+ }
422
+
423
+ #[ test]
424
+ fn fixup_while_1 ( ) {
425
+ check (
426
+ r#"
427
+ fn foo() {
428
+ while
429
+ }
430
+ "# ,
431
+ expect ! [ [ r#"
432
+ fn foo () {while __ra_fixup {}}
433
+ "# ] ] ,
434
+ )
435
+ }
436
+
437
+ #[ test]
438
+ fn fixup_while_2 ( ) {
439
+ check (
440
+ r#"
441
+ fn foo() {
442
+ while foo
443
+ }
444
+ "# ,
445
+ expect ! [ [ r#"
446
+ fn foo () {while foo {}}
447
+ "# ] ] ,
448
+ )
449
+ }
450
+ #[ test]
451
+ fn fixup_while_3 ( ) {
452
+ check (
453
+ r#"
454
+ fn foo() {
455
+ while {}
456
+ }
457
+ "# ,
458
+ expect ! [ [ r#"
459
+ fn foo () {while {}}
379
460
"# ] ] ,
380
461
)
381
462
}
0 commit comments