91 else if (tok.is_ignored) whitespace += tok |
91 else if (tok.is_ignored) whitespace += tok |
92 else { span ++= whitespace; whitespace.clear; span += tok } |
92 else { span ++= whitespace; whitespace.clear; span += tok } |
93 } |
93 } |
94 flush(span); flush(whitespace) |
94 flush(span); flush(whitespace) |
95 result.toList |
95 result.toList |
|
96 } |
|
97 |
|
98 |
|
99 |
|
100 /** command perspective **/ |
|
101 |
|
102 def command_perspective(node: Document.Node, perspective: Text.Perspective): Command.Perspective = |
|
103 { |
|
104 if (perspective.isEmpty) Nil |
|
105 else { |
|
106 val result = new mutable.ListBuffer[Command] |
|
107 @tailrec |
|
108 def check_ranges(ranges: List[Text.Range], commands: Stream[(Command, Text.Offset)]) |
|
109 { |
|
110 (ranges, commands) match { |
|
111 case (range :: more_ranges, (command, offset) #:: more_commands) => |
|
112 val command_range = command.range + offset |
|
113 range compare command_range match { |
|
114 case -1 => check_ranges(more_ranges, commands) |
|
115 case 0 => |
|
116 result += command |
|
117 check_ranges(ranges, more_commands) |
|
118 case 1 => check_ranges(ranges, more_commands) |
|
119 } |
|
120 case _ => |
|
121 } |
|
122 } |
|
123 val perspective_range = Text.Range(perspective.head.start, perspective.last.stop) |
|
124 check_ranges(perspective, node.command_range(perspective_range).toStream) |
|
125 result.toList |
|
126 } |
96 } |
127 } |
97 |
128 |
98 |
129 |
99 |
130 |
100 /** text edits **/ |
131 /** text edits **/ |
170 case None => commands |
201 case None => commands |
171 } |
202 } |
172 } |
203 } |
173 |
204 |
174 |
205 |
175 /* command perspective */ |
|
176 |
|
177 def command_perspective(node: Document.Node, perspective: Text.Perspective) |
|
178 : Command.Perspective = |
|
179 { |
|
180 if (perspective.isEmpty) Nil |
|
181 else { |
|
182 val result = new mutable.ListBuffer[Command] |
|
183 @tailrec |
|
184 def check_ranges(ranges: List[Text.Range], commands: Stream[(Command, Text.Offset)]) |
|
185 { |
|
186 (ranges, commands) match { |
|
187 case (range :: more_ranges, (command, offset) #:: more_commands) => |
|
188 val command_range = command.range + offset |
|
189 range compare command_range match { |
|
190 case -1 => check_ranges(more_ranges, commands) |
|
191 case 0 => |
|
192 result += command |
|
193 check_ranges(ranges, more_commands) |
|
194 case 1 => check_ranges(ranges, more_commands) |
|
195 } |
|
196 case _ => |
|
197 } |
|
198 } |
|
199 val perspective_range = Text.Range(perspective.head.start, perspective.last.stop) |
|
200 check_ranges(perspective, node.command_range(perspective_range).toStream) |
|
201 result.toList |
|
202 } |
|
203 } |
|
204 |
|
205 |
|
206 /* resulting document edits */ |
206 /* resulting document edits */ |
207 |
207 |
208 { |
208 { |
209 val doc_edits = new mutable.ListBuffer[Document.Edit_Command] |
209 val doc_edits = new mutable.ListBuffer[Document.Edit_Command] |
210 var nodes = previous.nodes |
210 var nodes = previous.nodes |