Skip to content

Commit e6b8e36

Browse files
small changes
1 parent 753d642 commit e6b8e36

File tree

20 files changed

+18
-41
lines changed

20 files changed

+18
-41
lines changed

Code/ContextSystem/BaseContexts/LoopContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using SER.Code.ContextSystem.Extensions;
22
using SER.Code.ContextSystem.Interfaces;
33
using SER.Code.ContextSystem.Structures;
4-
using SER.Code.ValueSystem;
54

65
namespace SER.Code.ContextSystem.BaseContexts;
76

Code/ContextSystem/BaseContexts/YieldingContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SER.Code.ContextSystem.Interfaces;
2-
using SER.Code.ContextSystem.Structures;
32
using SER.Code.Helpers;
43

54
namespace SER.Code.ContextSystem.BaseContexts;

Code/ContextSystem/Contexter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using SER.Code.ContextSystem.CommunicationInterfaces;
33
using SER.Code.ContextSystem.Contexts.Control;
44
using SER.Code.ContextSystem.Interfaces;
5-
using SER.Code.ContextSystem.Structures;
65
using SER.Code.Helpers;
76
using SER.Code.Helpers.Extensions;
87
using SER.Code.Helpers.ResultSystem;

Code/ContextSystem/Contexts/FunctionDefinitionContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ public class FunctionDefinitionContext :
1919
StatementContext,
2020
INotRunningContext,
2121
IAcceptOptionalVariableDefinitions,
22-
IMayReturnValueContext
22+
IMayReturnValueContext,
23+
IKeywordContext
2324
{
2425
public string FunctionName { get; private set; } = null!;
2526
private bool _end = false;
2627
private VariableToken[] _expectedVariables = [];
2728
private readonly List<Variable> _localVariables = [];
29+
30+
public string KeywordName => "func";
31+
public string Description => "Defines a function.";
32+
public string[] Arguments => ["[function name]"];
2833

2934
// gets the type of value associated with a token type of a variable prefix
3035
// sketchy!!

Code/ContextSystem/Contexts/VariableDefinition/VariableDefinitionContext.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using SER.Code.Helpers.Exceptions;
66
using SER.Code.Helpers.Extensions;
77
using SER.Code.Helpers.ResultSystem;
8-
using SER.Code.MethodSystem.BaseMethods;
98
using SER.Code.TokenSystem.Structures;
109
using SER.Code.TokenSystem.Tokens;
1110
using SER.Code.TokenSystem.Tokens.VariableTokens;
@@ -72,20 +71,10 @@ public override TryAddTokenRes TryAddToken(BaseToken token)
7271
return TryAddTokenRes.End();
7372
}
7473

75-
if (token is IContextableToken contextable)
74+
if (token is IContextableToken contextable &&
75+
contextable.GetContext(Script) is {} mainContext and IMayReturnValueContext returnValueContext)
7676
{
77-
if (methodToken.Method is not ReturningMethod)
78-
{
79-
return TryAddTokenRes.Error($"Method '{token.RawRep}' does not return a value");
80-
}
81-
82-
var methodContext = new MethodContext(methodToken)
83-
{
84-
Script = Script,
85-
LineNum = LineNum,
86-
};
87-
88-
_returnContext = (methodContext, methodContext);
77+
_returnContext = (mainContext, returnValueContext);
8978
return TryAddTokenRes.Continue();
9079
}
9180

@@ -108,22 +97,24 @@ protected override IEnumerator<float> Execute()
10897
{
10998
if (_returnContext.HasValue)
11099
{
111-
var coro = _returnContext.Value.main.ExecuteBaseContext();
100+
var (main, returner) = _returnContext.Value;
101+
102+
var coro = main.ExecuteBaseContext();
112103
while (coro.MoveNext())
113104
{
114105
yield return coro.Current;
115106
}
116107

117108
Log.D("checking for returned value");
118-
if (_returnContext.Value.returner.ReturnedValue is not { } value)
109+
if (returner.ReturnedValue is not { } value)
119110
{
120-
throw new ScriptRuntimeError($"Context {_returnContext.Value.main.Name} has not returned a value!");
111+
throw new ScriptRuntimeError($"Context {main.Name} has not returned a value!");
121112
}
122113

123114
if (value is not TValue tValue)
124115
{
125116
throw new ScriptRuntimeError(
126-
$"Value returned by '{_returnContext.Value.main.Name}' cannot be assigned to the {varToken.RawRep} variable");
117+
$"Value returned by '{main.Name}' cannot be assigned to the {varToken.RawRep} variable");
127118
}
128119

129120
Script.AddVariable(Variable.Create(varToken.Name, Value.Parse(tValue)));

Code/ContextSystem/Interfaces/IMayReturnValueContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using SER.Code.Helpers.ResultSystem;
2-
using SER.Code.ValueSystem;
1+
using SER.Code.ValueSystem;
32

43
namespace SER.Code.ContextSystem.Interfaces;
54

Code/Helpers/ExiledHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using LabApi.Loader;
22
using MEC;
3-
using UnityEngine;
43
using Logger = LabApi.Features.Console.Logger;
54

65
namespace SER.Code.Helpers;

Code/Plugin/Commands/HelpSystem/HelpCommand.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using CommandSystem;
44
using SER.Code.ContextSystem.BaseContexts;
55
using SER.Code.ContextSystem.Interfaces;
6-
using SER.Code.ContextSystem.Structures;
76
using SER.Code.FlagSystem.Flags;
87
using SER.Code.Helpers.Exceptions;
98
using SER.Code.Helpers.Extensions;

Code/TokenSystem/Structures/IContextableToken.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using SER.Code.ContextSystem.BaseContexts;
2-
using SER.Code.Helpers.ResultSystem;
32
using SER.Code.ScriptSystem;
43

54
namespace SER.Code.TokenSystem.Structures;

Code/TokenSystem/Tokenizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class Tokenizer
2727
typeof(CollectionVariableToken),
2828
typeof(ReferenceVariableToken),
2929
typeof(DurationToken),
30-
typeof(FunctionDefinitionToken)
30+
typeof(RunFunctionToken)
3131
];
3232

3333
public static readonly Type[] OrderedImportanceTokensFromCollectionSlices =

0 commit comments

Comments
 (0)