1
1
package dotty .tools .dotc
2
2
package printing
3
- import core .Contexts .Context
4
3
import language .implicitConversions
5
4
6
5
object Texts {
@@ -12,7 +11,7 @@ object Texts {
12
11
def relems : List [Text ]
13
12
14
13
def isEmpty : Boolean = this match {
15
- case Str (s) => s.isEmpty
14
+ case Str (s, _, _ ) => s.isEmpty
16
15
case Fluid (relems) => relems forall (_.isEmpty)
17
16
case Vertical (relems) => relems.isEmpty
18
17
}
@@ -25,7 +24,7 @@ object Texts {
25
24
def close = new Closed (relems)
26
25
27
26
def remaining (width : Int ): Int = this match {
28
- case Str (s) =>
27
+ case Str (s, _, _ ) =>
29
28
width - s.length
30
29
case Fluid (Nil ) =>
31
30
width
@@ -37,15 +36,15 @@ object Texts {
37
36
}
38
37
39
38
def lastLine : String = this match {
40
- case Str (s) => s
39
+ case Str (s, _, _ ) => s
41
40
case _ => relems.head.lastLine
42
41
}
43
42
44
43
def appendToLastLine (that : Text ): Text = that match {
45
- case Str (s2) =>
44
+ case Str (s2, start1, end1 ) =>
46
45
this match {
47
- case Str (s1) => Str (s1 + s2)
48
- case Fluid (Str (s1) :: prev) => Fluid (Str (s1 + s2) :: prev)
46
+ case Str (s1, start2, end2 ) => Str (s1 + s2, start1 min start2, end1 max end2 )
47
+ case Fluid (Str (s1, start2, end2 ) :: prev) => Fluid (Str (s1 + s2, start1 min start2, end1 max end2 ) :: prev)
49
48
case Fluid (relems) => Fluid (that :: relems)
50
49
}
51
50
case Fluid (relems) =>
@@ -66,7 +65,7 @@ object Texts {
66
65
}
67
66
68
67
def layout (width : Int ): Text = this match {
69
- case Str (_) =>
68
+ case Str (s, _, _) =>
70
69
this
71
70
case Fluid (relems) =>
72
71
((Str (" " ): Text ) /: relems.reverse)(_.append(width)(_))
@@ -75,13 +74,13 @@ object Texts {
75
74
}
76
75
77
76
def map (f : String => String ): Text = this match {
78
- case Str (s) => Str (f(s))
77
+ case Str (s, start, end ) => Str (f(s), start, end )
79
78
case Fluid (relems) => Fluid (relems map (_ map f))
80
79
case Vertical (relems) => Vertical (relems map (_ map f))
81
80
}
82
81
83
82
def stripPrefix (pre : String ): Text = this match {
84
- case Str (s) =>
83
+ case Str (s, _, _ ) =>
85
84
if (s.startsWith(pre)) s drop pre.length else s
86
85
case Fluid (relems) =>
87
86
val elems = relems.reverse
@@ -94,14 +93,18 @@ object Texts {
94
93
}
95
94
96
95
private def indented : Text = this match {
97
- case Str (s) => Str ((" " * indentMargin) + s)
96
+ case Str (s, start, end ) => Str ((" " * indentMargin) + s, start, end )
98
97
case Fluid (relems) => Fluid (relems map (_.indented))
99
98
case Vertical (relems) => Vertical (relems map (_.indented))
100
99
}
101
100
102
101
def print (sb : StringBuilder ): Unit = this match {
103
- case Str (s) =>
102
+ case Str (s, start, end ) =>
104
103
sb.append(s)
104
+ if (start == end)
105
+ sb.append(s " // @line ${start + 1 }" )
106
+ else if (start != Int .MaxValue )
107
+ sb.append(s " // @lines ${start + 1 } to ${end + 1 }" )
105
108
case _ =>
106
109
var follow = false
107
110
for (elem <- relems.reverse) {
@@ -155,7 +158,7 @@ object Texts {
155
158
def lines (xs : Traversable [Text ]) = Vertical (xs.toList.reverse)
156
159
}
157
160
158
- case class Str (s : String ) extends Text {
161
+ case class Str (s : String , startLine : Int = Int . MaxValue , endLine : Int = - 1 ) extends Text {
159
162
override def relems : List [Text ] = List (this )
160
163
}
161
164
0 commit comments