Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ServerCodeExcisionCommon/ServerCodeExcisionUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Antlr4.Runtime;

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

public static int FindScriptIndexForCodePoint(string script, int line, int column)
{
Expand Down Expand Up @@ -141,6 +143,24 @@ public static int FindScriptIndexForCodePoint(string script, int line, int colum
return (linesTraversed == line) ? (cursor + column) : -1;
}

public static int ShrinkServerScope(string script, int start, int end)
{
bool skip = true;
while (skip)
{
skip = false;

int search = script.IndexOfAny(NewLineChars, start) + 2;
if ((search < end) && SkippableScopeChars.Contains<char>(script.ElementAt(search)))
{
skip = true;
++start;
}
}

return start;
}

public static Type FindFirstDirectChildOfType<Type>(Antlr4.Runtime.Tree.IParseTree currentContext)
where Type : class
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public override UnrealAngelscriptNode VisitPostfixExpression(UnrealAngelscriptPa
ExcisionUtils.FindScriptIndexForCodePoint(Script, simpleDeclaration.Stop.Line, simpleDeclaration.Stop.Column) + 1,
ExcisionUtils.FindScriptIndexForCodePoint(Script, parentScope.Stop.Line, 0));

// We need to correct the start index to skip all the possible empty characters/new lines,
// if not we can miss the detection of a manually placed #ifdef
newData.StartIndex = ExcisionUtils.ShrinkServerScope(Script, newData.StartIndex, newData.StopIndex);

if (returnData.ReturnType != EReturnType.NoReturn)
{
string scopeIndentation = BuildIndentationForColumnCount(simpleDeclaration.Start.Column);
Expand Down
Loading