@@ -80,17 +80,21 @@ extension TracedProcessor {
8080 }
8181
8282 func formatInput( ) -> String {
83+ let distanceFromStart = input. distance (
84+ from: input. startIndex,
85+ to: currentPosition)
86+
8387 // Cut a reasonably sized substring from the input to print
8488 let start = input. index (
8589 currentPosition,
86- offsetBy: - 10 ,
90+ offsetBy: - 30 ,
8791 limitedBy: input. startIndex) ?? input. startIndex
8892 let end = input. index (
8993 currentPosition,
90- offsetBy: 10 ,
94+ offsetBy: 30 ,
9195 limitedBy: input. endIndex) ?? input. endIndex
92- let input = input [ start... end]
93-
96+ let input = input [ start..< end]
97+
9498 // String override for printing sub-character information.
9599 if !input. indices. contains ( currentPosition) {
96100 // Format unicode scalars as:
@@ -111,6 +115,7 @@ extension TracedProcessor {
111115 . joined ( ) )
112116 \( String ( repeating: " . " , count: matchedHighlightWidth) ) \
113117 ^ \( String ( repeating: " ~ " , count: nextHighlightWidth - 1 ) )
118+ position: \( distanceFromStart)
114119 """
115120 }
116121 if let string = input as? String {
@@ -119,10 +124,11 @@ extension TracedProcessor {
119124 return _format ( substring)
120125 }
121126 }
122- let dist = input. distance ( from: input . startIndex , to: currentPosition)
127+ let dist = input. distance ( from: start , to: currentPosition)
123128 return """
124129 input: \( input)
125130 \( String ( repeating: " ~ " , count: dist) ) ^
131+ position: \( distanceFromStart)
126132 """
127133 }
128134
0 commit comments