~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/core/Mono.Texteditor/Mono.TextEditor.Highlighting/SyntaxModeService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
                        }
180
180
                }
181
181
                
182
 
                public static void ScanSpans (Document doc, SyntaxMode mode, Rule rule, Stack<Span> spanStack, int start, int end)
 
182
                public static void ScanSpans (Document doc, SyntaxMode mode, Rule rule, CloneableStack<Span> spanStack, int start, int end)
183
183
                {
184
184
                        SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
185
185
                        parser.ParseSpans (start, end - start);
186
186
                }
187
187
                
188
 
                static bool IsEqual (Span[] spans1, Span[] spans2)
189
 
                {
190
 
                        if (spans1 == null || spans1.Length == 0) 
191
 
                                return spans2 == null || spans2.Length == 0;
192
 
                        if (spans2 == null || spans1.Length != spans2.Length)
193
 
                                return false;
194
 
                        for (int i = 0; i < spans1.Length; i++) {
195
 
                                if (spans1[i] != spans2[i]) {
196
 
                                        return false;
197
 
                                }
198
 
                        }
199
 
                        return true;
200
 
                }
201
 
                
202
188
                static Queue<UpdateWorker> updateQueue = new Queue<UpdateWorker> ();
203
189
                
204
190
                class UpdateWorker
231
217
                                ManualResetEvent = new ManualResetEvent (false);
232
218
                        }
233
219
                        
234
 
                        protected void ScanSpansThreaded (Document doc, Rule rule, Stack<Span> spanStack, int start, int end)
235
 
                        {
236
 
                                SyntaxMode.SpanParser parser = mode.CreateSpanParser (doc, mode, null, spanStack);
237
 
                                parser.ParseSpans (start, end - start);
238
 
                        }
239
220
                        
240
221
                        bool EndsWithContinuation (Span span, LineSegment line)
241
222
                        {
246
227
                        public void InnerRun ()
247
228
                        {
248
229
                                bool doUpdate = false;
249
 
                                LineSegment lineSegment = doc.GetLineByOffset (startOffset);
250
 
                                if (lineSegment == null)
251
 
                                        return;
252
 
                                RedBlackTree<LineSegmentTree.TreeNode>.RedBlackTreeIterator iter = lineSegment.Iter;
253
 
                                if (iter == null || iter.Current == null)
254
 
                                        return;
255
 
                                Stack<Span> spanStack = iter.Current.StartSpan != null ? new Stack<Span> (iter.Current.StartSpan) : new Stack<Span> ();
 
230
                                int startLine = doc.OffsetToLineNumber (startOffset);
 
231
                                if (startLine < 0)
 
232
                                        return;
256
233
                                try {
257
 
                                        LineSegment oldLine = iter.Current.Offset > 0 ? doc.GetLineByOffset (iter.Current.Offset - 1) : null;
258
 
                                        do {
259
 
                                                LineSegment line = iter.Current;
260
 
                                                if (line == null || line.Offset < 0)
261
 
                                                        break;
262
 
                                                
263
 
                                                List<Span> spanList = new List<Span> (spanStack.ToArray ());
264
 
                                                spanList.Reverse ();
265
 
                                                for (int i = 0; i < spanList.Count; i++) {
266
 
                                                        if (!EndsWithContinuation (spanList[i], oldLine)) {
267
 
                                                                spanList.RemoveAt (i);
268
 
                                                                i--;
269
 
                                                        }
270
 
                                                }
271
 
                                                Span[] newSpans = spanList.ToArray ();
 
234
                                        var lineSegment = doc.GetLine (startLine);
 
235
                                        if (lineSegment == null)
 
236
                                                return;
 
237
                                        var span = lineSegment.StartSpan;
 
238
                                        if (span == null)
 
239
                                                return;
 
240
                                        var spanStack = span.Clone ();
 
241
                                        SyntaxMode.SpanParser parser = mode.CreateSpanParser(doc, mode, null, spanStack);
 
242
                                        foreach (var line in doc.GetLinesStartingAt (startLine)) {
 
243
                                                if (line == null)
 
244
                                                        return;
272
245
                                                if (line.Offset > endOffset) {
273
 
                                                        bool equal = IsEqual (line.StartSpan, newSpans);
274
 
                                                        doUpdate |= !equal;
275
 
                                                        if (equal)
276
 
                                                                break;
277
 
                                                }
278
 
                                                line.StartSpan = newSpans.Length > 0 ? newSpans : null;
279
 
                                                oldLine = line;
280
 
                                                Rule rule = mode;
281
 
                                                if (spanStack.Count > 0 && !String.IsNullOrEmpty (spanStack.Peek ().Rule))
282
 
                                                        rule = mode.GetRule (spanStack.Peek ().Rule) ?? mode;
283
 
                                                
284
 
                                                ScanSpansThreaded (doc, rule, spanStack, line.Offset, line.EndOffset);
285
 
                                                while (spanStack.Count > 0 && !EndsWithContinuation (spanStack.Peek (), line))
286
 
                                                        spanStack.Pop ();
287
 
                                        
288
 
                                        } while (iter.MoveNext ());
 
246
                                                        span = line.StartSpan;
 
247
                                                        if (span == null)
 
248
                                                                return;
 
249
                                                        bool equal = span.Equals(spanStack);
 
250
                                                        doUpdate |= !equal;
 
251
                                                        if (equal)
 
252
                                                                break;
 
253
                                                }
 
254
                                                line.StartSpan = spanStack.Clone();
 
255
                                                parser.ParseSpans(line.Offset, line.Length);
 
256
                                                while (spanStack.Count > 0 && !EndsWithContinuation(spanStack.Peek(), line))
 
257
                                                        parser.PopSpan();
 
258
                                        }
289
259
                                } catch (Exception e) {
290
260
                                        Console.WriteLine ("Syntax highlighting exception:" + e);
291
261
                                }
347
317
                                        if (worker != null && worker.Doc == doc)
348
318
                                                worker.ManualResetEvent.WaitOne ();
349
319
                                } catch (Exception e) {
350
 
                                        Console.WriteLine ("Worker:" + worker);
351
 
                                        Console.WriteLine ("------");
352
320
                                        Console.WriteLine (e);
353
 
                                        Console.WriteLine ("------");
354
 
                                        Console.WriteLine ("worker.Doc:" + worker.Doc);
355
 
                                        Console.WriteLine ("worker.IsFinished:" + worker.IsFinished);
356
 
                                        Console.WriteLine ("worker.ManualResetEvent:" + worker.ManualResetEvent);
357
321
                                }
358
322
                        }
359
323
                }