Skip to content

Commit 753d642

Browse files
make TryGet<Context> into Context
1 parent 2e2e66b commit 753d642

File tree

15 files changed

+23
-24
lines changed

15 files changed

+23
-24
lines changed

Code/ContextSystem/Contexter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,8 @@ List<Context> contexts
136136
{
137137
return rs + "The beginning of the line is incorrectly strucutred.";
138138
}
139-
140-
if (contextable.TryGetContext(scr).HasErrored(out var contextError, out var context))
141-
return rs + contextError;
139+
140+
var context = contextable.GetContext(scr);
142141

143142
foreach (var token in tokens.Skip(1))
144143
{

Code/ContextSystem/Contexts/RunFunctionContext.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
namespace SER.Code.ContextSystem.Contexts;
1212

1313
[UsedImplicitly]
14-
public class RunFunctionContext : YieldingContext, IKeywordContext
14+
public class RunFunctionContext : YieldingContext, IMayReturnValueContext
1515
{
1616
private FunctionDefinitionContext? _functionDefinitionContext;
1717
private readonly List<IValueToken> _providedValues = [];
18-
19-
public string KeywordName => "run";
20-
public string Description => "Runs a local function with a given name.";
21-
public string[] Arguments => ["[function name]"];
18+
19+
public TypeOfValue? Returns => _functionDefinitionContext?.Returns;
20+
public Value? ReturnedValue => _functionDefinitionContext?.ReturnedValue;
2221

2322
public override TryAddTokenRes TryAddToken(BaseToken token)
2423
{

Code/ContextSystem/Contexts/VariableDefinition/VariableDefinitionContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using SER.Code.Helpers.Extensions;
77
using SER.Code.Helpers.ResultSystem;
88
using SER.Code.MethodSystem.BaseMethods;
9+
using SER.Code.TokenSystem.Structures;
910
using SER.Code.TokenSystem.Tokens;
1011
using SER.Code.TokenSystem.Tokens.VariableTokens;
1112
using SER.Code.ValueSystem;
@@ -71,7 +72,7 @@ public override TryAddTokenRes TryAddToken(BaseToken token)
7172
return TryAddTokenRes.End();
7273
}
7374

74-
if (token is MethodToken methodToken)
75+
if (token is IContextableToken contextable)
7576
{
7677
if (methodToken.Method is not ReturningMethod)
7778
{

Code/TokenSystem/Structures/IContextableToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ namespace SER.Code.TokenSystem.Structures;
66

77
public interface IContextableToken
88
{
9-
public TryGet<Context> TryGetContext(Script scr);
9+
public Context GetContext(Script scr);
1010
}

Code/TokenSystem/Tokens/CommentToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override IParseResult InternalParse(Script scr)
1515
: new Ignore();
1616
}
1717

18-
public TryGet<Context> TryGetContext(Script scr)
18+
public Context GetContext(Script scr)
1919
{
2020
return new NoOperationContext
2121
{

Code/TokenSystem/Tokens/FlagArgumentToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override IParseResult InternalParse(Script scr)
1515
: new Ignore();
1616
}
1717

18-
public TryGet<Context> TryGetContext(Script scr)
18+
public Context GetContext(Script scr)
1919
{
2020
return new NoOperationContext
2121
{

Code/TokenSystem/Tokens/FlagToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override IParseResult InternalParse(Script scr)
1515
: new Ignore();
1616
}
1717

18-
public TryGet<Context> TryGetContext(Script scr)
18+
public Context GetContext(Script scr)
1919
{
2020
return new NoOperationContext
2121
{

Code/TokenSystem/Tokens/FunctionDefinitionToken.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace SER.Code.TokenSystem.Tokens;
88

99
public class FunctionDefinitionToken : BaseToken, IContextableToken
1010
{
11-
public TryGet<Context> TryGetContext(Script scr)
11+
public Context GetContext(Script scr)
1212
{
13-
return new FunctionDefinitionContext
13+
return new RunFunctionContext
1414
{
1515
LineNum = LineNum,
1616
Script = scr
@@ -19,7 +19,7 @@ public TryGet<Context> TryGetContext(Script scr)
1919

2020
protected override IParseResult InternalParse(Script scr)
2121
{
22-
if (RawRep != "func")
22+
if (RawRep != "run")
2323
{
2424
return new Ignore();
2525
}

Code/TokenSystem/Tokens/KeywordToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override IParseResult InternalParse(Script scr)
3232
: new Ignore();
3333
}
3434

35-
public TryGet<Context> TryGetContext(Script scr)
35+
public Context GetContext(Script scr)
3636
{
3737
return Context.Create(_keywordType!, (scr, LineNum));
3838
}

Code/TokenSystem/Tokens/MethodToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override IParseResult InternalParse(Script scr)
2424
return new Success();
2525
}
2626

27-
public TryGet<Context> TryGetContext(Script scr)
27+
public Context GetContext(Script scr)
2828
{
2929
return new MethodContext(this)
3030
{

0 commit comments

Comments
 (0)