Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 9947c5e

Browse files
Merge pull request #2 from Hexer10/master
Update repo
2 parents 1326911 + 8a46806 commit 9947c5e

File tree

8 files changed

+90
-161
lines changed

8 files changed

+90
-161
lines changed

SourcepawnCondenser/SourcepawnCondenser/Tokenizer/Tokenizer.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
35

46
namespace SourcepawnCondenser.Tokenizer
57
{
@@ -174,7 +176,7 @@ public static List<Token> TokenizeString(string Source, bool IgnoreMultipleEOL)
174176
continue;
175177
}
176178
}
177-
179+
178180
// TODO: Create a real char token
179181
if (c == '\'' && i + 1 < sArrayLength)
180182
{
@@ -393,16 +395,37 @@ public static List<Token> TokenizeString(string Source, bool IgnoreMultipleEOL)
393395

394396
var directiveString = Source.Substring(startIndex, endIndex - startIndex);
395397
token.Add(new Token(directiveString, TokenKind.PrePocessorDirective, startIndex));
398+
if (directiveString == "#define" && sArray[endIndex] == ' ')
399+
{
400+
var name = new StringBuilder();
401+
for (var j = endIndex+1; j < sArrayLength; ++j)
402+
{
403+
if (sArray[j] == '\n' || sArray[j] == '\r')
404+
{
405+
i = j - 1;
406+
break;
407+
}
408+
409+
if (sArray[j] == ' ')
410+
{
411+
token.Add(
412+
new Token(name.ToString(), TokenKind.Identifier, endIndex+1));
413+
break;
414+
}
415+
name.Append(sArray[j]);
416+
}
417+
}
418+
396419
for (var j = i + 1; j < sArrayLength; ++j)
397420
if (sArray[j] == '\n' || sArray[j] == '\r')
398421
{
399-
i = j-1;
422+
i = j - 1;
400423
break;
401424
}
425+
402426
continue;
403427
}
404428
}
405-
406429
}
407430

408431
#endregion

Spcode.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
<Compile Include="UI\Interop\LanguageChooserWindow.xaml.cs">
173173
<DependentUpon>LanguageChooserWindow.xaml</DependentUpon>
174174
</Compile>
175-
<Compile Include="UI\MainWindowBackgroundParser.cs" />
176175
<Compile Include="UI\MainWindowServerQuery.cs" />
177176
<Compile Include="UI\MainWindowSPCompiler.cs" />
178177
<Compile Include="UI\MainWindowCommands.cs" />

UI/Components/EditorElement.xaml.cs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using System.Text.RegularExpressions;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using System.Timers;
@@ -16,6 +17,7 @@
1617
using ICSharpCode.AvalonEdit.Document;
1718
using ICSharpCode.AvalonEdit.Editing;
1819
using ICSharpCode.AvalonEdit.Folding;
20+
using ICSharpCode.AvalonEdit.Highlighting;
1921
using ICSharpCode.AvalonEdit.Rendering;
2022
using ICSharpCode.AvalonEdit.Utils;
2123
using MahApps.Metro.Controls.Dialogs;
@@ -170,6 +172,36 @@ public EditorElement(string filePath)
170172
CompileBox.IsChecked = filePath.EndsWith(".sp");
171173
}
172174

175+
public string FullFilePath
176+
{
177+
get => _FullFilePath;
178+
set
179+
{
180+
var fInfo = new FileInfo(value);
181+
_FullFilePath = fInfo.FullName;
182+
Parent.Title = fInfo.Name;
183+
if (fileWatcher != null) fileWatcher.Path = fInfo.DirectoryName;
184+
}
185+
}
186+
187+
public bool NeedsSave
188+
{
189+
get => _NeedsSave;
190+
set
191+
{
192+
if (!(value ^ _NeedsSave)) //when not changed
193+
return;
194+
_NeedsSave = value;
195+
if (Parent != null)
196+
{
197+
if (_NeedsSave)
198+
Parent.Title = "*" + Parent.Title;
199+
else
200+
Parent.Title = Parent.Title.Trim('*');
201+
}
202+
}
203+
}
204+
173205
private async void TextArea_MouseDown(object sender, MouseButtonEventArgs e)
174206
{
175207
if (!Keyboard.IsKeyDown(Key.LeftCtrl)) return;
@@ -254,9 +286,9 @@ private string GetWordAtMousePosition(MouseEventArgs e)
254286
if (offset >= editor.TextArea.Document.TextLength)
255287
offset--;
256288

257-
int offsetStart = TextUtilities.GetNextCaretPosition(editor.TextArea.Document, offset,
289+
var offsetStart = TextUtilities.GetNextCaretPosition(editor.TextArea.Document, offset,
258290
LogicalDirection.Backward, CaretPositioningMode.WordBorder);
259-
int offsetEnd = TextUtilities.GetNextCaretPosition(editor.TextArea.Document, offset,
291+
var offsetEnd = TextUtilities.GetNextCaretPosition(editor.TextArea.Document, offset,
260292
LogicalDirection.Forward, CaretPositioningMode.WordBorder);
261293

262294
if (offsetEnd == -1 || offsetStart == -1)
@@ -270,36 +302,6 @@ private string GetWordAtMousePosition(MouseEventArgs e)
270302
return editor.TextArea.Document.GetText(offsetStart, offsetEnd - offsetStart);
271303
}
272304

273-
public string FullFilePath
274-
{
275-
get => _FullFilePath;
276-
set
277-
{
278-
var fInfo = new FileInfo(value);
279-
_FullFilePath = fInfo.FullName;
280-
Parent.Title = fInfo.Name;
281-
if (fileWatcher != null) fileWatcher.Path = fInfo.DirectoryName;
282-
}
283-
}
284-
285-
public bool NeedsSave
286-
{
287-
get => _NeedsSave;
288-
set
289-
{
290-
if (!(value ^ _NeedsSave)) //when not changed
291-
return;
292-
_NeedsSave = value;
293-
if (Parent != null)
294-
{
295-
if (_NeedsSave)
296-
Parent.Title = "*" + Parent.Title;
297-
else
298-
Parent.Title = Parent.Title.Trim('*');
299-
}
300-
}
301-
}
302-
303305
private void AutoSaveTimer_Elapsed(object sender, ElapsedEventArgs e)
304306
{
305307
if (NeedsSave)
@@ -657,7 +659,6 @@ private void Caret_PositionChanged(object sender, EventArgs e)
657659
, fInfo.Name).Condense();
658660

659661
if (fInfo.Extension.Trim('.').ToLowerInvariant() == "sp")
660-
{
661662
if (el.IsLoaded)
662663
{
663664
caret = el.editor.CaretOffset;
@@ -666,7 +667,6 @@ private void Caret_PositionChanged(object sender, EventArgs e)
666667
.Condense();
667668
currentFunctions = definitions[i].Functions;
668669
}
669-
}
670670
}
671671

672672
var smDef = Program.Configs[Program.SelectedConfig].GetSMDef()
@@ -675,6 +675,7 @@ private void Caret_PositionChanged(object sender, EventArgs e)
675675
var acNodes = smDef.ProduceACNodes();
676676
var isNodes = smDef.ProduceISNodes();
677677

678+
ce.editor.SyntaxHighlighting = new AeonEditorHighlighting(smDef);
678679
foreach (var el in ee)
679680
{
680681
if (el == ce)
@@ -683,6 +684,7 @@ private void Caret_PositionChanged(object sender, EventArgs e)
683684
if (ce.ISAC_Open) continue;
684685
}
685686

687+
686688
el.InterruptLoadAutoCompletes(smDef.FunctionStrings, smFunctions, acNodes,
687689
isNodes, smDef.Methodmaps.ToArray(), smDef.Variables.ToArray());
688690
}

UI/Components/EditorElementHighlighter.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@
99
using System.Windows.Media;
1010
using ICSharpCode.AvalonEdit.Highlighting;
1111
using ICSharpCode.AvalonEdit.Rendering;
12+
using SourcepawnCondenser.SourcemodDefinition;
1213

1314
namespace SPCode.UI.Components
1415
{
1516
public class AeonEditorHighlighting : IHighlightingDefinition
1617
{
18+
19+
private SMDefinition smDef;
20+
public AeonEditorHighlighting() {}
21+
22+
public AeonEditorHighlighting(SMDefinition smDef)
23+
{
24+
this.smDef = smDef;
25+
}
26+
1727
public string Name => "SM";
1828

1929
public HighlightingRuleSet MainRuleSet
@@ -169,6 +179,17 @@ public HighlightingRuleSet MainRuleSet
169179
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture),
170180
Color = new HighlightingColor {Foreground = stringBrush}
171181
});
182+
183+
if (smDef != null)
184+
{
185+
if (smDef.Defines.Count > 0)
186+
rs.Rules.Add(new HighlightingRule
187+
{
188+
Regex = new Regex(string.Join("|", smDef.Defines.Select(e => "\\b" + e.Name + "\\b").ToArray())),
189+
Color = new HighlightingColor
190+
{Foreground = new SimpleHighlightingBrush(Program.OptionsObject.SH_Constants)}
191+
});
192+
}
172193
var def = Program.Configs[Program.SelectedConfig].GetSMDef();
173194
if (def.TypeStrings.Length > 0)
174195
rs.Rules.Add(new HighlightingRule //types

UI/Components/IntelliSenseController.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public partial class EditorElement
4343

4444
// TODO Add EnumStructs
4545
private SMMethodmap[] methodMaps;
46-
private SMVariable[] smVariables;
47-
46+
4847
private readonly Regex multilineCommentRegex = new Regex(@"/\*.*?\*/",
4948
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Singleline);
5049

@@ -71,7 +70,6 @@ public void LoadAutoCompletes()
7170
acEntrys = def.ProduceACNodes();
7271
isEntrys = def.ProduceISNodes();
7372
methodMaps = def.Methodmaps.ToArray();
74-
smVariables = def.Variables.ToArray();
7573
AutoCompleteBox.ItemsSource = acEntrys;
7674
MethodAutoCompleteBox.ItemsSource = isEntrys;
7775
}
@@ -88,7 +86,6 @@ public void InterruptLoadAutoCompletes(string[] FunctionStrings, SMFunction[] Fu
8886
AutoCompleteBox.ItemsSource = acEntrys;
8987
MethodAutoCompleteBox.ItemsSource = isEntrys;
9088
methodMaps = newMethodMaps;
91-
smVariables = newVariables;
9289
});
9390
}
9491

@@ -135,8 +132,10 @@ private void EvaluateIntelliSense()
135132
{
136133
if (c == '#')
137134
{
138-
HideISAC();
139-
return;
135+
string[] prep = {"define", "pragma", "file", "if"};
136+
acEntrys = ACNode.ConvertFromStringArray(prep, false, "#").ToArray();
137+
// HideISAC();
138+
break;
140139
}
141140

142141
if (!char.IsWhiteSpace(c)) break;
@@ -214,7 +213,6 @@ private void EvaluateIntelliSense()
214213
var classMatch = match.Groups["class"].Value;
215214
if (classMatch.Length > 0)
216215
{
217-
218216
var methodMap = methodMaps.FirstOrDefault(e => e.Name == classMatch);
219217
var method =
220218
methodMap?.Methods.FirstOrDefault(e => e.Name == methodString);
@@ -397,7 +395,7 @@ private bool ISAC_EvaluateKeyDownEvent(Key k)
397395
}
398396
}
399397

400-
editor.Document.Replace(endOffset, length+1, replaceString);
398+
editor.Document.Replace(endOffset, length + 1, replaceString);
401399
if (setCaret)
402400
editor.CaretOffset -= 1;
403401
return true;

UI/MainWindow.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ private void DockingManager_DocumentClosed(object sender, DocumentClosedEventArg
199199

200200
private void MetroWindow_Closing(object sender, CancelEventArgs e)
201201
{
202-
backgroundParserThread?.Abort();
203-
parseDistributorTimer?.Stop();
204202
ServerCheckThread?.Abort(); //a join would not work, so we have to be..forcefully...
205203
var lastOpenFiles = new List<string>();
206204
var editors = GetAllEditorElements();

0 commit comments

Comments
 (0)