Skip to content

Commit 860e279

Browse files
begin rework
1 parent 7f6f776 commit 860e279

41 files changed

Lines changed: 354 additions & 513 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using SER.Code.Helpers;
2+
using SER.Code.ScriptSystem;
3+
4+
namespace SER.Code.ContextSystem.BaseContexts;
5+
6+
public abstract class AdditionalContext : Context
7+
{
8+
private Safe<RunnableContext> _parentContext;
9+
public RunnableContext ParentContext
10+
{
11+
get => _parentContext.Value;
12+
set => _parentContext = value;
13+
}
14+
15+
public static AdditionalContext Create(Type contextType, Script scr, RunnableContext parentContext)
16+
{
17+
var context = (AdditionalContext)Activator.CreateInstance(contextType);
18+
context.Script = scr;
19+
context.ParentContext = parentContext;
20+
return context;
21+
}
22+
23+
public override string ToString() => $"{FriendlyName} attached to {ParentContext}";
24+
}
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SER.Code.ContextSystem.Structures;
1+
using SER.Code.ContextSystem.Structures;
22
using SER.Code.Helpers.ResultSystem;
33
using SER.Code.ScriptSystem;
44
using SER.Code.TokenSystem.Tokens;
@@ -9,29 +9,18 @@ public abstract class Context
99
{
1010
public required Script Script { get; set; } = null!;
1111

12-
public required uint? LineNum { get; set; }
13-
14-
public StatementContext? ParentContext { get; set; } = null;
15-
1612
protected abstract string FriendlyName { get; }
1713

1814
public abstract TryAddTokenRes TryAddToken(BaseToken token);
1915

2016
public abstract Result VerifyCurrentState();
2117

22-
public static Context Create(Type contextType, (Script scr, uint? lineNum) info)
18+
public static Context Create(Type contextType, Script scr)
2319
{
2420
var context = (Context)Activator.CreateInstance(contextType);
25-
context.Script = info.scr;
26-
context.LineNum = info.lineNum;
21+
context.Script = scr;
2722
return context;
2823
}
2924

30-
public override string ToString()
31-
{
32-
if (LineNum.HasValue)
33-
return $"{FriendlyName} at line {LineNum}";
34-
35-
return FriendlyName;
36-
}
25+
public abstract override string ToString();
3726
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using SER.Code.ScriptSystem;
2+
3+
namespace SER.Code.ContextSystem.BaseContexts;
4+
5+
public abstract class RunnableContext : Context
6+
{
7+
public required uint? LineNum { get; set; }
8+
9+
public StatementContext? ParentContext { get; set; } = null;
10+
11+
public static RunnableContext Create(Type contextType, Script scr, uint? lineNum )
12+
{
13+
var context = (RunnableContext)Activator.CreateInstance(contextType);
14+
context.Script = scr;
15+
context.LineNum = lineNum;
16+
return context;
17+
}
18+
19+
public override string ToString()
20+
{
21+
if (LineNum.HasValue)
22+
return $"{FriendlyName} at line {LineNum}";
23+
24+
return FriendlyName;
25+
}
26+
}

Code/ContextSystem/BaseContexts/StandardContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SER.Code.ContextSystem.BaseContexts;
22

3-
public abstract class StandardContext : Context
3+
public abstract class StandardContext : RunnableContext
44
{
55
public void Run()
66
{

Code/ContextSystem/BaseContexts/StatementContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SER.Code.ContextSystem.BaseContexts;
66

77
public abstract class StatementContext : YieldingContext
88
{
9-
public readonly List<Context> Children = [];
9+
public readonly List<RunnableContext> Children = [];
1010

1111
public void SendControlMessage(ParentContextControlMessage msg)
1212
{

Code/ContextSystem/BaseContexts/YieldingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace SER.Code.ContextSystem.BaseContexts;
55

6-
public abstract class YieldingContext : Context
6+
public abstract class YieldingContext : RunnableContext
77
{
88
public IEnumerator<float> Run()
99
{

Code/ContextSystem/Contexter.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ namespace SER.Code.ContextSystem;
1515
/// </summary>
1616
public static class Contexter
1717
{
18-
public static TryGet<Context[]> ContextLines(Line[] lines, Script scr)
18+
public static TryGet<RunnableContext[]> ContextLines(Line[] lines, Script scr)
1919
{
2020
Stack<StatementContext> statementStack = [];
21-
List<Context> contexts = [];
21+
List<RunnableContext> contexts = [];
2222

2323
List<Result> errors = [];
2424
foreach (var line in lines)
@@ -47,10 +47,10 @@ public static TryGet<Context[]> ContextLines(Line[] lines, Script scr)
4747
}
4848

4949
private static Result TryAddResult(
50-
Context context,
50+
RunnableContext context,
5151
uint lineNum,
5252
Stack<StatementContext> statementStack,
53-
List<Context> contexts
53+
List<RunnableContext> contexts
5454
) {
5555
Result rs = $"Invalid context {context}";
5656

@@ -129,19 +129,20 @@ List<Context> contexts
129129
return true;
130130
}
131131

132-
public static TryGet<Context?> ContextLine(BaseToken[] tokens, uint? lineNum, Script scr)
132+
public static TryGet<RunnableContext?> ContextLine(BaseToken[] tokens, uint? lineNum, Script scr)
133133
{
134134
Result rs = $"Line {(lineNum.HasValue ? $"{lineNum.Value} " : "")}is invalid";
135135

136136
var firstToken = tokens.FirstOrDefault();
137-
if (firstToken is null) return null as Context;
137+
if (firstToken is null) return null as RunnableContext;
138138

139139
if (firstToken is not IContextableToken contextable)
140140
{
141141
return $"'{firstToken.RawRep}' is not a valid way to start a line. Perhaps you made a typo?";
142142
}
143143

144144
var context = contextable.GetContext(scr);
145+
if (context is null) return context;
145146

146147
foreach (var token in tokens.Skip(1))
147148
{
@@ -154,7 +155,7 @@ List<Context> contexts
154155
return context;
155156
}
156157

157-
private static Result HandleCurrentContext(BaseToken token, Context context, out bool endLineContexting)
158+
private static Result HandleCurrentContext(BaseToken token, RunnableContext context, out bool endLineContexting)
158159
{
159160
Result rs = $"Cannot add '{token.RawRep}' to {context}";
160161
Log.Debug($"Handling token {token} in context {context}");

Code/ContextSystem/Contexts/Control/ReturnKeyword.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace SER.Code.ContextSystem.Contexts.Control;
1515
public class ReturnKeyword : StandardContext, IKeywordContext
1616
{
1717
private IValueToken? _returnValueToken;
18-
private (Context main, IMayReturnValueContext returner)? _returnContext = null;
18+
private (RunnableContext main, IMayReturnValueContext returner)? _returnContext = null;
1919

2020
public string KeywordName => "return";
2121
public string Description => "Returns value when in a function.";

Code/ContextSystem/Contexts/NoOperationContext.cs

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

0 commit comments

Comments
 (0)