Skip to content

Commit e1d6d3e

Browse files
committed
Remove intermediate UnrealAngelscriptServerCodeParser.
1 parent 8de1df5 commit e1d6d3e

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

ServerCodeExciser/ServerCodeExcisionProcessor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ private ExcisionStats ProcessCodeFile(string fileName, string inputPath, EExcisi
183183
// Setup parsing and output.
184184
List<KeyValuePair<int, string>> serverCodeInjections = new List<KeyValuePair<int, string>>();
185185
var inputStream = new AntlrInputStream(script);
186-
var lexer = excisionLanguage.CreateLexer(inputStream);
186+
var lexer = excisionLanguage.CreateLexer<UnrealAngelscriptLexer>(inputStream);
187187
lexer.AddErrorListener(new ExcisionLexerErrorListener());
188188
var commonTokenStream = new CommonTokenStream(lexer);
189-
var parser = excisionLanguage.CreateParser(commonTokenStream);
189+
var parser = excisionLanguage.CreateParser<UnrealAngelscriptParser>(commonTokenStream);
190+
parser.AddErrorListener(new ExcisionParserErrorListener());
191+
190192
var answerText = new StringBuilder();
191193
answerText.Append(script);
192194

@@ -221,7 +223,7 @@ private ExcisionStats ProcessCodeFile(string fileName, string inputPath, EExcisi
221223
// Gather all the injections we want to make
222224
if (visitor != null)
223225
{
224-
visitor.VisitContext(parser.GetParseTree());
226+
visitor.VisitContext(parser.script());
225227
if (_parameters.UseFunctionStats)
226228
{
227229
stats.TotalNrCharacters = visitor.TotalNumberOfFunctionCharactersVisited;

ServerCodeExcisionCommon/IServerCodeExcisionLanguage.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,23 @@ public interface IServerCodeExcisionLanguage
99
List<string> ServerOnlySymbols { get; }
1010

1111
string ServerPrecompilerSymbol { get; }
12+
1213
string ServerScopeStartString { get; }
14+
1315
string ServerScopeEndString { get; }
1416

15-
Antlr4.Runtime.Lexer CreateLexer(Antlr4.Runtime.AntlrInputStream inputStream);
16-
IServerCodeParser CreateParser(Antlr4.Runtime.CommonTokenStream tokenStream);
17-
17+
T CreateLexer<T>(Antlr4.Runtime.AntlrInputStream inputStream)
18+
where T : Antlr4.Runtime.Lexer;
19+
20+
T CreateParser<T>(Antlr4.Runtime.CommonTokenStream tokenStream)
21+
where T : Antlr4.Runtime.Parser;
22+
1823
IServerCodeVisitor CreateSimpleVisitor(string code);
24+
1925
IServerCodeVisitor CreateFunctionVisitor(string code);
26+
2027
IServerCodeVisitor CreateSymbolVisitor(string code);
21-
28+
2229
bool AnyServerOnlySymbolsInScript(string script);
2330
}
2431
}

ServerCodeExcisionCommon/IServerCodeParser.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

ServerCodeExcisionCommon/ServerCodeExcisionUtils.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public enum EExciserReturnValues
8989

9090
public class ExcisionException : Exception
9191
{
92-
public ExcisionException(string excisionError, Exception innerException) : base(excisionError, innerException) {}
92+
public ExcisionException(string excisionError, Exception innerException)
93+
: base(excisionError, innerException)
94+
{
95+
}
9396
}
9497

9598
public class ExcisionParserErrorListener : Antlr4.Runtime.IAntlrErrorListener<Antlr4.Runtime.IToken>

UnrealAngelscriptServerCodeExcision/UnrealAngelsciptServerCodeParser.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

UnrealAngelscriptServerCodeExcision/UnrealAngelscriptServerCodeExcisionLanguage.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System.Collections.Generic;
21
using ServerCodeExcisionCommon;
2+
using System;
3+
using System.Collections.Generic;
34

45
namespace UnrealAngelscriptServerCodeExcision
56
{
@@ -10,27 +11,33 @@ public class UnrealAngelscriptServerCodeExcisionLanguage : IServerCodeExcisionLa
1011
@"^System::IsServer\(\)$",
1112
@"^[A-z]+\.HasAuthority\(\)$"
1213
};
14+
1315
public List<string> ServerOnlySymbolRegexes { get { return _angelscriptServerOnlySymbolRegexes; } }
1416

1517
private List<string> _angelscriptServerOnlySymbols = new List<string>
1618
{
1719
"hasauthority()",
1820
"server"
1921
};
22+
2023
public List<string> ServerOnlySymbols { get { return _angelscriptServerOnlySymbols; } }
2124

2225
public string ServerPrecompilerSymbol { get { return "WITH_SERVER"; } }
26+
2327
public string ServerScopeStartString { get { return "\r\n#ifdef " + ServerPrecompilerSymbol; } }
28+
2429
public string ServerScopeEndString { get { return "#endif // " + ServerPrecompilerSymbol + "\r\n"; } }
2530

26-
public Antlr4.Runtime.Lexer CreateLexer(Antlr4.Runtime.AntlrInputStream inputStream)
27-
{
28-
return new UnrealAngelscriptLexer(inputStream);
31+
public T CreateLexer<T>(Antlr4.Runtime.AntlrInputStream inputStream)
32+
where T : Antlr4.Runtime.Lexer
33+
{
34+
return (T)Activator.CreateInstance(typeof(T), inputStream);
2935
}
3036

31-
public IServerCodeParser CreateParser(Antlr4.Runtime.CommonTokenStream tokenStream)
37+
public T CreateParser<T>(Antlr4.Runtime.CommonTokenStream tokenStream)
38+
where T : Antlr4.Runtime.Parser
3239
{
33-
return new UnrealAngelscriptServerCodeParser(tokenStream);
40+
return (T)Activator.CreateInstance(typeof(T), tokenStream);
3441
}
3542

3643
public IServerCodeVisitor CreateSimpleVisitor(string code)

0 commit comments

Comments
 (0)