Skip to content

Commit 2d27d74

Browse files
committed
Allow empty lines at the beginning of a server scope
1 parent 46b8559 commit 2d27d74

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ServerCodeExcisionCommon/ServerCodeExcisionUtils.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using Antlr4.Runtime;
45

56
namespace ServerCodeExcisionCommon
@@ -110,6 +111,7 @@ public void SyntaxError(TextWriter output, IRecognizer recognizer, int offending
110111
public static class ExcisionUtils
111112
{
112113
private static char[] NewLineChars = { '\r', '\n' };
114+
private static char[] SkippableScopeChars = { '\t', '\r', '\n' };
113115

114116
public static int FindScriptIndexForCodePoint(string script, int line, int column)
115117
{
@@ -141,6 +143,24 @@ public static int FindScriptIndexForCodePoint(string script, int line, int colum
141143
return (linesTraversed == line) ? (cursor + column) : -1;
142144
}
143145

146+
public static int ShrinkServerScope(string script, int start, int end)
147+
{
148+
bool skip = true;
149+
while (skip)
150+
{
151+
skip = false;
152+
153+
int search = script.IndexOfAny(NewLineChars, start) + 2;
154+
if ((search < end) && SkippableScopeChars.Contains<char>(script.ElementAt(search)))
155+
{
156+
skip = true;
157+
++start;
158+
}
159+
}
160+
161+
return start;
162+
}
163+
144164
public static Type FindFirstDirectChildOfType<Type>(Antlr4.Runtime.Tree.IParseTree currentContext)
145165
where Type : class
146166
{

UnrealAngelscriptServerCodeExcision/UnrealAngelscriptSymbolVisitor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ public override UnrealAngelscriptNode VisitPostfixExpression(UnrealAngelscriptPa
263263
ExcisionUtils.FindScriptIndexForCodePoint(Script, simpleDeclaration.Stop.Line, simpleDeclaration.Stop.Column) + 1,
264264
ExcisionUtils.FindScriptIndexForCodePoint(Script, parentScope.Stop.Line, 0));
265265

266+
// We need to correct the start index to skip all the possible empty characters/new lines,
267+
// if not we can miss the detection of a manually placed #ifdef
268+
newData.StartIndex = ExcisionUtils.ShrinkServerScope(Script, newData.StartIndex, newData.StopIndex);
269+
266270
if (returnData.ReturnType != EReturnType.NoReturn)
267271
{
268272
string scopeIndentation = BuildIndentationForColumnCount(simpleDeclaration.Start.Column);

0 commit comments

Comments
 (0)