@@ -21,8 +21,25 @@ case class Collectionstrawman_v0(mirror: SemanticCtx)
21
21
toImport.asPatch
22
22
}
23
23
24
+ val rangeImport = Symbol (" _root_.strawman.collection.immutable.Range." )
25
+ val inclusiveRange = Symbol (
26
+ " _root_.scala.runtime.RichInt#to(I)Lscala/collection/immutable/Range/Inclusive;." )
27
+ val rangeSymbol = Symbol (
28
+ " _root_.scala.runtime.RichInt#until(I)Lscala/collection/immutable/Range;." )
29
+ def range (ctx : RewriteCtx ): Patch = {
30
+ ctx.tree.collect {
31
+ case tree @ Term .ApplyInfix (lhs, op, targs, arg :: Nil )
32
+ if op.symbol.contains(inclusiveRange) =>
33
+ ctx.replaceTree(tree, q " Range.inclusive( $lhs, $arg) " .syntax) +
34
+ ctx.addGlobalImport(rangeImport)
35
+ case tree @ Term .ApplyInfix (lhs, op, targs, arg :: Nil )
36
+ if op.symbol.contains(rangeSymbol) =>
37
+ ctx.replaceTree(tree, q " Range( $lhs, $arg) " .syntax) +
38
+ ctx.addGlobalImport(rangeImport)
39
+ }
40
+ }.asPatch
41
+
24
42
def rewrite (ctx : RewriteCtx ): Patch = {
25
- ctx.debugMirror()
26
43
def p (name : String ) =
27
44
s " scala.Predef. $name" -> s " strawman.collection.immutable. $name"
28
45
def s (name : String , rename : Option [String ] = None ) =
@@ -32,28 +49,28 @@ case class Collectionstrawman_v0(mirror: SemanticCtx)
32
49
s " strawman.collection.immutable. ${rename.getOrElse(name)}"
33
50
def m (name : String ) =
34
51
s " scala.collection.mutable. $name" -> s " strawman.collection.mutable. $name"
35
- ifSymbolFound( ctx) +
36
- ctx.replaceSymbols(
37
- i(" HashMap " ),
38
- i (" Map" ),
39
- p( " Map " ),
40
- s (" List" ),
41
- i( " List " ),
42
- s (" Nil" ),
43
- i( " Nil " ),
44
- s (" `::`" ),
45
- i (" `: :`" ),
46
- s (" `+:`" ),
47
- i (" `+: `" ),
48
- s (" `:+`" ),
49
- i(" `:+` " ),
50
- i (" Stream" , Some (" LazyList" )),
51
- s(" Stream " , Some ( " LazyList " ) ),
52
- s(" `#::` " ),
53
- s( " `#::` " ),
54
- s( " Vector " ),
55
- i( " Vector " ),
56
- m( " ArrayBuffer " )
57
- )
52
+ ctx.replaceSymbols(
53
+ i( " HashMap " ),
54
+ i(" Map " ),
55
+ p (" Map" ),
56
+ s( " List " ),
57
+ i (" List" ),
58
+ s( " Nil " ),
59
+ i (" Nil" ),
60
+ s( " `::` " ),
61
+ i (" `::`" ),
62
+ s (" `+ :`" ),
63
+ i (" `+:`" ),
64
+ s (" `:+ `" ),
65
+ i (" `:+`" ),
66
+ i(" Stream " , Some ( " LazyList " ) ),
67
+ s (" Stream" , Some (" LazyList" )),
68
+ s(" `#::` " ),
69
+ s(" Vector " ),
70
+ i( " Vector " ),
71
+ m( " ArrayBuffer " )
72
+ ) +
73
+ ifSymbolFound(ctx) +
74
+ range(ctx )
58
75
}
59
76
}
0 commit comments