@@ -421,6 +421,28 @@ class Builder {
421
421
) ;
422
422
}
423
423
424
+ expandMapFilterMacro (
425
+ offset : number ,
426
+ target : Expr ,
427
+ x : string ,
428
+ test : Expr ,
429
+ step : Expr ,
430
+ ) : Expr {
431
+ return this . newListMacro (
432
+ offset ,
433
+ target ,
434
+ x ,
435
+ this . newCallExpr ( offset , "_?_:_" , [
436
+ test ,
437
+ this . newCallExpr ( offset , "_+_" , [
438
+ this . newIdentExpr ( offset , "__result__" ) ,
439
+ this . newListExpr ( offset , [ step ] ) ,
440
+ ] ) ,
441
+ this . newIdentExpr ( offset , "__result__" ) ,
442
+ ] ) ,
443
+ ) ;
444
+ }
445
+
424
446
expandFilterMacro ( offset : number , target : Expr , x : string , step : Expr ) : Expr {
425
447
return this . newListMacro (
426
448
offset ,
@@ -485,46 +507,56 @@ class Builder {
485
507
const callExpr = call . exprKind . value ;
486
508
const varName = callExpr . args [ 0 ] ;
487
509
if (
510
+ varName !== undefined &&
488
511
call . exprKind . value . target !== undefined &&
489
- callExpr . args . length === 2 &&
490
- varName . exprKind . case === "identExpr"
512
+ varName . exprKind ?. case === "identExpr"
491
513
) {
492
- switch ( callExpr . function ) {
493
- case "exists" :
494
- return this . expandExistsMacro (
495
- offset ,
496
- call . exprKind . value . target ,
497
- varName . exprKind . value . name ,
498
- call . exprKind . value . args [ 1 ] ,
499
- ) ;
500
- case "all" :
501
- return this . expandAllMacro (
502
- offset ,
503
- call . exprKind . value . target ,
504
- varName . exprKind . value . name ,
505
- call . exprKind . value . args [ 1 ] ,
506
- ) ;
507
- case "map" :
508
- return this . expandMapMacro (
509
- offset ,
510
- call . exprKind . value . target ,
511
- varName . exprKind . value . name ,
512
- call . exprKind . value . args [ 1 ] ,
513
- ) ;
514
- case "filter" :
515
- return this . expandFilterMacro (
516
- offset ,
517
- call . exprKind . value . target ,
518
- varName . exprKind . value . name ,
519
- call . exprKind . value . args [ 1 ] ,
520
- ) ;
521
- case "exists_one" :
522
- return this . expandExistsOne (
523
- offset ,
524
- call . exprKind . value . target ,
525
- varName . exprKind . value . name ,
526
- call . exprKind . value . args [ 1 ] ,
527
- ) ;
514
+ if ( callExpr . args . length === 2 ) {
515
+ switch ( callExpr . function ) {
516
+ case "exists" :
517
+ return this . expandExistsMacro (
518
+ offset ,
519
+ call . exprKind . value . target ,
520
+ varName . exprKind . value . name ,
521
+ call . exprKind . value . args [ 1 ] ,
522
+ ) ;
523
+ case "all" :
524
+ return this . expandAllMacro (
525
+ offset ,
526
+ call . exprKind . value . target ,
527
+ varName . exprKind . value . name ,
528
+ call . exprKind . value . args [ 1 ] ,
529
+ ) ;
530
+ case "map" :
531
+ return this . expandMapMacro (
532
+ offset ,
533
+ call . exprKind . value . target ,
534
+ varName . exprKind . value . name ,
535
+ call . exprKind . value . args [ 1 ] ,
536
+ ) ;
537
+ case "filter" :
538
+ return this . expandFilterMacro (
539
+ offset ,
540
+ call . exprKind . value . target ,
541
+ varName . exprKind . value . name ,
542
+ call . exprKind . value . args [ 1 ] ,
543
+ ) ;
544
+ case "exists_one" :
545
+ return this . expandExistsOne (
546
+ offset ,
547
+ call . exprKind . value . target ,
548
+ varName . exprKind . value . name ,
549
+ call . exprKind . value . args [ 1 ] ,
550
+ ) ;
551
+ }
552
+ } else if ( callExpr . args . length === 3 && callExpr . function == "map" ) {
553
+ return this . expandMapFilterMacro (
554
+ offset ,
555
+ call . exprKind . value . target ,
556
+ varName . exprKind . value . name ,
557
+ call . exprKind . value . args [ 1 ] ,
558
+ call . exprKind . value . args [ 2 ] ,
559
+ ) ;
528
560
}
529
561
}
530
562
}
0 commit comments