14 using System.Collections.Generic;
17 using System.Threading;
18 using System.Runtime.InteropServices;
19 using System.Diagnostics;
23 namespace Irony.GrammarExplorer {
33 Thread _colorizerThread;
38 _scanner = _parser.Scanner;
39 _colorizerThread =
new Thread(ColorizerLoop);
40 _colorizerThread.IsBackground =
true;
41 _parserThread =
new Thread(ParserLoop);
42 _parserThread.IsBackground =
true;
45 if ((_colorizerThread.ThreadState & System.Threading.ThreadState.Running) == 0) {
46 _parserThread.Start();
47 _colorizerThread.Start();
54 _parserThread.Join(500);
55 if(_parserThread.IsAlive)
56 _parserThread.Abort();
57 _colorizerThread.Join(500);
58 if(_colorizerThread.IsAlive)
59 _colorizerThread.Abort();
61 System.Diagnostics.Debug.WriteLine(
"Error when stopping EditorAdapter: " + ex.Message);
66 text = text ?? string.Empty;
71 get {
return _parseTree; }
76 private void ParseSource(
string newText) {
78 if (newText !=
string.Empty) {
79 _parseTree = _parser.Parse(newText);
82 var views = GetViews();
83 foreach (var view
in views)
84 view.UpdateParsedSource(_parseTree);
88 #region Views manipulation: AddView, RemoveView, GetViews
103 if (result == null) {
106 _viewsCopy.AddRange(_views);
114 private void ParserLoop() {
117 string newtext = Interlocked.Exchange(ref _newText, null);
118 if(newtext != null) {
119 ParseSource(newtext);
123 fmShowException.ShowException(ex);
124 System.Windows.Forms.MessageBox.Show(
"Fatal error in code colorizer. Colorizing had been disabled.");
130 private void ColorizerLoop() {
132 EditorViewAdapterList views = GetViews();
134 foreach (EditorViewAdapter view
in views) {
136 if (view.WantsColorize)
137 view.TryInvokeColorize();
EditorAdapter(LanguageData language)
Scanner base class. The Scanner's function is to transform a stream of characters into aggregates/wor...
void SetNewText(string text)
void AddView(EditorViewAdapter view)
void RemoveView(EditorViewAdapter view)